@tanstack/react-store
Advanced tools
Comparing version 0.0.1-beta.89 to 0.0.1-beta.90
@@ -14,7 +14,7 @@ { | ||
"name": "store/build/esm/index.js", | ||
"uid": "0d14-6" | ||
"uid": "a441-10" | ||
}, | ||
{ | ||
"name": "react-store/src/index.tsx", | ||
"uid": "0d14-8" | ||
"uid": "a441-12" | ||
} | ||
@@ -29,20 +29,20 @@ ] | ||
"nodeParts": { | ||
"0d14-6": { | ||
"renderedLength": 1313, | ||
"gzipLength": 489, | ||
"a441-10": { | ||
"renderedLength": 1336, | ||
"gzipLength": 522, | ||
"brotliLength": 0, | ||
"mainUid": "0d14-5" | ||
"mainUid": "a441-9" | ||
}, | ||
"0d14-8": { | ||
"a441-12": { | ||
"renderedLength": 754, | ||
"gzipLength": 343, | ||
"brotliLength": 0, | ||
"mainUid": "0d14-7" | ||
"mainUid": "a441-11" | ||
} | ||
}, | ||
"nodeMetas": { | ||
"0d14-5": { | ||
"a441-9": { | ||
"id": "/packages/store/build/esm/index.js", | ||
"moduleParts": { | ||
"index.production.js": "0d14-6" | ||
"index.production.js": "a441-10" | ||
}, | ||
@@ -52,17 +52,17 @@ "imported": [], | ||
{ | ||
"uid": "0d14-7" | ||
"uid": "a441-11" | ||
} | ||
] | ||
}, | ||
"0d14-7": { | ||
"a441-11": { | ||
"id": "/packages/react-store/src/index.tsx", | ||
"moduleParts": { | ||
"index.production.js": "0d14-8" | ||
"index.production.js": "a441-12" | ||
}, | ||
"imported": [ | ||
{ | ||
"uid": "0d14-9" | ||
"uid": "a441-13" | ||
}, | ||
{ | ||
"uid": "0d14-5" | ||
"uid": "a441-9" | ||
} | ||
@@ -73,3 +73,3 @@ ], | ||
}, | ||
"0d14-9": { | ||
"a441-13": { | ||
"id": "use-sync-external-store/shim/with-selector", | ||
@@ -80,3 +80,3 @@ "moduleParts": {}, | ||
{ | ||
"uid": "0d14-7" | ||
"uid": "a441-11" | ||
} | ||
@@ -83,0 +83,0 @@ ], |
@@ -29,10 +29,7 @@ /** | ||
listeners = new Set(); | ||
#batching = false; | ||
#flushing = 0; | ||
_batching = false; | ||
_flushing = 0; | ||
constructor(initialState, options) { | ||
this.state = initialState; | ||
this.options = options; | ||
if (this.options?.onUpdate) { | ||
this.subscribe(this.options?.onUpdate); | ||
} | ||
} | ||
@@ -50,9 +47,14 @@ subscribe = listener => { | ||
this.state = this.options?.updateFn ? this.options.updateFn(previous)(updater) : updater(previous); | ||
this.#flush(); | ||
// Always run onUpdate, regardless of batching | ||
this.options?.onUpdate?.(); | ||
// Attempt to flush | ||
this._flush(); | ||
}; | ||
#flush = () => { | ||
if (this.#batching) return; | ||
const flushId = ++this.#flushing; | ||
_flush = () => { | ||
if (this._batching) return; | ||
const flushId = ++this._flushing; | ||
this.listeners.forEach(listener => { | ||
if (this.#flushing !== flushId) return; | ||
if (this._flushing !== flushId) return; | ||
listener(); | ||
@@ -62,7 +64,7 @@ }); | ||
batch = cb => { | ||
if (this.#batching) return cb(); | ||
this.#batching = true; | ||
if (this._batching) return cb(); | ||
this._batching = true; | ||
cb(); | ||
this.#batching = false; | ||
this.#flush(); | ||
this._batching = false; | ||
this._flush(); | ||
}; | ||
@@ -69,0 +71,0 @@ } |
@@ -21,3 +21,3 @@ /** | ||
* @license MIT | ||
*/function s(t,e){if(Object.is(t,e))return!0;if("object"!=typeof t||null===t||"object"!=typeof e||null===e)return!1;const s=Object.keys(t);if(s.length!==Object.keys(e).length)return!1;for(let i=0;i<s.length;i++)if(!Object.prototype.hasOwnProperty.call(e,s[i])||!Object.is(t[s[i]],e[s[i]]))return!1;return!0}t.Store=class{listeners=new Set;#t=!1;#e=0;constructor(t,e){this.state=t,this.options=e,this.options?.onUpdate&&this.subscribe(this.options?.onUpdate)}subscribe=t=>{this.listeners.add(t);const e=this.options?.onSubscribe?.(t,this);return()=>{this.listeners.delete(t),e?.()}};setState=t=>{const e=this.state;this.state=this.options?.updateFn?this.options.updateFn(e)(t):t(e),this.#s()};#s=()=>{if(this.#t)return;const t=++this.#e;this.listeners.forEach((e=>{this.#e===t&&e()}))};batch=t=>{if(this.#t)return t();this.#t=!0,t(),this.#t=!1,this.#s()}},t.shallow=s,t.useStore=function(t,i=(t=>t)){return e.useSyncExternalStoreWithSelector(t.subscribe,(()=>t.state),(()=>t.state),i,s)},Object.defineProperty(t,"__esModule",{value:!0})})); | ||
*/function s(t,e){if(Object.is(t,e))return!0;if("object"!=typeof t||null===t||"object"!=typeof e||null===e)return!1;const s=Object.keys(t);if(s.length!==Object.keys(e).length)return!1;for(let i=0;i<s.length;i++)if(!Object.prototype.hasOwnProperty.call(e,s[i])||!Object.is(t[s[i]],e[s[i]]))return!1;return!0}t.Store=class{listeners=new Set;_batching=!1;_flushing=0;constructor(t,e){this.state=t,this.options=e}subscribe=t=>{this.listeners.add(t);const e=this.options?.onSubscribe?.(t,this);return()=>{this.listeners.delete(t),e?.()}};setState=t=>{const e=this.state;this.state=this.options?.updateFn?this.options.updateFn(e)(t):t(e),this.options?.onUpdate?.(),this._flush()};_flush=()=>{if(this._batching)return;const t=++this._flushing;this.listeners.forEach((e=>{this._flushing===t&&e()}))};batch=t=>{if(this._batching)return t();this._batching=!0,t(),this._batching=!1,this._flush()}},t.shallow=s,t.useStore=function(t,i=(t=>t)){return e.useSyncExternalStoreWithSelector(t.subscribe,(()=>t.state),(()=>t.state),i,s)},Object.defineProperty(t,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index.production.js.map |
{ | ||
"name": "@tanstack/react-store", | ||
"author": "Tanner Linsley", | ||
"version": "0.0.1-beta.89", | ||
"version": "0.0.1-beta.90", | ||
"license": "MIT", | ||
@@ -39,3 +39,3 @@ "repository": "tanstack/react-store", | ||
"use-sync-external-store": "^1.2.0", | ||
"@tanstack/store": "0.0.1-beta.89" | ||
"@tanstack/store": "0.0.1-beta.90" | ||
}, | ||
@@ -42,0 +42,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
164040
+ Added@tanstack/store@0.0.1-beta.90(transitive)
- Removed@tanstack/store@0.0.1-beta.89(transitive)