Comparing version 0.0.5 to 0.0.6
# Changelog | ||
## 0.0.5 / 2023-06-25 | ||
## 0.0.6 / 2023-09-26 | ||
- Pin peer dependency as `mingo@6.x.x`. | ||
- Default clone mode to "copy". | ||
## 0.0.5 / 2023-06-26 | ||
- Add `mingo@6.4.2` as peerDependency. | ||
@@ -5,0 +9,0 @@ |
@@ -11,2 +11,3 @@ "use strict"; | ||
const util_2 = require("./util"); | ||
const NOT_FOUND = Symbol(); | ||
/** | ||
@@ -39,3 +40,3 @@ * Creates a new store object. | ||
})); | ||
this.mutate = (0, updater_1.createUpdater)(options); | ||
this.mutate = (0, updater_1.createUpdater)(Object.assign({ cloneMode: "copy" }, options)); | ||
} | ||
@@ -125,2 +126,20 @@ /** | ||
} | ||
notifyWith(val) { | ||
for (const cb of this.listeners) { | ||
/*eslint-disable*/ | ||
try { | ||
cb(val); | ||
} | ||
catch (_a) { | ||
this.listeners.delete(cb); | ||
} | ||
finally { | ||
if (this.onceOnly.has(cb)) { | ||
this.listeners.delete(cb); | ||
this.onceOnly.delete(cb); | ||
} | ||
} | ||
/*eslint-disable-enable*/ | ||
} | ||
} | ||
/** | ||
@@ -146,3 +165,3 @@ * Return the current value from state if the condition is fulfilled. | ||
/** | ||
* Run all the listeners with the current value of the selector if not undefined. | ||
* Notify all listeners with the current value of the selector if it is not undefined. | ||
* When the value is 'undefined' the listeners will not be invoked because it is indistinguishable from a failed condition. | ||
@@ -153,26 +172,28 @@ * Callers should never store undefined values in the store. Update operations ignore undefined values. | ||
notifyAll() { | ||
// only recompute if there are active listeners. | ||
if (!this.listeners.size) | ||
return; | ||
// reset the cache when notifyAll() is called. | ||
this.cached = false; | ||
// compute new value. | ||
const val = this.get(); | ||
if (val !== undefined) { | ||
this.notifyWith(val); | ||
} | ||
} | ||
/** | ||
* Notify all listeners with the current value of the selector if different from the previous value. | ||
* If a listener throws an exception when notified, it is removed and does not receive future notifications. | ||
*/ | ||
notifyChanged() { | ||
// only recompute if there are active listeners. | ||
if (!this.listeners.size) | ||
return; | ||
const prev = this.cached ? this.get() : NOT_FOUND; | ||
// reset the cache when notifyChanged() is called. | ||
this.cached = false; | ||
// compute new value. | ||
const val = this.get(); | ||
if (val !== undefined) { | ||
/*eslint-disable*/ | ||
for (const cb of this.listeners) { | ||
try { | ||
cb(val); | ||
} | ||
catch (_a) { | ||
this.listeners.delete(cb); | ||
} | ||
finally { | ||
if (this.onceOnly.has(cb)) { | ||
this.listeners.delete(cb); | ||
this.onceOnly.delete(cb); | ||
} | ||
} | ||
} | ||
/*eslint-disable-enable*/ | ||
if (!(0, util_1.isEqual)(prev, val)) { | ||
this.notifyWith(val); | ||
} | ||
@@ -179,0 +200,0 @@ } |
@@ -6,4 +6,5 @@ import { Query } from "mingo"; | ||
import { createUpdater } from "mingo/updater"; | ||
import { cloneDeep, stringify } from "mingo/util"; | ||
import { cloneDeep, isEqual, stringify } from "mingo/util"; | ||
import { cloneFrozen, extractKeyPaths, sameAncestor } from "./util"; | ||
const NOT_FOUND = Symbol(); | ||
/** | ||
@@ -35,3 +36,3 @@ * Creates a new store object. | ||
})); | ||
this.mutate = createUpdater(options); | ||
this.mutate = createUpdater(Object.assign({ cloneMode: "copy" }, options)); | ||
} | ||
@@ -120,2 +121,20 @@ /** | ||
} | ||
notifyWith(val) { | ||
for (const cb of this.listeners) { | ||
/*eslint-disable*/ | ||
try { | ||
cb(val); | ||
} | ||
catch (_a) { | ||
this.listeners.delete(cb); | ||
} | ||
finally { | ||
if (this.onceOnly.has(cb)) { | ||
this.listeners.delete(cb); | ||
this.onceOnly.delete(cb); | ||
} | ||
} | ||
/*eslint-disable-enable*/ | ||
} | ||
} | ||
/** | ||
@@ -141,3 +160,3 @@ * Return the current value from state if the condition is fulfilled. | ||
/** | ||
* Run all the listeners with the current value of the selector if not undefined. | ||
* Notify all listeners with the current value of the selector if it is not undefined. | ||
* When the value is 'undefined' the listeners will not be invoked because it is indistinguishable from a failed condition. | ||
@@ -148,26 +167,28 @@ * Callers should never store undefined values in the store. Update operations ignore undefined values. | ||
notifyAll() { | ||
// only recompute if there are active listeners. | ||
if (!this.listeners.size) | ||
return; | ||
// reset the cache when notifyAll() is called. | ||
this.cached = false; | ||
// compute new value. | ||
const val = this.get(); | ||
if (val !== undefined) { | ||
this.notifyWith(val); | ||
} | ||
} | ||
/** | ||
* Notify all listeners with the current value of the selector if different from the previous value. | ||
* If a listener throws an exception when notified, it is removed and does not receive future notifications. | ||
*/ | ||
notifyChanged() { | ||
// only recompute if there are active listeners. | ||
if (!this.listeners.size) | ||
return; | ||
const prev = this.cached ? this.get() : NOT_FOUND; | ||
// reset the cache when notifyChanged() is called. | ||
this.cached = false; | ||
// compute new value. | ||
const val = this.get(); | ||
if (val !== undefined) { | ||
/*eslint-disable*/ | ||
for (const cb of this.listeners) { | ||
try { | ||
cb(val); | ||
} | ||
catch (_a) { | ||
this.listeners.delete(cb); | ||
} | ||
finally { | ||
if (this.onceOnly.has(cb)) { | ||
this.listeners.delete(cb); | ||
this.onceOnly.delete(cb); | ||
} | ||
} | ||
} | ||
/*eslint-disable-enable*/ | ||
if (!isEqual(prev, val)) { | ||
this.notifyWith(val); | ||
} | ||
@@ -174,0 +195,0 @@ } |
@@ -68,2 +68,3 @@ import { Query } from "mingo"; | ||
constructor(state: RawObject, projection: Record<keyof T, AnyVal>, query: Query, options: QueryOptions); | ||
private notifyWith; | ||
/** | ||
@@ -76,3 +77,3 @@ * Return the current value from state if the condition is fulfilled. | ||
/** | ||
* Run all the listeners with the current value of the selector if not undefined. | ||
* Notify all listeners with the current value of the selector if it is not undefined. | ||
* When the value is 'undefined' the listeners will not be invoked because it is indistinguishable from a failed condition. | ||
@@ -84,2 +85,7 @@ * Callers should never store undefined values in the store. Update operations ignore undefined values. | ||
/** | ||
* Notify all listeners with the current value of the selector if different from the previous value. | ||
* If a listener throws an exception when notified, it is removed and does not receive future notifications. | ||
*/ | ||
notifyChanged(): void; | ||
/** | ||
* Remove all registered listeners. | ||
@@ -86,0 +92,0 @@ */ |
{ | ||
"name": "adaka", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "High-precision state management using MongoDB query language.", | ||
@@ -22,3 +22,3 @@ "main": "./dist/cjs/index.js", | ||
"peerDependencies": { | ||
"mingo": "^6.4.2" | ||
"mingo": "^6.x.x" | ||
}, | ||
@@ -25,0 +25,0 @@ "devDependencies": {}, |
41971
868