@tanstack/store 0.0.1 → 0.1.0

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.
@@ -1,45 +0,0 @@
1
- {
2
- "version": 2,
3
- "tree": {
4
- "name": "root",
5
- "children": [
6
- {
7
- "name": "index.production.js",
8
- "children": [
9
- {
10
- "name": "packages/store/src/index.ts",
11
- "uid": "1b85-3"
12
- }
13
- ]
14
- }
15
- ],
16
- "isRoot": true
17
- },
18
- "nodeParts": {
19
- "1b85-3": {
20
- "renderedLength": 1603,
21
- "gzipLength": 519,
22
- "brotliLength": 0,
23
- "mainUid": "1b85-2"
24
- }
25
- },
26
- "nodeMetas": {
27
- "1b85-2": {
28
- "id": "/packages/store/src/index.ts",
29
- "moduleParts": {
30
- "index.production.js": "1b85-3"
31
- },
32
- "imported": [],
33
- "importedBy": [],
34
- "isEntry": true
35
- }
36
- },
37
- "env": {
38
- "rollup": "2.79.1"
39
- },
40
- "options": {
41
- "gzip": true,
42
- "brotli": false,
43
- "sourcemap": false
44
- }
45
- }
@@ -1,40 +0,0 @@
1
- /**
2
- * @tanstack/store/src/index.ts
3
- *
4
- * Copyright (c) TanStack
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE.md file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- type AnyUpdater = (...args: any[]) => any;
12
- type Listener = (opts: {
13
- priority: Priority;
14
- }) => void;
15
- type Priority = 'high' | 'low';
16
- interface StoreOptions<TState, TUpdater extends AnyUpdater = (cb: TState) => TState> {
17
- updateFn?: (previous: TState) => (updater: TUpdater) => TState;
18
- onSubscribe?: (listener: Listener, store: Store<TState, TUpdater>) => () => void;
19
- onUpdate?: (opts: {
20
- priority: Priority;
21
- }) => void;
22
- defaultPriority?: Priority;
23
- }
24
- declare class Store<TState, TUpdater extends AnyUpdater = (cb: TState) => TState> {
25
- listeners: Set<Listener>;
26
- state: TState;
27
- options?: StoreOptions<TState, TUpdater>;
28
- _batching: boolean;
29
- _flushing: number;
30
- _nextPriority: null | Priority;
31
- constructor(initialState: TState, options?: StoreOptions<TState, TUpdater>);
32
- subscribe: (listener: Listener) => () => void;
33
- setState: (updater: TUpdater, opts?: {
34
- priority: Priority;
35
- }) => void;
36
- _flush: () => void;
37
- batch: (cb: () => void) => void;
38
- }
39
-
40
- export { AnyUpdater, Listener, Priority, Store };
@@ -1,78 +0,0 @@
1
- /**
2
- * @tanstack/store/src/index.ts
3
- *
4
- * Copyright (c) TanStack
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE.md file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- (function (global, factory) {
12
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
13
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
14
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Store = {}));
15
- })(this, (function (exports) { 'use strict';
16
-
17
- class Store {
18
- listeners = new Set();
19
- _batching = false;
20
- _flushing = 0;
21
- _nextPriority = null;
22
- constructor(initialState, options) {
23
- this.state = initialState;
24
- this.options = options;
25
- }
26
- subscribe = listener => {
27
- this.listeners.add(listener);
28
- const unsub = this.options?.onSubscribe?.(listener, this);
29
- return () => {
30
- this.listeners.delete(listener);
31
- unsub?.();
32
- };
33
- };
34
- setState = (updater, opts) => {
35
- const previous = this.state;
36
- this.state = this.options?.updateFn ? this.options.updateFn(previous)(updater) : updater(previous);
37
- const priority = opts?.priority ?? this.options?.defaultPriority ?? 'high';
38
- if (this._nextPriority === null) {
39
- this._nextPriority = priority;
40
- } else if (this._nextPriority === 'high') {
41
- this._nextPriority = priority;
42
- } else {
43
- this._nextPriority = this.options?.defaultPriority ?? 'high';
44
- }
45
-
46
- // Always run onUpdate, regardless of batching
47
- this.options?.onUpdate?.({
48
- priority: this._nextPriority
49
- });
50
-
51
- // Attempt to flush
52
- this._flush();
53
- };
54
- _flush = () => {
55
- if (this._batching) return;
56
- const flushId = ++this._flushing;
57
- this.listeners.forEach(listener => {
58
- if (this._flushing !== flushId) return;
59
- listener({
60
- priority: this._nextPriority ?? 'high'
61
- });
62
- });
63
- };
64
- batch = cb => {
65
- if (this._batching) return cb();
66
- this._batching = true;
67
- cb();
68
- this._batching = false;
69
- this._flush();
70
- };
71
- }
72
-
73
- exports.Store = Store;
74
-
75
- Object.defineProperty(exports, '__esModule', { value: true });
76
-
77
- }));
78
- //# sourceMappingURL=index.development.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.development.js","sources":["../../src/index.ts"],"sourcesContent":["export type AnyUpdater = (...args: any[]) => any\n\nexport type Listener = (opts: { priority: Priority }) => void\n\nexport type Priority = 'high' | 'low'\n\ninterface 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?: (opts: { priority: Priority }) => void\n defaultPriority?: Priority\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 _nextPriority: null | Priority = null\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 = (\n updater: TUpdater,\n opts?: {\n priority: Priority\n },\n ) => {\n const previous = this.state\n this.state = this.options?.updateFn\n ? this.options.updateFn(previous)(updater)\n : (updater as any)(previous)\n\n const priority = opts?.priority ?? this.options?.defaultPriority ?? 'high'\n if (this._nextPriority === null) {\n this._nextPriority = priority\n } else if (this._nextPriority === 'high') {\n this._nextPriority = priority\n } else {\n this._nextPriority = this.options?.defaultPriority ?? 'high'\n }\n\n // Always run onUpdate, regardless of batching\n this.options?.onUpdate?.({\n priority: this._nextPriority,\n })\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 priority: this._nextPriority ?? 'high',\n })\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":["Store","listeners","Set","_batching","_flushing","_nextPriority","constructor","initialState","options","state","subscribe","listener","add","unsub","onSubscribe","delete","setState","updater","opts","previous","updateFn","priority","defaultPriority","onUpdate","_flush","flushId","forEach","batch","cb"],"mappings":";;;;;;;;;;;;;;;;EAmBO,MAAMA,KAAK,CAGhB;EACAC,EAAAA,SAAS,GAAG,IAAIC,GAAG,EAAY,CAAA;EAG/BC,EAAAA,SAAS,GAAG,KAAK,CAAA;EACjBC,EAAAA,SAAS,GAAG,CAAC,CAAA;EACbC,EAAAA,aAAa,GAAoB,IAAI,CAAA;EAErCC,EAAAA,WAAWA,CAACC,YAAoB,EAAEC,OAAwC,EAAE;MAC1E,IAAI,CAACC,KAAK,GAAGF,YAAY,CAAA;MACzB,IAAI,CAACC,OAAO,GAAGA,OAAO,CAAA;EACxB,GAAA;IAEAE,SAAS,GAAIC,QAAkB,IAAK;EAClC,IAAA,IAAI,CAACV,SAAS,CAACW,GAAG,CAACD,QAAQ,CAAC,CAAA;MAC5B,MAAME,KAAK,GAAG,IAAI,CAACL,OAAO,EAAEM,WAAW,GAAGH,QAAQ,EAAE,IAAI,CAAC,CAAA;EACzD,IAAA,OAAO,MAAM;EACX,MAAA,IAAI,CAACV,SAAS,CAACc,MAAM,CAACJ,QAAQ,CAAC,CAAA;EAC/BE,MAAAA,KAAK,IAAI,CAAA;OACV,CAAA;KACF,CAAA;EAEDG,EAAAA,QAAQ,GAAGA,CACTC,OAAiB,EACjBC,IAEC,KACE;EACH,IAAA,MAAMC,QAAQ,G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K,GAAIC,EAAc,IAAK;EAC1B,IAAA,IAAI,IAAI,CAACzB,SAAS,EAAE,OAAOyB,EAAE,EAAE,CAAA;MAC/B,IAAI,CAACzB,SAAS,GAAG,IAAI,CAAA;EACrByB,IAAAA,EAAE,EAAE,CAAA;MACJ,IAAI,CAACzB,SAAS,GAAG,KAAK,CAAA;MACtB,IAAI,CAACqB,MAAM,EAAE,CAAA;KACd,CAAA;EACH;;;;;;;;;;"}
@@ -1,12 +0,0 @@
1
- /**
2
- * @tanstack/store/src/index.ts
3
- *
4
- * Copyright (c) TanStack
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE.md file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- !function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i((t="undefined"!=typeof globalThis?globalThis:t||self).Store={})}(this,(function(t){"use strict";t.Store=class{listeners=new Set;_batching=!1;_flushing=0;_nextPriority=null;constructor(t,i){this.state=t,this.options=i}subscribe=t=>{this.listeners.add(t);const i=this.options?.onSubscribe?.(t,this);return()=>{this.listeners.delete(t),i?.()}};setState=(t,i)=>{const s=this.state;this.state=this.options?.updateFn?this.options.updateFn(s)(t):t(s);const e=i?.priority??this.options?.defaultPriority??"high";null===this._nextPriority||"high"===this._nextPriority?this._nextPriority=e:this._nextPriority=this.options?.defaultPriority??"high",this.options?.onUpdate?.({priority:this._nextPriority}),this._flush()};_flush=()=>{if(this._batching)return;const t=++this._flushing;this.listeners.forEach((i=>{this._flushing===t&&i({priority:this._nextPriority??"high"})}))};batch=t=>{if(this._batching)return t();this._batching=!0,t(),this._batching=!1,this._flush()}},Object.defineProperty(t,"__esModule",{value:!0})}));
12
- //# sourceMappingURL=index.production.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.production.js","sources":["../../src/index.ts"],"sourcesContent":["export type AnyUpdater = (...args: any[]) => any\n\nexport type Listener = (opts: { priority: Priority }) => void\n\nexport type Priority = 'high' | 'low'\n\ninterface 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?: (opts: { priority: Priority }) => void\n defaultPriority?: Priority\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 _nextPriority: null | Priority = null\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 = (\n updater: TUpdater,\n opts?: {\n priority: Priority\n },\n ) => {\n const previous = this.state\n this.state = this.options?.updateFn\n ? this.options.updateFn(previous)(updater)\n : (updater as any)(previous)\n\n const priority = opts?.priority ?? this.options?.defaultPriority ?? 'high'\n if (this._nextPriority === null) {\n this._nextPriority = priority\n } else if (this._nextPriority === 'high') {\n this._nextPriority = priority\n } else {\n this._nextPriority = this.options?.defaultPriority ?? 'high'\n }\n\n // Always run onUpdate, regardless of batching\n this.options?.onUpdate?.({\n priority: this._nextPriority,\n })\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 priority: this._nextPriority ?? 'high',\n })\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":["listeners","Set","_batching","_flushing","_nextPriority","constructor","initialState","options","this","state","subscribe","listener","add","unsub","onSubscribe","delete","setState","updater","opts","previous","updateFn","priority","defaultPriority","onUpdate","_flush","flushId","forEach","batch","cb"],"mappings":";;;;;;;;;;qPAmBO,MAILA,UAAY,IAAIC,IAGhBC,WAAY,EACZC,UAAY,EACZC,cAAiC,KAEjCC,YAAYC,EAAsBC,GAChCC,KAAKC,MAAQH,EACbE,KAAKD,QAAUA,CACjB,CAEAG,UAAaC,IACXH,KAAKR,UAAUY,IAAID,GACnB,MAAME,EAAQL,KAAKD,SAASO,cAAcH,EAAUH,MACpD,MAAO,KACLA,KAAKR,UAAUe,OAAOJ,GACtBE,KAAS,CACV,EAGHG,SAAWA,CACTC,EACAC,KAIA,MAAMC,EAAWX,KAAKC,MACtBD,KAAKC,MAAQD,KAAKD,SAASa,SACvBZ,KAAKD,QAAQa,SAASD,EAAtBX,CAAgCS,GAC/BA,EAAgBE,GAErB,MAAME,EAAWH,GAAMG,UAAYb,KAAKD,SAASe,iBAAmB,OACzC,OAAvBd,KAAKJ,eAEyB,SAAvBI,KAAKJ,cADdI,KAAKJ,cAAgBiB,EAIrBb,KAAKJ,cAAgBI,KAAKD,SAASe,iBAAmB,OAIxDd,KAAKD,SAASgB,WAAW,CACvBF,SAAUb,KAAKJ,gBAIjBI,KAAKgB,QAAQ,EAGfA,OAASA,KACP,GAAIhB,KAAKN,UAAW,OACpB,MAAMuB,IAAYjB,KAAKL,UACvBK,KAAKR,UAAU0B,SAASf,IAClBH,KAAKL,YAAcsB,GACvBd,EAAS,CACPU,SAAUb,KAAKJ,eAAiB,QAChC,GACF,EAGJuB,MAASC,IACP,GAAIpB,KAAKN,UAAW,OAAO0B,IAC3BpB,KAAKN,WAAY,EACjB0B,IACApB,KAAKN,WAAY,EACjBM,KAAKgB,QAAQ"}