i have 2 models cross referencing each other. this:
mainmodel:
define( [ 'durandal/app', 'durandal/plugins/router', 'models/shell', 'models/editmodel' ], function (app, router, shell, editmodel) { //... return { //... // function should accessible editmodel update: function() { //... }, showeditview: function() { // initialise editmodel data , show according view afterwards editmodel.init('set important stuff here...'); router.navigateto('#/editview'); } //... }; } ); editmodel:
define( [ 'durandal/app', 'durandal/plugins/router', 'models/shell', 'models/mainmodel' ], function (app, router, shell, mainmodel) { //... return { //... // function should accessible mainmodel init: function() { //... }, showmainview: function() { // update the mainmodel data , show according view afterwards mainmodel.update('set new data here...'); router.navigateto('#/mainview'); } //... }; } ); unfortunately not working. if load page on mainview , call showeditview, variable editview known , works fine variable mainmodel in editmodel undefined , therefore call mainmodel.update(...) fails. same thing happens if load page on editview in "opposite direction" (var mainmodel in editmodel known, editmodel in mainmodel undefined).
is known issue , if so: how can circumvent it?
i posted question in durandals google group
thanks
check requierejs documentation circular dependencies http://requirejs.org/docs/api.html#circular.
circular dependencies rare, , sign might want rethink design. however, needed, , in case, use require() specified above.
for main.js add require dependency , explicitly require models/editmodel should trick. either replicate other modules or rethink design ;-).
define( [ 'require', 'durandal/app', 'durandal/plugins/router', 'models/shell', 'models/editmodel' ], function (require, app, router, shell, editmodel) { //... return { //... // function should accessible editmodel update: function() { //... }, showeditview: function() { // initialise editmodel data , show according view afterwards require('models/editmodel').init('set important stuff here...'); router.navigateto('#/editview'); } //... }; } );
Comments
Post a Comment