@tanstack/store 0.4.1 → 0.5.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.
- package/dist/cjs/index.cjs +3 -6
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -2
- package/dist/esm/index.d.ts +1 -2
- package/dist/esm/index.js +3 -6
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -22,18 +22,15 @@ class Store {
|
|
|
22
22
|
this._flush();
|
|
23
23
|
};
|
|
24
24
|
this._flush = () => {
|
|
25
|
-
if (this._batching)
|
|
26
|
-
return;
|
|
25
|
+
if (this._batching) return;
|
|
27
26
|
const flushId = ++this._flushing;
|
|
28
27
|
this.listeners.forEach((listener) => {
|
|
29
|
-
if (this._flushing !== flushId)
|
|
30
|
-
return;
|
|
28
|
+
if (this._flushing !== flushId) return;
|
|
31
29
|
listener();
|
|
32
30
|
});
|
|
33
31
|
};
|
|
34
32
|
this.batch = (cb) => {
|
|
35
|
-
if (this._batching)
|
|
36
|
-
return cb();
|
|
33
|
+
if (this._batching) return cb();
|
|
37
34
|
this._batching = true;
|
|
38
35
|
cb();
|
|
39
36
|
this._batching = false;
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/index.ts"],"sourcesContent":["export type AnyUpdater = (...args: any[]) => any\n\nexport type Listener = () => void\n\
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/index.ts"],"sourcesContent":["export type AnyUpdater = (...args: any[]) => any\n\nexport type Listener = () => void\n\nexport interface StoreOptions<\n TState,\n TUpdater extends AnyUpdater = (cb: TState) => TState,\n> {\n updateFn?: (previous: TState) => (updater: TUpdater) => TState\n onSubscribe?: (\n listener: Listener,\n store: Store<TState, TUpdater>,\n ) => () => void\n onUpdate?: () => void\n}\n\nexport class Store<\n TState,\n TUpdater extends AnyUpdater = (cb: TState) => TState,\n> {\n listeners = new Set<Listener>()\n state: TState\n options?: StoreOptions<TState, TUpdater>\n _batching = false\n _flushing = 0\n\n constructor(initialState: TState, options?: StoreOptions<TState, TUpdater>) {\n this.state = initialState\n this.options = options\n }\n\n subscribe = (listener: Listener) => {\n this.listeners.add(listener)\n const unsub = this.options?.onSubscribe?.(listener, this)\n return () => {\n this.listeners.delete(listener)\n unsub?.()\n }\n }\n\n setState = (updater: TUpdater) => {\n const previous = this.state\n this.state = this.options?.updateFn\n ? this.options.updateFn(previous)(updater)\n : (updater as any)(previous)\n\n // Always run onUpdate, regardless of batching\n this.options?.onUpdate?.()\n\n // Attempt to flush\n this._flush()\n }\n\n _flush = () => {\n if (this._batching) return\n const flushId = ++this._flushing\n this.listeners.forEach((listener) => {\n if (this._flushing !== flushId) return\n listener()\n })\n }\n\n batch = (cb: () => void) => {\n if (this._batching) return cb()\n this._batching = true\n cb()\n this._batching = false\n this._flush()\n }\n}\n"],"names":[],"mappings":";;AAgBO,MAAM,MAGX;AAAA,EAOA,YAAY,cAAsB,SAA0C;AAN5E,SAAA,gCAAgB;AAGJ,SAAA,YAAA;AACA,SAAA,YAAA;AAOZ,SAAA,YAAY,CAAC,aAAuB;;AAC7B,WAAA,UAAU,IAAI,QAAQ;AAC3B,YAAM,SAAQ,gBAAK,YAAL,mBAAc,gBAAd,4BAA4B,UAAU;AACpD,aAAO,MAAM;AACN,aAAA,UAAU,OAAO,QAAQ;AACtB;AAAA,MAAA;AAAA,IACV;AAGF,SAAA,WAAW,CAAC,YAAsB;;AAChC,YAAM,WAAW,KAAK;AACtB,WAAK,UAAQ,UAAK,YAAL,mBAAc,YACvB,KAAK,QAAQ,SAAS,QAAQ,EAAE,OAAO,IACtC,QAAgB,QAAQ;AAG7B,uBAAK,YAAL,mBAAc,aAAd;AAGA,WAAK,OAAO;AAAA,IAAA;AAGd,SAAA,SAAS,MAAM;AACb,UAAI,KAAK,UAAW;AACd,YAAA,UAAU,EAAE,KAAK;AAClB,WAAA,UAAU,QAAQ,CAAC,aAAa;AAC/B,YAAA,KAAK,cAAc,QAAS;AACvB;MAAA,CACV;AAAA,IAAA;AAGH,SAAA,QAAQ,CAAC,OAAmB;AACtB,UAAA,KAAK,UAAW,QAAO;AAC3B,WAAK,YAAY;AACd;AACH,WAAK,YAAY;AACjB,WAAK,OAAO;AAAA,IAAA;AAxCZ,SAAK,QAAQ;AACb,SAAK,UAAU;AAAA,EACjB;AAwCF;;"}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type AnyUpdater = (...args: any[]) => any;
|
|
2
2
|
export type Listener = () => void;
|
|
3
|
-
interface StoreOptions<TState, TUpdater extends AnyUpdater = (cb: TState) => TState> {
|
|
3
|
+
export interface StoreOptions<TState, TUpdater extends AnyUpdater = (cb: TState) => TState> {
|
|
4
4
|
updateFn?: (previous: TState) => (updater: TUpdater) => TState;
|
|
5
5
|
onSubscribe?: (listener: Listener, store: Store<TState, TUpdater>) => () => void;
|
|
6
6
|
onUpdate?: () => void;
|
|
@@ -17,4 +17,3 @@ export declare class Store<TState, TUpdater extends AnyUpdater = (cb: TState) =>
|
|
|
17
17
|
_flush: () => void;
|
|
18
18
|
batch: (cb: () => void) => void;
|
|
19
19
|
}
|
|
20
|
-
export {};
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type AnyUpdater = (...args: any[]) => any;
|
|
2
2
|
export type Listener = () => void;
|
|
3
|
-
interface StoreOptions<TState, TUpdater extends AnyUpdater = (cb: TState) => TState> {
|
|
3
|
+
export interface StoreOptions<TState, TUpdater extends AnyUpdater = (cb: TState) => TState> {
|
|
4
4
|
updateFn?: (previous: TState) => (updater: TUpdater) => TState;
|
|
5
5
|
onSubscribe?: (listener: Listener, store: Store<TState, TUpdater>) => () => void;
|
|
6
6
|
onUpdate?: () => void;
|
|
@@ -17,4 +17,3 @@ export declare class Store<TState, TUpdater extends AnyUpdater = (cb: TState) =>
|
|
|
17
17
|
_flush: () => void;
|
|
18
18
|
batch: (cb: () => void) => void;
|
|
19
19
|
}
|
|
20
|
-
export {};
|
package/dist/esm/index.js
CHANGED
|
@@ -20,18 +20,15 @@ class Store {
|
|
|
20
20
|
this._flush();
|
|
21
21
|
};
|
|
22
22
|
this._flush = () => {
|
|
23
|
-
if (this._batching)
|
|
24
|
-
return;
|
|
23
|
+
if (this._batching) return;
|
|
25
24
|
const flushId = ++this._flushing;
|
|
26
25
|
this.listeners.forEach((listener) => {
|
|
27
|
-
if (this._flushing !== flushId)
|
|
28
|
-
return;
|
|
26
|
+
if (this._flushing !== flushId) return;
|
|
29
27
|
listener();
|
|
30
28
|
});
|
|
31
29
|
};
|
|
32
30
|
this.batch = (cb) => {
|
|
33
|
-
if (this._batching)
|
|
34
|
-
return cb();
|
|
31
|
+
if (this._batching) return cb();
|
|
35
32
|
this._batching = true;
|
|
36
33
|
cb();
|
|
37
34
|
this._batching = false;
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["export type AnyUpdater = (...args: any[]) => any\n\nexport type Listener = () => void\n\
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["export type AnyUpdater = (...args: any[]) => any\n\nexport type Listener = () => void\n\nexport interface StoreOptions<\n TState,\n TUpdater extends AnyUpdater = (cb: TState) => TState,\n> {\n updateFn?: (previous: TState) => (updater: TUpdater) => TState\n onSubscribe?: (\n listener: Listener,\n store: Store<TState, TUpdater>,\n ) => () => void\n onUpdate?: () => void\n}\n\nexport class Store<\n TState,\n TUpdater extends AnyUpdater = (cb: TState) => TState,\n> {\n listeners = new Set<Listener>()\n state: TState\n options?: StoreOptions<TState, TUpdater>\n _batching = false\n _flushing = 0\n\n constructor(initialState: TState, options?: StoreOptions<TState, TUpdater>) {\n this.state = initialState\n this.options = options\n }\n\n subscribe = (listener: Listener) => {\n this.listeners.add(listener)\n const unsub = this.options?.onSubscribe?.(listener, this)\n return () => {\n this.listeners.delete(listener)\n unsub?.()\n }\n }\n\n setState = (updater: TUpdater) => {\n const previous = this.state\n this.state = this.options?.updateFn\n ? this.options.updateFn(previous)(updater)\n : (updater as any)(previous)\n\n // Always run onUpdate, regardless of batching\n this.options?.onUpdate?.()\n\n // Attempt to flush\n this._flush()\n }\n\n _flush = () => {\n if (this._batching) return\n const flushId = ++this._flushing\n this.listeners.forEach((listener) => {\n if (this._flushing !== flushId) return\n listener()\n })\n }\n\n batch = (cb: () => void) => {\n if (this._batching) return cb()\n this._batching = true\n cb()\n this._batching = false\n this._flush()\n }\n}\n"],"names":[],"mappings":"AAgBO,MAAM,MAGX;AAAA,EAOA,YAAY,cAAsB,SAA0C;AAN5E,SAAA,gCAAgB;AAGJ,SAAA,YAAA;AACA,SAAA,YAAA;AAOZ,SAAA,YAAY,CAAC,aAAuB;AAf/B;AAgBE,WAAA,UAAU,IAAI,QAAQ;AAC3B,YAAM,SAAQ,gBAAK,YAAL,mBAAc,gBAAd,4BAA4B,UAAU;AACpD,aAAO,MAAM;AACN,aAAA,UAAU,OAAO,QAAQ;AACtB;AAAA,MAAA;AAAA,IACV;AAGF,SAAA,WAAW,CAAC,YAAsB;AAxB7B;AAyBH,YAAM,WAAW,KAAK;AACtB,WAAK,UAAQ,UAAK,YAAL,mBAAc,YACvB,KAAK,QAAQ,SAAS,QAAQ,EAAE,OAAO,IACtC,QAAgB,QAAQ;AAG7B,uBAAK,YAAL,mBAAc,aAAd;AAGA,WAAK,OAAO;AAAA,IAAA;AAGd,SAAA,SAAS,MAAM;AACb,UAAI,KAAK,UAAW;AACd,YAAA,UAAU,EAAE,KAAK;AAClB,WAAA,UAAU,QAAQ,CAAC,aAAa;AAC/B,YAAA,KAAK,cAAc,QAAS;AACvB;MAAA,CACV;AAAA,IAAA;AAGH,SAAA,QAAQ,CAAC,OAAmB;AACtB,UAAA,KAAK,UAAW,QAAO;AAC3B,WAAK,YAAY;AACd;AACH,WAAK,YAAY;AACjB,WAAK,OAAO;AAAA,IAAA;AAxCZ,SAAK,QAAQ;AACb,SAAK,UAAU;AAAA,EACjB;AAwCF;"}
|
package/package.json
CHANGED