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.
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"?
Created attachment 152560 [details] Proposed fix
Sorry, attachment should go to another issue #251075.
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.
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
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.
(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.
https://hg.netbeans.org/ergonomics/rev/f7780c8e9f06
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