Inheritance for durandal (HotTowel) viewmodels? -


simple question, pretty sure it's complicated answer :)

is possible implement form of inheritance viewmodels in durandal?

so if have viewmodel this:

define(['durandal/app', 'services/datacontext', 'durandal/plugins/router', 'services/logger'],     function (app, datacontext, router, logger) {         var somevariable = ko.observable();         var issaving = ko.observable(false);          var vm = {             activate: activate,             somevariable : somevariable,             refresh: refresh,             cancel: function () { router.navigateback(); },             haschanges: ko.computed(function () { return datacontext.haschanges(); }),             cansave: ko.computed(function () { return datacontext.haschanges() && !issaving(); }),             goback: function () { router.navigateback(); },             save: function() {                 issaving(true);                 return datacontext.savechanges().fin(function () { issaving(false); })             },             candeactivate: function() {                 if (datacontext.haschanges()) {                     var msg = 'do want leave , cancel?';                     return app.showmessage(msg, 'navigate away', ['yes', 'no'])                         .then(function(selectedoption) {                             if (selectedoption === 'yes') {                                 datacontext.cancelchanges();                             }                             return selectedoption;                         });                 }                 return true;             }         };          return vm;          //#region internal methods         function activate(routedata) {             logger.log('view activated id {' + routedata.id + '}, null, 'view', true);             });         }         //#endregion          function refresh(id) {             return datacontext.getbyid(client, id);         }     }); 

is possible make kind of base type , inherit further viewmodels it, being able extend requires list , on?

there question on this, viewmodels don't appear quite same one's build durandal/hottowel.

thanks.

i'm pretty sure can accomplished jquery's extend method. occurred me, there may i'm missing, basic example along lines of:

basevm.js

... mentioned viewmodel 

inheritingvm.js

define(['basevm'], function (basevm) {    var somenewobservable = ko.observable();     var vm = $.extend({         somenewobservable : somenewobservable    }, basevm);     return vm; }); 

please let me know if works. coded top of head , hasn't been tested.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -