You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.
I'm trying to use napajs with prototype functions. How can I bind 'this' inside the broadcast api?
Moreover, I'm trying to require momentjs and toolbox inside broadcast, but it's not working.
The text was updated successfully, but these errors were encountered:
I don't get what's the question... could you share an example to help me understand?
I've tried the moment module. It works in this way -
constnapa=require('napajs');letz1=napa.zone.create('z1',{workers: 1});z1.broadcastSync(()=>{letmoment=require('moment');console.log(moment().format("MMM Do YY"));});
This does not work:
z1.broadcastSync(()=>{letmoment=require('moment');});z1.execute(()=>{console.log(moment().format("MMM Do YY"));//ReferenceError: moment is not defined});
By using global it does work:
z1.broadcastSync(()=>{global.moment=require('moment');});z1.execute(()=>{console.log(global.moment().format("MMM Do YY"));});
I have a class Greedy and some prototype functions that I need to broadcast such as Greedy.prototype.optimize = function(orders, moovers){ ... return solution}. I can't call z1.broadcastSync(this.optimize.toString()) inside others prototype functions. How can I do it?
In my previous attempt I always put definitions of customized class into a separated file. Say I have a file greedy.js with the definition of optimize() inside so I broadcast a call to require() to handle this kind of requirement.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I'm trying to use napajs with prototype functions. How can I bind 'this' inside the broadcast api?
Moreover, I'm trying to require momentjs and toolbox inside broadcast, but it's not working.
The text was updated successfully, but these errors were encountered: