@tamagui/use-store 1.32.0 → 1.32.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/Store.js +24 -22
- package/dist/cjs/Store.js.map +1 -1
- package/dist/cjs/helpers.js +2 -1
- package/dist/cjs/helpers.js.map +1 -1
- package/dist/cjs/useStore.js +46 -82
- package/dist/cjs/useStore.js.map +2 -2
- package/dist/esm/Store.js +24 -22
- package/dist/esm/Store.js.map +1 -1
- package/dist/esm/helpers.js +2 -1
- package/dist/esm/helpers.js.map +1 -1
- package/dist/esm/useStore.js +48 -96
- package/dist/esm/useStore.js.map +2 -2
- package/package.json +2 -2
- package/src/Store.tsx +24 -27
- package/src/helpers.tsx +4 -1
- package/src/interfaces.tsx +2 -1
- package/src/useStore.tsx +56 -142
- package/types/Store.d.ts +0 -5
- package/types/Store.d.ts.map +1 -1
- package/types/helpers.d.ts.map +1 -1
- package/types/interfaces.d.ts +2 -1
- package/types/interfaces.d.ts.map +1 -1
- package/types/useStore.d.ts +2 -3
- package/types/useStore.d.ts.map +1 -1
package/src/useStore.tsx
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useCallback,
|
|
3
|
-
useEffect,
|
|
4
|
-
useLayoutEffect,
|
|
5
|
-
useRef,
|
|
6
|
-
useSyncExternalStore,
|
|
7
|
-
} from 'react'
|
|
1
|
+
import { useCallback, useRef, useSyncExternalStore } from 'react'
|
|
8
2
|
|
|
9
3
|
import { isEqualSubsetShallow } from './comparators'
|
|
10
4
|
import { configureOpts } from './configureUseStore'
|
|
@@ -18,39 +12,19 @@ import {
|
|
|
18
12
|
} from './helpers'
|
|
19
13
|
import { Selector, StoreInfo, UseStoreOptions } from './interfaces'
|
|
20
14
|
import {
|
|
21
|
-
ADD_TRACKER,
|
|
22
15
|
SHOULD_DEBUG,
|
|
23
16
|
Store,
|
|
24
17
|
StoreTracker,
|
|
25
|
-
TRACK,
|
|
26
18
|
TRIGGER_UPDATE,
|
|
27
19
|
disableTracking,
|
|
28
20
|
setDisableStoreTracking,
|
|
29
21
|
} from './Store'
|
|
30
22
|
import { useAsyncExternalStore } from './useAsyncExternalStore'
|
|
31
|
-
import {
|
|
32
|
-
DebugStores,
|
|
33
|
-
shouldDebug,
|
|
34
|
-
useCurrentComponent,
|
|
35
|
-
useDebugStoreComponent,
|
|
36
|
-
} from './useStoreDebug'
|
|
37
|
-
|
|
38
|
-
// sanity check types here
|
|
39
|
-
// class StoreTest extends Store<{ id: number }> {}
|
|
40
|
-
// const storeTest = createStore(StoreTest, { id: 3 })
|
|
41
|
-
// const useStoreTest = createUseStore(StoreTest)
|
|
42
|
-
// const useStoreSelectorTest = createUseStoreSelector(StoreTest, (s) => s.props.id)
|
|
43
|
-
// const num = useStoreSelectorTest({ id: 0 })
|
|
44
|
-
// const ya = useStoreTest({ id: 1 })
|
|
45
|
-
// const yb = useStoreTest({ id: 1 }, (x) => x.props.id)
|
|
46
|
-
// const z = useStore(StoreTest)
|
|
47
|
-
// const abc = useGlobalStore(storeTest)
|
|
48
|
-
// const abc2 = useGlobalStore(storeTest)
|
|
49
|
-
// const abcSel = useGlobalStoreSelector(storeTest, (x) => x.props.id)
|
|
23
|
+
import { DebugStores, useCurrentComponent } from './useStoreDebug'
|
|
50
24
|
|
|
51
25
|
const idFn = (_) => _
|
|
52
26
|
const shouldUseSyncDefault =
|
|
53
|
-
typeof window !== 'undefined' && window.location.hash.includes(`
|
|
27
|
+
typeof window !== 'undefined' && !window.location.hash.includes(`use-async-store`)
|
|
54
28
|
|
|
55
29
|
// no singleton, just react
|
|
56
30
|
export function useStore<A extends Store<B>, B extends Object>(
|
|
@@ -60,38 +34,24 @@ export function useStore<A extends Store<B>, B extends Object>(
|
|
|
60
34
|
): A {
|
|
61
35
|
const selectorCb = useCallback(options.selector || idFn, [])
|
|
62
36
|
const selector = options.selector ? selectorCb : options.selector
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
useDebugStoreComponent(StoreKlass)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// if (options.once) {
|
|
69
|
-
// const key = props ? getKey(props) : ''
|
|
70
|
-
// const info = useMemo(() => {
|
|
71
|
-
// return getOrCreateStoreInfo(StoreKlass, props, { avoidCache: true }, key)
|
|
72
|
-
// }, [key])
|
|
73
|
-
// return useStoreFromInfo(info, selector)
|
|
74
|
-
// }
|
|
75
|
-
|
|
76
|
-
const info = getOrCreateStoreInfo(StoreKlass, props)
|
|
77
|
-
return useStoreFromInfo(info, selector)
|
|
37
|
+
const info = getOrCreateStoreInfo(StoreKlass, props, options)
|
|
38
|
+
return useStoreFromInfo(info, selector, options)
|
|
78
39
|
}
|
|
79
40
|
|
|
80
41
|
export function useStoreDebug<A extends Store<B>, B extends Object>(
|
|
81
42
|
StoreKlass: (new (props: B) => A) | (new () => A),
|
|
82
|
-
props?: B
|
|
83
|
-
selector?: any
|
|
43
|
+
props?: B
|
|
84
44
|
): A {
|
|
85
|
-
|
|
86
|
-
return useStore(StoreKlass, props, selector)
|
|
45
|
+
return useStore(StoreKlass, props, { debug: true })
|
|
87
46
|
}
|
|
88
47
|
|
|
89
48
|
// singleton
|
|
90
49
|
export function createStore<A extends Store<B>, B extends Object>(
|
|
91
50
|
StoreKlass: new (props: B) => A | (new () => A),
|
|
92
|
-
props?: B
|
|
51
|
+
props?: B,
|
|
52
|
+
options?: UseStoreOptions<A, any>
|
|
93
53
|
): A {
|
|
94
|
-
return getOrCreateStoreInfo(StoreKlass, props).store as any
|
|
54
|
+
return getOrCreateStoreInfo(StoreKlass, props, options).store as any
|
|
95
55
|
}
|
|
96
56
|
// use singleton with react
|
|
97
57
|
// TODO selector support with types...
|
|
@@ -106,10 +66,7 @@ export function useGlobalStore<A extends Store<B>, B extends Object>(
|
|
|
106
66
|
if (!info) {
|
|
107
67
|
throw new Error(`This store not created using createStore()`)
|
|
108
68
|
}
|
|
109
|
-
|
|
110
|
-
useDebugStoreComponent(store.constructor)
|
|
111
|
-
}
|
|
112
|
-
return useStoreFromInfo(info)
|
|
69
|
+
return useStoreFromInfo(info, undefined, { debug })
|
|
113
70
|
}
|
|
114
71
|
|
|
115
72
|
export function useGlobalStoreSelector<
|
|
@@ -127,10 +84,7 @@ export function useGlobalStoreSelector<
|
|
|
127
84
|
if (!info) {
|
|
128
85
|
throw new Error(`This store not created using createStore()`)
|
|
129
86
|
}
|
|
130
|
-
|
|
131
|
-
useDebugStoreComponent(store.constructor)
|
|
132
|
-
}
|
|
133
|
-
return useStoreFromInfo(info, selector)
|
|
87
|
+
return useStoreFromInfo(info, selector, { debug })
|
|
134
88
|
}
|
|
135
89
|
|
|
136
90
|
// for creating a usable store hook
|
|
@@ -179,16 +133,6 @@ export function trackStoresAccess(cb: StoreAccessTracker) {
|
|
|
179
133
|
}
|
|
180
134
|
}
|
|
181
135
|
|
|
182
|
-
// TODO deprecate and replace with usePortal
|
|
183
|
-
// for ephemeral stores (alpha, not working correctly yet)
|
|
184
|
-
export function useStoreOnce<A extends Store<B>, B extends Object>(
|
|
185
|
-
StoreKlass: (new (props: B) => A) | (new () => A),
|
|
186
|
-
props?: B,
|
|
187
|
-
selector?: any
|
|
188
|
-
): A {
|
|
189
|
-
return useStore(StoreKlass, props, { selector, once: true })
|
|
190
|
-
}
|
|
191
|
-
|
|
192
136
|
// get non-singleton outside react (weird)
|
|
193
137
|
export function getStore<A extends Store<B>, B extends Object>(
|
|
194
138
|
StoreKlass: (new (props: B) => A) | (new () => A),
|
|
@@ -200,24 +144,12 @@ export function getStore<A extends Store<B>, B extends Object>(
|
|
|
200
144
|
function getOrCreateStoreInfo(
|
|
201
145
|
StoreKlass: any,
|
|
202
146
|
props: any,
|
|
203
|
-
|
|
147
|
+
options?: UseStoreOptions & { avoidCache?: boolean },
|
|
204
148
|
propsKeyCalculated?: string
|
|
205
149
|
) {
|
|
206
150
|
const uid = getStoreUid(StoreKlass, propsKeyCalculated ?? props)
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
const cached = cache.get(uid)
|
|
210
|
-
if (cached) {
|
|
211
|
-
// warn if creating an already existing store!
|
|
212
|
-
// need to detect HMR more cleanly if possible
|
|
213
|
-
if (cached.storeInstance.constructor.toString() !== StoreKlass.toString()) {
|
|
214
|
-
console.warn(
|
|
215
|
-
'Error: Stores must have a unique name (ignore if this is a hot reload)'
|
|
216
|
-
)
|
|
217
|
-
} else {
|
|
218
|
-
return cached
|
|
219
|
-
}
|
|
220
|
-
}
|
|
151
|
+
if (!options?.avoidCache && cache.has(uid)) {
|
|
152
|
+
return cache.get(uid)!
|
|
221
153
|
}
|
|
222
154
|
|
|
223
155
|
// init
|
|
@@ -225,7 +157,7 @@ function getOrCreateStoreInfo(
|
|
|
225
157
|
|
|
226
158
|
const getters = {}
|
|
227
159
|
const actions = {}
|
|
228
|
-
const stateKeys
|
|
160
|
+
const stateKeys = new Set<string>()
|
|
229
161
|
const descriptors = getStoreDescriptors(storeInstance)
|
|
230
162
|
for (const key in descriptors) {
|
|
231
163
|
const descriptor = descriptors[key]
|
|
@@ -236,7 +168,7 @@ function getOrCreateStoreInfo(
|
|
|
236
168
|
getters[key] = descriptor.get
|
|
237
169
|
} else {
|
|
238
170
|
if (key !== 'props' && key[0] !== '_') {
|
|
239
|
-
stateKeys.
|
|
171
|
+
stateKeys.add(key)
|
|
240
172
|
}
|
|
241
173
|
}
|
|
242
174
|
}
|
|
@@ -248,6 +180,7 @@ function getOrCreateStoreInfo(
|
|
|
248
180
|
getters,
|
|
249
181
|
stateKeys,
|
|
250
182
|
actions,
|
|
183
|
+
debug: options?.debug,
|
|
251
184
|
gettersState: {
|
|
252
185
|
getCache: new Map<string, any>(),
|
|
253
186
|
depsToGetter: new Map<string, Set<string>>(),
|
|
@@ -271,7 +204,7 @@ function getOrCreateStoreInfo(
|
|
|
271
204
|
store,
|
|
272
205
|
}
|
|
273
206
|
|
|
274
|
-
if (!
|
|
207
|
+
if (!options?.avoidCache) {
|
|
275
208
|
cache.set(uid, value)
|
|
276
209
|
}
|
|
277
210
|
|
|
@@ -299,7 +232,8 @@ export const setIsInReaction = (val: boolean) => {
|
|
|
299
232
|
|
|
300
233
|
function useStoreFromInfo(
|
|
301
234
|
info: StoreInfo,
|
|
302
|
-
userSelector?: Selector<any> | undefined
|
|
235
|
+
userSelector?: Selector<any> | undefined,
|
|
236
|
+
options?: UseStoreOptions
|
|
303
237
|
): any {
|
|
304
238
|
const { store } = info
|
|
305
239
|
if (!store) {
|
|
@@ -310,34 +244,25 @@ function useStoreFromInfo(
|
|
|
310
244
|
if (!internal.current) {
|
|
311
245
|
internal.current = {
|
|
312
246
|
component,
|
|
313
|
-
isTracking: false,
|
|
314
|
-
firstRun: true,
|
|
315
247
|
tracked: new Set<string>(),
|
|
316
|
-
dispose: null as any,
|
|
317
248
|
last: null,
|
|
318
249
|
lastKeys: null,
|
|
319
250
|
}
|
|
320
|
-
const dispose = store[ADD_TRACKER](internal.current)
|
|
321
|
-
internal.current.dispose = dispose
|
|
322
251
|
}
|
|
323
252
|
const curInternal = internal.current!
|
|
324
|
-
|
|
325
|
-
const shouldPrintDebug =
|
|
326
|
-
!!process.env.LOG_LEVEL &&
|
|
327
|
-
(configureOpts.logLevel === 'debug' || shouldDebug(component, info))
|
|
253
|
+
const shouldPrintDebug = options?.debug
|
|
328
254
|
|
|
329
255
|
const getSnapshot = useCallback(() => {
|
|
330
256
|
const curInternal = internal.current!
|
|
331
|
-
const keys = curInternal.
|
|
257
|
+
const keys = [...(!curInternal.tracked.size ? info.stateKeys : curInternal.tracked)]
|
|
258
|
+
const nextKeys = `${store._version}${keys.join('')}${userSelector || ''}`
|
|
259
|
+
const lastKeys = curInternal.lastKeys
|
|
332
260
|
|
|
333
|
-
|
|
261
|
+
// avoid updates
|
|
334
262
|
if (nextKeys === curInternal.lastKeys) {
|
|
335
|
-
if (shouldPrintDebug) {
|
|
336
|
-
// rome-ignore lint/nursery/noConsoleLog: <explanation>
|
|
337
|
-
console.log('avoid update', nextKeys, curInternal.lastKeys)
|
|
338
|
-
}
|
|
339
263
|
return curInternal.last
|
|
340
264
|
}
|
|
265
|
+
|
|
341
266
|
curInternal.lastKeys = nextKeys
|
|
342
267
|
|
|
343
268
|
let snap: any
|
|
@@ -363,11 +288,13 @@ function useStoreFromInfo(
|
|
|
363
288
|
if (shouldPrintDebug) {
|
|
364
289
|
// prettier-ignore
|
|
365
290
|
// rome-ignore lint/nursery/noConsoleLog: <explanation>
|
|
366
|
-
console.log('🌑 getSnapshot', { userSelector, info, isUnchanged, component, keys, snap, curInternal })
|
|
291
|
+
console.log('🌑 getSnapshot', { userSelector, info, isUnchanged, component, keys, last, snap, curInternal, nextKeys, lastKeys })
|
|
367
292
|
}
|
|
293
|
+
|
|
368
294
|
if (isUnchanged) {
|
|
369
295
|
return last
|
|
370
296
|
}
|
|
297
|
+
|
|
371
298
|
curInternal.last = snap
|
|
372
299
|
return snap
|
|
373
300
|
}, [])
|
|
@@ -376,26 +303,7 @@ function useStoreFromInfo(
|
|
|
376
303
|
? useSyncExternalStore(store.subscribe, getSnapshot, getSnapshot)
|
|
377
304
|
: useAsyncExternalStore(store.subscribe, getSnapshot, getSnapshot)
|
|
378
305
|
|
|
379
|
-
|
|
380
|
-
useEffect(() => {
|
|
381
|
-
return curInternal.dispose
|
|
382
|
-
}, [])
|
|
383
|
-
|
|
384
|
-
// we never allow removing selector
|
|
385
|
-
if (!userSelector) {
|
|
386
|
-
// before each render
|
|
387
|
-
curInternal.isTracking = true
|
|
388
|
-
|
|
389
|
-
// track access, runs after each render
|
|
390
|
-
useLayoutEffect(() => {
|
|
391
|
-
curInternal.isTracking = false
|
|
392
|
-
curInternal.firstRun = false
|
|
393
|
-
if (shouldPrintDebug) {
|
|
394
|
-
// rome-ignore lint/nursery/noConsoleLog: <explanation>
|
|
395
|
-
console.log('🌑 finish render, tracking', [...curInternal.tracked])
|
|
396
|
-
}
|
|
397
|
-
})
|
|
398
|
-
} else {
|
|
306
|
+
if (userSelector) {
|
|
399
307
|
return state
|
|
400
308
|
}
|
|
401
309
|
|
|
@@ -407,6 +315,14 @@ function useStoreFromInfo(
|
|
|
407
315
|
if (isInReaction) {
|
|
408
316
|
return curVal
|
|
409
317
|
}
|
|
318
|
+
const keyString = key as string // fine for our uses
|
|
319
|
+
if (info.stateKeys.has(keyString) || keyString in info.getters) {
|
|
320
|
+
if (shouldPrintDebug) {
|
|
321
|
+
// rome-ignore lint/nursery/noConsoleLog: <explanation>
|
|
322
|
+
console.log('tracking', keyString)
|
|
323
|
+
}
|
|
324
|
+
curInternal.tracked.add(keyString)
|
|
325
|
+
}
|
|
410
326
|
if (Reflect.has(state, key)) {
|
|
411
327
|
return Reflect.get(state, key)
|
|
412
328
|
}
|
|
@@ -422,6 +338,7 @@ function createProxiedStore(storeInfo: Omit<StoreInfo, 'store' | 'source'>) {
|
|
|
422
338
|
const { actions, storeInstance, getters, gettersState } = storeInfo
|
|
423
339
|
const { getCache, curGetKeys, depsToGetter } = gettersState
|
|
424
340
|
const constr = storeInstance.constructor
|
|
341
|
+
const shouldDebug = storeInfo.debug ?? DebugStores.has(constr)
|
|
425
342
|
|
|
426
343
|
let didSet = false
|
|
427
344
|
let isInAction = false
|
|
@@ -446,7 +363,7 @@ function createProxiedStore(storeInfo: Omit<StoreInfo, 'store' | 'source'>) {
|
|
|
446
363
|
if (isGetFn || gettersState.isGetting) {
|
|
447
364
|
return Reflect.apply(actionFn, proxiedStore, args)
|
|
448
365
|
}
|
|
449
|
-
if (process.env.NODE_ENV === 'development' &&
|
|
366
|
+
if (process.env.NODE_ENV === 'development' && shouldDebug) {
|
|
450
367
|
// rome-ignore lint/nursery/noConsoleLog: <explanation>
|
|
451
368
|
console.log('(debug) startAction', key, { isInAction })
|
|
452
369
|
}
|
|
@@ -466,7 +383,7 @@ function createProxiedStore(storeInfo: Omit<StoreInfo, 'store' | 'source'>) {
|
|
|
466
383
|
const ogAction = wrappedActions[key]
|
|
467
384
|
wrappedActions[key] = new Proxy(ogAction, {
|
|
468
385
|
apply(target, thisArg, args) {
|
|
469
|
-
const isDebugging =
|
|
386
|
+
const isDebugging = shouldDebug || storeInfo.debug
|
|
470
387
|
const shouldLog =
|
|
471
388
|
process.env.LOG_LEVEL !== '0' &&
|
|
472
389
|
(isDebugging || configureOpts.logLevel !== 'error')
|
|
@@ -566,23 +483,23 @@ function createProxiedStore(storeInfo: Omit<StoreInfo, 'store' | 'source'>) {
|
|
|
566
483
|
},
|
|
567
484
|
})
|
|
568
485
|
}
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
486
|
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
487
|
+
function hashCode(str: string) {
|
|
488
|
+
let hash = 0
|
|
489
|
+
for (let i = 0; i < str.length; i++) {
|
|
490
|
+
hash = str.charCodeAt(i) + ((hash << 5) - hash)
|
|
491
|
+
}
|
|
492
|
+
return hash
|
|
493
|
+
}
|
|
579
494
|
|
|
580
|
-
|
|
581
|
-
|
|
495
|
+
function strColor(str: string) {
|
|
496
|
+
return `hsl(${hashCode(str) % 360}, 90%, 40%)`
|
|
497
|
+
}
|
|
498
|
+
}
|
|
582
499
|
}
|
|
583
500
|
|
|
584
501
|
const finishAction = (val?: any) => {
|
|
585
|
-
if (process.env.NODE_ENV === 'development' &&
|
|
502
|
+
if (process.env.NODE_ENV === 'development' && shouldDebug) {
|
|
586
503
|
// rome-ignore lint/nursery/noConsoleLog: <explanation>
|
|
587
504
|
console.log('(debug) finishAction', { didSet })
|
|
588
505
|
}
|
|
@@ -624,14 +541,11 @@ function createProxiedStore(storeInfo: Omit<StoreInfo, 'store' | 'source'>) {
|
|
|
624
541
|
|
|
625
542
|
// non-actions...
|
|
626
543
|
|
|
627
|
-
const shouldPrintDebug =
|
|
628
|
-
process.env.NODE_ENV === 'development' && DebugStores.has(constr)
|
|
629
|
-
|
|
630
544
|
if (!trackingDisabled) {
|
|
631
545
|
if (gettersState.isGetting) {
|
|
632
546
|
gettersState.curGetKeys.add(key)
|
|
633
547
|
} else {
|
|
634
|
-
storeInstance[TRACK](key,
|
|
548
|
+
// storeInstance[TRACK](key, shouldDebug)
|
|
635
549
|
}
|
|
636
550
|
}
|
|
637
551
|
|
|
@@ -676,7 +590,7 @@ function createProxiedStore(storeInfo: Omit<StoreInfo, 'store' | 'source'>) {
|
|
|
676
590
|
if (typeof key === 'string') {
|
|
677
591
|
clearGetterCache(key)
|
|
678
592
|
}
|
|
679
|
-
if (
|
|
593
|
+
if (shouldDebug) {
|
|
680
594
|
setters.add({ key, value })
|
|
681
595
|
if (storeInstance[SHOULD_DEBUG]()) {
|
|
682
596
|
// rome-ignore lint/nursery/noConsoleLog: <explanation>
|
package/types/Store.d.ts
CHANGED
|
@@ -3,11 +3,8 @@ export declare const ADD_TRACKER: unique symbol;
|
|
|
3
3
|
export declare const TRACK: unique symbol;
|
|
4
4
|
export declare const SHOULD_DEBUG: unique symbol;
|
|
5
5
|
export type StoreTracker = {
|
|
6
|
-
isTracking: boolean;
|
|
7
6
|
tracked: Set<string>;
|
|
8
|
-
dispose: () => void;
|
|
9
7
|
component?: any;
|
|
10
|
-
firstRun: boolean;
|
|
11
8
|
last?: any;
|
|
12
9
|
lastKeys?: any;
|
|
13
10
|
};
|
|
@@ -21,8 +18,6 @@ export declare class Store<Props extends Object = {}> {
|
|
|
21
18
|
constructor(props: Props);
|
|
22
19
|
subscribe: (onChanged: Function) => () => void;
|
|
23
20
|
[TRIGGER_UPDATE](): void;
|
|
24
|
-
[ADD_TRACKER](tracker: StoreTracker): () => void;
|
|
25
|
-
[TRACK](key: string, debug?: boolean): void;
|
|
26
21
|
[SHOULD_DEBUG](): boolean;
|
|
27
22
|
}
|
|
28
23
|
//# sourceMappingURL=Store.d.ts.map
|
package/types/Store.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Store.d.ts","sourceRoot":"","sources":["../src/Store.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,cAAc,eAAW,CAAA;AACtC,eAAO,MAAM,WAAW,eAAW,CAAA;AACnC,eAAO,MAAM,KAAK,eAAW,CAAA;AAC7B,eAAO,MAAM,YAAY,eAAW,CAAA;AAEpC,MAAM,MAAM,YAAY,GAAG;IACzB,
|
|
1
|
+
{"version":3,"file":"Store.d.ts","sourceRoot":"","sources":["../src/Store.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,cAAc,eAAW,CAAA;AACtC,eAAO,MAAM,WAAW,eAAW,CAAA;AACnC,eAAO,MAAM,KAAK,eAAW,CAAA;AAC7B,eAAO,MAAM,YAAY,eAAW,CAAA;AAEpC,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACpB,SAAS,CAAC,EAAE,GAAG,CAAA;IACf,IAAI,CAAC,EAAE,GAAG,CAAA;IACV,QAAQ,CAAC,EAAE,GAAG,CAAA;CACf,CAAA;AAED,eAAO,MAAM,eAAe,sBAAgB,CAAA;AAE5C,eAAO,MAAM,uBAAuB,kBAAmB,GAAG,OAAO,OAAO,SAGvE,CAAA;AAED,qBAAa,KAAK,CAAC,KAAK,SAAS,MAAM,GAAG,EAAE;IAKvB,KAAK,EAAE,KAAK;IAJ/B,OAAO,CAAC,UAAU,CAAsB;IACxC,OAAO,CAAC,SAAS,CAA0B;IAC3C,QAAQ,SAAI;gBAEO,KAAK,EAAE,KAAK;IAE/B,SAAS,cAAe,QAAQ,gBAK9B;IAEF,CAAC,cAAc,CAAC;IAiChB,CAAC,YAAY,CAAC;CAMf"}
|
package/types/helpers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAUxC,wBAAgB,WAAW,CAAC,WAAW,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAUxC,wBAAgB,WAAW,CAAC,WAAW,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,UAS1E;AAED,eAAO,MAAM,iBAAiB,eAA8B,CAAA;AAC5D,eAAO,MAAM,KAAK,wBAA+B,CAAA;AAEjD,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,GAAG;;EAWrD;AAED,wBAAgB,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,SAAS,KAAK,KAAK,CAAC,EAAE,GAAG,KAAK,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAEpF;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,UAYnC;AAID,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAMrD;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,GAAG,OAejC;AAGD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,GAAG,OAI3C"}
|
package/types/interfaces.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE/B,MAAM,MAAM,QAAQ,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO,IAAI,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAA;AAE5D,MAAM,MAAM,gBAAgB,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,KAAK,KAAK,GAAG,CAAA;AAChE,MAAM,MAAM,eAAe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AK,IAAI;IACjC,cAAc,CAAC,EAAE;QACf,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,KAAK,OAAO,CAAA;KAC3C,CAAA;IAED,KAAK,EAAE,CAAC,CAAA;IACR,aAAa,EAAE,GAAG,CAAA;IAClB,OAAO,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAA;IAC/B,OAAO,EAAE,GAAG,CAAA;IACZ,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACtB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,YAAY,EAAE;QACZ,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;QAC1B,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAA;QACtC,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;QACvB,SAAS,EAAE,OAAO,CAAA;KACnB,CAAA;CACF,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,CAAA;CACtC,CAAA"}
|
package/types/useStore.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Selector, UseStoreOptions } from './interfaces';
|
|
2
2
|
import { Store } from './Store';
|
|
3
3
|
export declare function useStore<A extends Store<B>, B extends Object>(StoreKlass: (new (props: B) => A) | (new () => A), props?: B, options?: UseStoreOptions<A, any>): A;
|
|
4
|
-
export declare function useStoreDebug<A extends Store<B>, B extends Object>(StoreKlass: (new (props: B) => A) | (new () => A), props?: B
|
|
5
|
-
export declare function createStore<A extends Store<B>, B extends Object>(StoreKlass: new (props: B) => A | (new () => A), props?: B): A;
|
|
4
|
+
export declare function useStoreDebug<A extends Store<B>, B extends Object>(StoreKlass: (new (props: B) => A) | (new () => A), props?: B): A;
|
|
5
|
+
export declare function createStore<A extends Store<B>, B extends Object>(StoreKlass: new (props: B) => A | (new () => A), props?: B, options?: UseStoreOptions<A, any>): A;
|
|
6
6
|
export declare function useGlobalStore<A extends Store<B>, B extends Object>(instance: A, debug?: boolean): A;
|
|
7
7
|
export declare function useGlobalStoreSelector<A extends Store<B>, B extends Object, Selector extends (store: A) => any>(instance: A, selector: Selector, debug?: boolean): Selector extends (a: A) => infer C ? C : unknown;
|
|
8
8
|
export declare function createUseStore<Props, Store>(StoreKlass: (new (props: Props) => Store) | (new () => Store)): <Res, C extends Selector<Store, Res>, Props_1 extends Object>(props?: Props_1 | undefined, options?: UseStoreOptions) => C extends Selector<any, infer B> ? B extends Object ? B : Store : Store;
|
|
@@ -10,7 +10,6 @@ export declare function createUseStoreSelector<A extends Store<Props>, Props ext
|
|
|
10
10
|
export declare function useStoreSelector<A extends Store<B>, B extends Object, S extends Selector<any, Selected>, Selected>(StoreKlass: (new (props: B) => A) | (new () => A), selector: S, props?: B): Selected;
|
|
11
11
|
type StoreAccessTracker = (store: any) => void;
|
|
12
12
|
export declare function trackStoresAccess(cb: StoreAccessTracker): () => void;
|
|
13
|
-
export declare function useStoreOnce<A extends Store<B>, B extends Object>(StoreKlass: (new (props: B) => A) | (new () => A), props?: B, selector?: any): A;
|
|
14
13
|
export declare function getStore<A extends Store<B>, B extends Object>(StoreKlass: (new (props: B) => A) | (new () => A), props?: B): A;
|
|
15
14
|
export declare const allStores: {};
|
|
16
15
|
export declare const setIsInReaction: (val: boolean) => void;
|
package/types/useStore.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStore.d.ts","sourceRoot":"","sources":["../src/useStore.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useStore.d.ts","sourceRoot":"","sources":["../src/useStore.tsx"],"names":[],"mappings":"AAYA,OAAO,EAAE,QAAQ,EAAa,eAAe,EAAE,MAAM,cAAc,CAAA;AACnE,OAAO,EAEL,KAAK,EAKN,M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