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
22 lines
536 B
JavaScript
22 lines
536 B
JavaScript
import { id, registerSubscriptions, registerFire } from './util.js';
|
|
|
|
export function prop(store, hash = id) {
|
|
let subscribers = [];
|
|
let id = hash(store);
|
|
|
|
const accessor = function _prop(newVal) {
|
|
const newId = hash(newVal);
|
|
if (newVal !== undefined && id !== newId) {
|
|
id = newId;
|
|
store = newVal;
|
|
accessor.fire(store);
|
|
}
|
|
return store;
|
|
};
|
|
accessor.subscribe = registerSubscriptions(subscribers);
|
|
accessor.fire = registerFire(subscribers);
|
|
accessor.unsubscribeAll = () => (subscribers = []);
|
|
|
|
return accessor;
|
|
}
|