@tanstack/store 0.0.1-beta.134 → 0.0.1-beta.148
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/build/cjs/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 = (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":";;;;;;;;;;;;;;AAmBO,MAAMA,KAAK,CAGhB;
|
|
1
|
+
{"version":3,"file":"index.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":";;;;;;;;;;;;;;AAmBO,MAAMA,KAAK,CAGhB;AACAC,EAAAA,SAAS,GAAG,IAAIC,GAAG,EAAY,CAAA;AAG/BC,EAAAA,SAAS,GAAG,KAAK,CAAA;AACjBC,EAAAA,SAAS,GAAG,CAAC,CAAA;AACbC,EAAAA,aAAa,GAAoB,IAAI,CAAA;AAErCC,EAAAA,WAAWA,CAACC,YAAoB,EAAEC,OAAwC,EAAE;IAC1E,IAAI,CAACC,KAAK,GAAGF,YAAY,CAAA;IACzB,IAAI,CAACC,OAAO,GAAGA,OAAO,CAAA;AACxB,GAAA;EAEAE,SAAS,GAAIC,QAAkB,IAAK;AAClC,IAAA,IAAI,CAACV,SAAS,CAACW,GAAG,CAACD,QAAQ,CAAC,CAAA;IAC5B,MAAME,KAAK,GAAG,IAAI,CAACL,OAAO,EAAEM,WAAW,GAAGH,QAAQ,EAAE,IAAI,CAAC,CAAA;AACzD,IAAA,OAAO,MAAM;AACX,MAAA,IAAI,CAACV,SAAS,CAACc,MAAM,CAACJ,QAAQ,CAAC,CAAA;AAC/BE,MAAAA,KAAK,IAAI,CAAA;KACV,CAAA;GACF,CAAA;AAEDG,EAAAA,QAAQ,GAAGA,CACT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,CAAA;AACJ,KAAC,CAAC,CAAA;GACH,CAAA;EAEDsB,KAAK,GAAIC,EAAc,IAAK;AAC1B,IAAA,IAAI,IAAI,CAACzB,SAAS,EAAE,OAAOyB,EAAE,EAAE,CAAA;IAC/B,IAAI,CAACzB,SAAS,GAAG,IAAI,CAAA;AACrByB,IAAAA,EAAE,EAAE,CAAA;IACJ,IAAI,CAACzB,SAAS,GAAG,KAAK,CAAA;IACtB,IAAI,CAACqB,MAAM,EAAE,CAAA;GACd,CAAA;AACH;;;;"}
|
package/build/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 = (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":";;;;;;;;;;AAmBO,MAAMA,KAAK,CAGhB;
|
|
1
|
+
{"version":3,"file":"index.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":";;;;;;;;;;AAmBO,MAAMA,KAAK,CAGhB;AACAC,EAAAA,SAAS,GAAG,IAAIC,GAAG,EAAY,CAAA;AAG/BC,EAAAA,SAAS,GAAG,KAAK,CAAA;AACjBC,EAAAA,SAAS,GAAG,CAAC,CAAA;AACbC,EAAAA,aAAa,GAAoB,IAAI,CAAA;AAErCC,EAAAA,WAAWA,CAACC,YAAoB,EAAEC,OAAwC,EAAE;IAC1E,IAAI,CAACC,KAAK,GAAGF,YAAY,CAAA;IACzB,IAAI,CAACC,OAAO,GAAGA,OAAO,CAAA;AACxB,GAAA;EAEAE,SAAS,GAAIC,QAAkB,IAAK;AAClC,IAAA,IAAI,CAACV,SAAS,CAACW,GAAG,CAACD,QAAQ,CAAC,CAAA;IAC5B,MAAME,KAAK,GAAG,IAAI,CAACL,OAAO,EAAEM,WAAW,GAAGH,QAAQ,EAAE,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AACyB,OAAO,CAAEf,QAAQ,IAAK;AACnC,MAAA,IAAI,IAAI,CAACP,SAAS,KAAKqB,OAAO,EAAE,OAAA;AAChCd,MAAAA,QAAQ,CAAC;AACPU,QAAAA,QAAQ,EAAE,IAAI,CAAChB,aAAa,IAAI,MAAA;AAClC,OAAC,CAAC,CAAA;AACJ,KAAC,CAAC,CAAA;GACH,CAAA;EAEDsB,KAAK,GAAIC,EAAc,IAAK;AAC1B,IAAA,IAAI,IAAI,CAACzB,SAAS,EAAE,OAAOyB,EAAE,EAAE,CAAA;IAC/B,IAAI,CAACzB,SAAS,GAAG,IAAI,CAAA;AACrByB,IAAAA,EAAE,EAAE,CAAA;IACJ,IAAI,CAACzB,SAAS,GAAG,KAAK,CAAA;IACtB,IAAI,CAACqB,MAAM,EAAE,CAAA;GACd,CAAA;AACH;;;;"}
|
package/build/stats-html.html
CHANGED
|
@@ -4024,7 +4024,7 @@ var drawChart = (function (exports) {
|
|
|
4024
4024
|
</script>
|
|
4025
4025
|
<script>
|
|
4026
4026
|
/*<!--*/
|
|
4027
|
-
const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.production.js","children":[{"name":"packages/store/src/index.ts","uid":"
|
|
4027
|
+
const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.production.js","children":[{"name":"packages/store/src/index.ts","uid":"c566-1"}]}],"isRoot":true},"nodeParts":{"c566-1":{"renderedLength":1603,"gzipLength":519,"brotliLength":0,"mainUid":"c566-0"}},"nodeMetas":{"c566-0":{"id":"/packages/store/src/index.ts","moduleParts":{"index.production.js":"c566-1"},"imported":[],"importedBy":[],"isEntry":true}},"env":{"rollup":"2.79.1"},"options":{"gzip":true,"brotli":false,"sourcemap":false}};
|
|
4028
4028
|
|
|
4029
4029
|
const run = () => {
|
|
4030
4030
|
const width = window.innerWidth;
|
package/build/stats-react.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"children": [
|
|
9
9
|
{
|
|
10
10
|
"name": "packages/store/src/index.ts",
|
|
11
|
-
"uid": "
|
|
11
|
+
"uid": "c566-3"
|
|
12
12
|
}
|
|
13
13
|
]
|
|
14
14
|
}
|
|
@@ -16,18 +16,18 @@
|
|
|
16
16
|
"isRoot": true
|
|
17
17
|
},
|
|
18
18
|
"nodeParts": {
|
|
19
|
-
"
|
|
19
|
+
"c566-3": {
|
|
20
20
|
"renderedLength": 1603,
|
|
21
21
|
"gzipLength": 519,
|
|
22
22
|
"brotliLength": 0,
|
|
23
|
-
"mainUid": "
|
|
23
|
+
"mainUid": "c566-2"
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"nodeMetas": {
|
|
27
|
-
"
|
|
27
|
+
"c566-2": {
|
|
28
28
|
"id": "/packages/store/src/index.ts",
|
|
29
29
|
"moduleParts": {
|
|
30
|
-
"index.production.js": "
|
|
30
|
+
"index.production.js": "c566-3"
|
|
31
31
|
},
|
|
32
32
|
"imported": [],
|
|
33
33
|
"importedBy": [],
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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,C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,IAAI,CAAChB,aAAAA;EACjB,KAAC,CAAC,CAAA;;EAEF;MACA,IAAI,CAACmB,MAAM,EAAE,CAAA;KACd,CAAA;IAEDA,MAAM,GAAGA,MAAM;MACb,IAAI,IAAI,CAACrB,SAAS,EAAE,OAAA;EACpB,IAAA,MAAMsB,OAAO,GAAG,EAAE,IAAI,CAACrB,SAAS,CAAA;EAChC,IAAA,IAAI,CAACH,SAAS,CAACyB,OAAO,CAAEf,QAAQ,IAAK;EACnC,MAAA,IAAI,IAAI,CAACP,SAAS,KAAKqB,OAAO,EAAE,OAAA;EAChCd,MAAAA,QAAQ,CAAC;EACPU,QAAAA,QAAQ,EAAE,IAAI,CAAChB,aAAa,IAAI,MAAA;EAClC,OAAC,CAAC,CAAA;EACJ,KAAC,CAAC,CAAA;KACH,CAAA;IAEDsB,KAAK,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 +1 @@
|
|
|
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,
|
|
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"}
|