knockout.js - Durandal Subrouting (Hottowel) Life Cycle Callbacks -


this works well getting sub menu work within main view.

i able activate() function work sub menu viewmodels adding activate: true compose binding. other life cycle events not firing though. how canactivate(), candeactivate() , deactivate() work within sub viewmodels?

refer link @ top of post source code. answer linked question contains example i've used integrate functionality hot towel project.

looks way @evan-larsen constructed inabout activator() prevents execution of candeactivate , deactivate events. not sure why yet.

by converting use system.acquireinstead able make events fire again.

return system.acquire(convertsplattomoduleid(activationdata.splat)).then(function( sample ) {        app.inabout(new sample());    }); 

here's modified about/index.js.

define(   ['durandal/system', 'durandal/viewmodel', 'durandal/plugins/router'],   function( system, viewmodel, router ) {       var defaultpage = 'aboutus';        function convertnametomoduleid ( name ) {           return 'deeplinkingexample/areas/about/' + name + '/' + name;       }        function convertsplattomoduleid ( splat ) {           if ( splat && splat.length > 0 ) {               return convertnametomoduleid(splat[0]);           }           return convertnametomoduleid(defaultpage);       }        var app = {           inabout: viewmodel.activator(),            activate: function( activationdata ) {                    return system.acquire(convertsplattomoduleid(activationdata.splat)).then(function( sample ) {                       app.inabout(new sample());                   });           },            showpage: function( name ) {               return function() {                   router.navigateto('#/about/' + name);               };           },            ispageactive: function( name ) {               var modulename = convertnametomoduleid(name);               return ko.computed(function() {                     return this.inabout().__moduleid__ === modulename;               }, this);           }       };        return app;   } ); 

the code above assume returned detail vms ctors. aboutme.js below should it.

define(['durandal/app', 'durandal/system'], function (app, system) {      var ctor = function() {            this.name = "about me";            this.description = "for demonstration only";        };         ctor.prototype.canactivate = function () {            return app.showmessage('do want view ' + this.name + '?', 'master detail', ['yes', 'no']);        };         ctor.prototype.activate = function() {            system.log('model activating', this);        };         ctor.prototype.candeactivate = function () {            return app.showmessage('do want leave ' + this.name + '?', 'master detail', ['yes', 'no']);        };         ctor.prototype.deactivate = function () {            system.log('model deactivating', this);        };         return ctor; }); 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -