Bundle is no longer necessary since all tools have the "set all subscribers dirty before updating" behavior. Added additional guarantees around subscription call order. tool.fire() can be called externally
19 lines
469 B
JavaScript
19 lines
469 B
JavaScript
export const id = a => a;
|
|
|
|
export const registerSubscriptions = subscriptionsArray => fn => {
|
|
subscriptionsArray.push(fn);
|
|
return () => {
|
|
const idx = subscriptionsArray.indexOf(fn);
|
|
if (idx !== -1) {
|
|
subscriptionsArray.splice(idx, 1);
|
|
}
|
|
return subscriptionsArray.length;
|
|
};
|
|
};
|
|
|
|
export const call = a => (typeof a === 'function' ? a() : a);
|
|
|
|
export const registerFire = subscriptionsArray => val => {
|
|
subscriptionsArray.map(s => s(val)).forEach(call);
|
|
};
|