seqda 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +10 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "seqda",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Sequential Data Store",
5
5
  "main": "src/index.js",
6
6
  "type": "commonjs",
package/src/index.js CHANGED
@@ -92,7 +92,7 @@ function getPath(...parts) {
92
92
  return parts.filter(Boolean).join('.');
93
93
  }
94
94
 
95
- function createStoreSubsection(store, sectionTemplate, path) {
95
+ function createStoreSubsection(options, store, sectionTemplate, path) {
96
96
  const isCacheInvalid = (scopeName, args) => {
97
97
  let thisCache = cache[scopeName];
98
98
  if (!thisCache)
@@ -130,7 +130,9 @@ function createStoreSubsection(store, sectionTemplate, path) {
130
130
  };
131
131
 
132
132
  const get = () => {
133
- store.emit('fetchScope', { store, scopeName: path });
133
+ if (options.emitOnFetch === true)
134
+ store.emit('fetchScope', { store, scopeName: path });
135
+
134
136
  let currentState = Nife.get(store[INTERNAL_STATE], path);
135
137
  return currentState;
136
138
  };
@@ -169,7 +171,7 @@ function createStoreSubsection(store, sectionTemplate, path) {
169
171
 
170
172
  let value = sectionTemplate[key];
171
173
  if (Nife.instanceOf(value, 'object')) {
172
- scope[key] = createStoreSubsection(store, value, getPath(path, key));
174
+ scope[key] = createStoreSubsection(options, store, value, getPath(path, key));
173
175
  subScopes.push(key);
174
176
  continue;
175
177
  }
@@ -186,12 +188,15 @@ function createStoreSubsection(store, sectionTemplate, path) {
186
188
  return Object.freeze(scope);
187
189
  }
188
190
 
189
- function createStore(template) {
191
+ function createStore(template, _options) {
190
192
  if (!Nife.instanceOf(template, 'object'))
191
193
  throw new TypeError('createStore: provided "template" must be an object.');
192
194
 
195
+ const options = _options || {};
193
196
  const store = new EventEmitter();
194
197
 
198
+ store.setMaxListeners(Infinity);
199
+
195
200
  Object.defineProperty(store, INTERNAL_STATE, {
196
201
  writable: true,
197
202
  enumerable: false,
@@ -199,7 +204,7 @@ function createStore(template) {
199
204
  value: {},
200
205
  });
201
206
 
202
- let constructedStore = createStoreSubsection(store, template);
207
+ let constructedStore = createStoreSubsection(options, store, template);
203
208
 
204
209
  Object.defineProperties(constructedStore, {
205
210
  'getState': {