javascript - Knockout Postbox communicating between components - how to ensure subscriber is active -
i have issue publishing on knockout observable within component, , have component view model subscribes postbox event.
the publish event within 'data-table' components view model , follows:
this.pagerparams = ko.observable({ currentpage: this.currentpage, totalitems: this.recordstotal, itemsperpage: this.length }).publishon("pagerparams"); i have 'pager' component subscribes postbox publish.
ko.postbox.subscribe("pagerparams", (params: pagerparams) => { this.assignparamvalues(params, false); this.numberofpages(math.ceil(this.totalitems() / this.itemsperpage()) || 1); this.pagenumbers(this.getpagenumbers()); }); the above postbox subscription registered in view models constructor. depending on component becomes active first, issue pagerparams subscription published in 'data-table' components view model, pager not acknowledge event has been published whatsoever.
i've found reason because 'pager' component needs become active before 'data-table' component, otherwise 'pager' view models subscription checks incoming publishes when line of code has been run.. , lot of time, after data-table has published event.
my question is, how can ensure pager component becomes active before data-table component pub-sub event system works in expected in scenario?
you need handshake protocol. each component publish started message on postbox upon startup. each subscribe started message other , upon receiving it, issue started again , unsubscribe.
whichever starts first publish message never received. 2nd start publish, 1st receive that, re-send, , unsubscribe, , 2nd re-send message never received. each knows other alive, , can dependent tasks then.
Comments
Post a Comment