This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 251076 - Recursive references in Knockout modeling API not supported
Summary: Recursive references in Knockout modeling API not supported
Status: RESOLVED FIXED
Alias: None
Product: web
Classification: Unclassified
Component: Knockout (show other bugs)
Version: 8.1
Hardware: PC Linux
: P3 normal (vote)
Assignee: Jaroslav Tulach
URL:
Keywords:
Depends on: 231131
Blocks:
  Show dependency tree
 
Reported: 2015-03-10 18:31 UTC by Jaroslav Tulach
Modified: 2015-03-21 07:56 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Proposed fix (3.17 KB, patch)
2015-03-11 15:32 UTC, Roman Svitanic
Details | Diff
Patch reusing the cycle detection in TopologicalSortException (7.53 KB, patch)
2015-03-18 15:21 UTC, Jaroslav Tulach
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jaroslav Tulach 2015-03-10 18:31:43 UTC
The Knockout modeling API 
http://bits.netbeans.org/dev/javadoc/org-netbeans-api-knockout/overview-summary.html
has a way to define "modelProperty". It tries its best to sort the models according to dependencies, but if one creates:

  m1 = Bindings.create("Hello");
  m2 = Bindings.create("Multi");
  m1.modelProperty("multi", m2, false);
  m2.modelProperty("hello", m1, false);
  m2.intProperty("int", false);

e.g. creating a cyclic reference between the models - then the generated code does not create valid structure in JavaScript. It ends up like:

var Hello = {
  "multi" : Multi
};
var Multi = {
  "int" : 0,
  "hello" : Hello
};
ko.applyBindings(Multi);

and the Hello.multi value remains undefined. A possible fix would be something like:


var Multi = {
  "int" : 0
};
var Hello = {
  "multi" : Multi
};
Multi.hello = Hello;
ko.applyBindings(Multi);

Again question for Petr: Will you recognize such code and properly offer "hello" as a property of Multi in code completion? E.g. should the model API be changed to solve cycles using this "late assignments"?
Comment 1 Roman Svitanic 2015-03-11 15:32:58 UTC
Created attachment 152560 [details]
Proposed fix
Comment 2 Roman Svitanic 2015-03-11 15:35:09 UTC
Sorry, attachment should go to another issue #251075.
Comment 3 Petr Pisl 2015-03-11 16:28:39 UTC
The case 

var Multi = {
  "int" : 0
};
var Hello = {
  "multi" : Multi
};
Multi.hello = Hello;


works correctly now. In the model there is basically no cycle. In the our model there is the property hello of Multi object that has one assignment of Hello "type". So the model basically doesn't know about the cycle. Code completion works correctly as well, because the types are counted for every type after . separately in an expression. For example  code completion Multi.hello.multi.hello.| works as expected and offers multi property. 

But mark occurrences will not work for the second occurrence of hello identifier in this example. The cycle is there detected and computing occurrences is stopped then.
Comment 4 Jaroslav Tulach 2015-03-12 20:59:34 UTC
Petr seems to be OK with the late time assignments like

Multi.hello = Hello;

and belives that JavaScript editor should understand them correctly. So we need to modify the API to detect a cycle between Multi/Hello and solve it with the late assignment. Btw. NetBeans have an API for detecting cycles in a topological graph: 

http://bits.netbeans.org/dev/javadoc/org-openide-util-ui/org/openide/util/Utilities.html#topologicalSort%28java.util.Collection,%20java.util.Map%29
http://bits.netbeans.org/dev/javadoc/org-openide-util/org/openide/util/TopologicalSortException.html?is-external=true
Comment 5 Jaroslav Tulach 2015-03-18 15:21:38 UTC
Created attachment 152696 [details]
Patch reusing the cycle detection in TopologicalSortException

This is my proposed fix. It will work well even if there are multiple separate cycles between the models thanks to the heavy job done by the TopologicalSortException.

Unless there are objections I'd like to apply it while keeping the version number of the generated JavaScript 1, as there was no release with the current format yet.
Comment 6 Roman Svitanic 2015-03-18 16:21:53 UTC
(In reply to Jaroslav Tulach from comment #5)
> Created attachment 152696 [details]
> Patch reusing the cycle detection in TopologicalSortException
> 
> This is my proposed fix. It will work well even if there are multiple
> separate cycles between the models thanks to the heavy job done by the
> TopologicalSortException.

Proposed fix seems to solve the issue and I think it can be integrated. Thanks.

> 
> Unless there are objections I'd like to apply it while keeping the version
> number of the generated JavaScript 1, as there was no release with the
> current format yet.

I do not have any objections.
Comment 7 Jaroslav Tulach 2015-03-18 17:01:36 UTC
https://hg.netbeans.org/ergonomics/rev/f7780c8e9f06
Comment 8 Quality Engineering 2015-03-21 07:56:14 UTC
Integrated into 'main-silver', will be available in build *201503210001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/f7780c8e9f06
User: Jaroslav Tulach <jtulach@netbeans.org>
Log: #251076: Generate reasonable format even if there are recursive dependencies between used models