@tamagui/use-store 1.32.0 → 1.32.1

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/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(`sync-store`)
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
- if (options.debug) {
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
- useDebugStoreComponent(StoreKlass)
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
- if (debug) {
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
- if (debug) {
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
- opts?: { avoidCache: boolean },
147
+ options?: UseStoreOptions & { avoidCache?: boolean },
204
148
  propsKeyCalculated?: string
205
149
  ) {
206
150
  const uid = getStoreUid(StoreKlass, propsKeyCalculated ?? props)
207
-
208
- if (!opts?.avoidCache) {
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: string[] = []
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.push(key)
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 (!opts?.avoidCache) {
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.firstRun ? info.stateKeys : [...curInternal.tracked]
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
- const nextKeys = `${store._version}${keys.join('')}${userSelector?.toString() || ''}`
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,7 +288,7 @@ 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
  }
368
293
  if (isUnchanged) {
369
294
  return last
@@ -376,26 +301,7 @@ function useStoreFromInfo(
376
301
  ? useSyncExternalStore(store.subscribe, getSnapshot, getSnapshot)
377
302
  : useAsyncExternalStore(store.subscribe, getSnapshot, getSnapshot)
378
303
 
379
- // dispose tracker on unmount
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 {
304
+ if (userSelector) {
399
305
  return state
400
306
  }
401
307
 
@@ -407,6 +313,14 @@ function useStoreFromInfo(
407
313
  if (isInReaction) {
408
314
  return curVal
409
315
  }
316
+ const keyString = key as string // fine for our uses
317
+ if (info.stateKeys.has(keyString) || keyString in info.getters) {
318
+ if (shouldPrintDebug) {
319
+ // rome-ignore lint/nursery/noConsoleLog: <explanation>
320
+ console.log('tracking', keyString)
321
+ }
322
+ curInternal.tracked.add(keyString)
323
+ }
410
324
  if (Reflect.has(state, key)) {
411
325
  return Reflect.get(state, key)
412
326
  }
@@ -422,6 +336,7 @@ function createProxiedStore(storeInfo: Omit<StoreInfo, 'store' | 'source'>) {
422
336
  const { actions, storeInstance, getters, gettersState } = storeInfo
423
337
  const { getCache, curGetKeys, depsToGetter } = gettersState
424
338
  const constr = storeInstance.constructor
339
+ const shouldDebug = storeInfo.debug ?? DebugStores.has(constr)
425
340
 
426
341
  let didSet = false
427
342
  let isInAction = false
@@ -446,7 +361,7 @@ function createProxiedStore(storeInfo: Omit<StoreInfo, 'store' | 'source'>) {
446
361
  if (isGetFn || gettersState.isGetting) {
447
362
  return Reflect.apply(actionFn, proxiedStore, args)
448
363
  }
449
- if (process.env.NODE_ENV === 'development' && DebugStores.has(constr)) {
364
+ if (process.env.NODE_ENV === 'development' && shouldDebug) {
450
365
  // rome-ignore lint/nursery/noConsoleLog: <explanation>
451
366
  console.log('(debug) startAction', key, { isInAction })
452
367
  }
@@ -466,7 +381,7 @@ function createProxiedStore(storeInfo: Omit<StoreInfo, 'store' | 'source'>) {
466
381
  const ogAction = wrappedActions[key]
467
382
  wrappedActions[key] = new Proxy(ogAction, {
468
383
  apply(target, thisArg, args) {
469
- const isDebugging = DebugStores.has(constr)
384
+ const isDebugging = shouldDebug || storeInfo.debug
470
385
  const shouldLog =
471
386
  process.env.LOG_LEVEL !== '0' &&
472
387
  (isDebugging || configureOpts.logLevel !== 'error')
@@ -566,23 +481,23 @@ function createProxiedStore(storeInfo: Omit<StoreInfo, 'store' | 'source'>) {
566
481
  },
567
482
  })
568
483
  }
569
- }
570
- }
571
484
 
572
- function hashCode(str: string) {
573
- let hash = 0
574
- for (let i = 0; i < str.length; i++) {
575
- hash = str.charCodeAt(i) + ((hash << 5) - hash)
576
- }
577
- return hash
578
- }
485
+ function hashCode(str: string) {
486
+ let hash = 0
487
+ for (let i = 0; i < str.length; i++) {
488
+ hash = str.charCodeAt(i) + ((hash << 5) - hash)
489
+ }
490
+ return hash
491
+ }
579
492
 
580
- function strColor(str: string) {
581
- return `hsl(${hashCode(str) % 360}, 90%, 40%)`
493
+ function strColor(str: string) {
494
+ return `hsl(${hashCode(str) % 360}, 90%, 40%)`
495
+ }
496
+ }
582
497
  }
583
498
 
584
499
  const finishAction = (val?: any) => {
585
- if (process.env.NODE_ENV === 'development' && DebugStores.has(constr)) {
500
+ if (process.env.NODE_ENV === 'development' && shouldDebug) {
586
501
  // rome-ignore lint/nursery/noConsoleLog: <explanation>
587
502
  console.log('(debug) finishAction', { didSet })
588
503
  }
@@ -624,14 +539,11 @@ function createProxiedStore(storeInfo: Omit<StoreInfo, 'store' | 'source'>) {
624
539
 
625
540
  // non-actions...
626
541
 
627
- const shouldPrintDebug =
628
- process.env.NODE_ENV === 'development' && DebugStores.has(constr)
629
-
630
542
  if (!trackingDisabled) {
631
543
  if (gettersState.isGetting) {
632
544
  gettersState.curGetKeys.add(key)
633
545
  } else {
634
- storeInstance[TRACK](key, shouldPrintDebug)
546
+ // storeInstance[TRACK](key, shouldDebug)
635
547
  }
636
548
  }
637
549
 
@@ -676,7 +588,7 @@ function createProxiedStore(storeInfo: Omit<StoreInfo, 'store' | 'source'>) {
676
588
  if (typeof key === 'string') {
677
589
  clearGetterCache(key)
678
590
  }
679
- if (process.env.LOG_LEVEL && configureOpts.logLevel !== 'error') {
591
+ if (shouldDebug) {
680
592
  setters.add({ key, value })
681
593
  if (storeInstance[SHOULD_DEBUG]()) {
682
594
  // 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
@@ -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,UAAU,EAAE,OAAO,CAAA;IACnB,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACpB,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,SAAS,CAAC,EAAE,GAAG,CAAA;IACf,QAAQ,EAAE,OAAO,CAAA;IACjB,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;IAOhB,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE,YAAY;IAOnC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;IAmBpC,CAAC,YAAY,CAAC;CAMf"}
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"}
@@ -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,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AAW,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"}
@@ -16,7 +16,8 @@ export type StoreInfo<A = Store> = {
16
16
  [key: string]: any;
17
17
  };
18
18
  actions: any;
19
- stateKeys: string[];
19
+ stateKeys: Set<string>;
20
+ debug?: boolean;
20
21
  gettersState: {
21
22
  getCache: Map<string, any>;
22
23
  depsToGetter: Map<string, Set<string>>;
@@ -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,CAAC,KAAK,GAAG,GAAG,EAAE,WAAW,GAAG,GAAG,IAAI;IAC5D,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,QAAQ,CAAC,EAAE,gBAAgB,CAAC,KAAK,EAAE,WAAW,CAAC,CAAA;IAC/C,IAAI,CAAC,EAAE,OAAO,CAAA;CACf,CAAA;AAED,MAAM,MAAM,SAAS,CAAC,CAAC,GAAG,KAAK,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,C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O,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"}
@@ -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, selector?: any): A;
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;
@@ -1 +1 @@
1
- {"version":3,"file":"useStore.d.ts","sourceRoot":"","sources":["../src/useStore.tsx"],"names":[],"mappings":"AAkBA,OAAO,EAAE,QAAQ,EAAa,eAAe,EAAE,MAAM,cAAc,CAAA;AACnE,OAAO,EAGL,KAAK,EAMN,MAAM,SAAS,CAAA;AA2BhB,wBAAgB,QAAQ,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,EAC3D,UAAU,EAAE,CAAC,KAAK,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,EACjD,KAAK,CAAC,EAAE,CAAC,EACT,OAAO,GAAE,eAAe,CAAC,CAAC,EAAE,GAAG,CAAkB,GAChD,CAAC,CAkBH;AAED,wBAAgB,aAAa,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,SA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