javascript - Passing multiple viewmodels to a component - performance issues? -
using knockout.js components i'm wondering if performance affected when passing multiple viewmodels component instead of single one.
having following:
function masterviewmodel(){ this.demo = new demoviewmodel().init(); this.demo2 = new demo2viewmodel().init(); this.demo3 = new demo3viewmodel().init(); this.demo4 = new demo4viewmodel().init(); this.demo5 = new demo5viewmodel().init(); this.demo6 = new demo6viewmodel().init(); } var mm = new masterviewmodel(); ko.applybindings(mm, $(':root').get(0));
i thinking of passing whole masterviewmodel variable component in order able access viewmodels it:
ko.components.register(element, { viewmodel: { instance: mm }, template: { require: 'text!views/mycomponent.html' }, });
would performance affected in bad way if instead of passing single viewmodel?
ko.components.register(element, { viewmodel: { instance: mm.demo3 }, template: { require: 'text!views/mycomponent.html' }, });
will there noticeable performance difference between register
option 1 , 2? no. code you've presented, 2 options equivalent, except 1 instance of .
operator. negligable.
knockout not afaik walk entire view model object graph take action (e.g. subscribe observable changes), keeps reference view model instance.
apart direct answer question: performance context dependent. if have doubts option faster: race horses.