| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- "use strict";
- function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }
- var id = 0;
- function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
- const packageJson = {
- "version": "2.1.1"
- };
- /**
- * Default store that keeps state in a simple object.
- */
- var _publish = /*#__PURE__*/_classPrivateFieldLooseKey("publish");
- class DefaultStore {
- constructor() {
- Object.defineProperty(this, _publish, {
- value: _publish2
- });
- this.state = {};
- this.callbacks = []; // TODO: use a Set instead, make it a private prop
- }
- getState() {
- return this.state;
- }
- setState(patch) {
- const prevState = { ...this.state
- };
- const nextState = { ...this.state,
- ...patch
- };
- this.state = nextState;
- _classPrivateFieldLooseBase(this, _publish)[_publish](prevState, nextState, patch);
- }
- subscribe(listener) {
- this.callbacks.push(listener);
- return () => {
- // Remove the listener.
- this.callbacks.splice(this.callbacks.indexOf(listener), 1);
- };
- }
- } // TODO: export the class instead in the next major.
- function _publish2() {
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
- args[_key] = arguments[_key];
- }
- this.callbacks.forEach(listener => {
- listener(...args);
- });
- }
- DefaultStore.VERSION = packageJson.version;
- function defaultStore() {
- return new DefaultStore();
- }
- module.exports = defaultStore;
|