The Bank Addon - sjonesyodle/Cluster GitHub Wiki

The Bank provides 3 useful methods to get, set, and load global data in your app.

There are times when it makes sense for a module to produce useful data for other modules to consume without sharing it through _pub.

A use case would be when a module that is initializing before another needs to produce data that may be a dependency for modules further down the queue. If the module tries to broadcast this data, future modules will not receive it since their listeners are not yet bound.

So why not just change the load order of the modules then?

  • Sometimes this is the answer. This is more of a synchronous approach which occasionally makes sense.

Adding members

sig: this.cluster.Bank.add( BankName, BoxName, BoxContents );

this.cluster.Bank.add("MOD_A", "Ids", [{id:"abc123"},{id : "xyz456"}]);

Please note that the keyword this is only used in the context of a module


Get member

sig: this.cluster.Bank.get( BankName, BoxName );

var ids = this.cluster.Bank.get("MOD_A", "Ids");

logs -> [{id:"abc123"},{id : "xyz456"}]


Load members into a context

sig: this.cluster.Bank.load({ BoxName : BankName }, contextObject); (returns bool)

var ModuleB = {}; // Let's pretend this is a module...
this.cluster.Bank.add("MOD_A", "Names", ["Spike", "Jet"]);
this.cluster.Bank.Load({
    "Names": "MOD_A",
    "Ids": "MOD_A"
}, ModuleB);

console.log(ModuleB.Names); // ["Spike", "Jet"]
console.log(ModuleB.Ids); // [{id:"abc123"},{id : "xyz456"}]