@legendapp/state 0.9.2-alpha.9 → 0.10.0-next.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.
Files changed (93) hide show
  1. package/index.cjs +634 -0
  2. package/index.cjs.map +1 -0
  3. package/index.d.ts +10 -6
  4. package/index.esm.mjs +613 -0
  5. package/index.esm.mjs.map +1 -0
  6. package/index.js +633 -42
  7. package/index.js.map +1 -1
  8. package/internal.cjs +26 -0
  9. package/internal.cjs.map +1 -0
  10. package/internal.d.ts +2 -3
  11. package/internal.esm.mjs +3 -0
  12. package/internal.esm.mjs.map +1 -0
  13. package/internal.js +26 -12
  14. package/internal.js.map +1 -1
  15. package/{src/persist/local-storage.js → local-storage.cjs} +6 -4
  16. package/local-storage.cjs.map +1 -0
  17. package/local-storage.esm.mjs +36 -0
  18. package/local-storage.esm.mjs.map +1 -0
  19. package/local-storage.js +39 -17
  20. package/local-storage.js.map +1 -1
  21. package/{src/persist/mmkv.js → mmkv.cjs} +9 -6
  22. package/mmkv.cjs.map +1 -0
  23. package/mmkv.esm.mjs +50 -0
  24. package/mmkv.esm.mjs.map +1 -0
  25. package/mmkv.js +53 -17
  26. package/mmkv.js.map +1 -1
  27. package/package.json +34 -10
  28. package/persist.cjs +195 -0
  29. package/persist.cjs.map +1 -0
  30. package/persist.d.ts +6 -0
  31. package/persist.esm.mjs +188 -0
  32. package/persist.esm.mjs.map +1 -0
  33. package/persist.js +195 -0
  34. package/persist.js.map +1 -0
  35. package/react.cjs +124 -0
  36. package/react.cjs.map +1 -0
  37. package/react.d.ts +1 -3
  38. package/react.esm.mjs +119 -0
  39. package/react.esm.mjs.map +1 -0
  40. package/react.js +123 -20
  41. package/react.js.map +1 -1
  42. package/src/globals.d.ts +12 -7
  43. package/src/helpers.d.ts +5 -0
  44. package/src/is.d.ts +7 -0
  45. package/src/observable.d.ts +6 -8
  46. package/src/observableBatcher.d.ts +11 -2
  47. package/src/observableComputed.d.ts +2 -2
  48. package/src/observableInterfaces.d.ts +156 -49
  49. package/src/on.d.ts +7 -0
  50. package/src/{configureObservable.d.ts → persist/configureObservablePersistence.d.ts} +2 -3
  51. package/src/persist/persistHelpers.d.ts +3 -0
  52. package/src/persist/persistObservable.d.ts +3 -0
  53. package/src/react/useNewObservable.d.ts +2 -3
  54. package/src/react/useObservables.d.ts +2 -2
  55. package/src/state.d.ts +13 -0
  56. package/src/configureObservable.js +0 -13
  57. package/src/configureObservable.js.map +0 -1
  58. package/src/globals.js +0 -71
  59. package/src/globals.js.map +0 -1
  60. package/src/observable.js +0 -347
  61. package/src/observable.js.map +0 -1
  62. package/src/observableBatcher.js +0 -61
  63. package/src/observableBatcher.js.map +0 -1
  64. package/src/observableComputed.js +0 -28
  65. package/src/observableComputed.js.map +0 -1
  66. package/src/observableEvent.js +0 -28
  67. package/src/observableEvent.js.map +0 -1
  68. package/src/observableFns.d.ts +0 -36
  69. package/src/observableFns.js +0 -231
  70. package/src/observableFns.js.map +0 -1
  71. package/src/observableInterfaces.js +0 -3
  72. package/src/observableInterfaces.js.map +0 -1
  73. package/src/observableState.d.ts +0 -29
  74. package/src/observableState.js +0 -32
  75. package/src/observableState.js.map +0 -1
  76. package/src/persist/local-storage.js.map +0 -1
  77. package/src/persist/mmkv.js.map +0 -1
  78. package/src/persistObservable.d.ts +0 -3
  79. package/src/persistObservable.js +0 -120
  80. package/src/persistObservable.js.map +0 -1
  81. package/src/primitivePrototypes.d.ts +0 -1
  82. package/src/primitivePrototypes.js +0 -22
  83. package/src/primitivePrototypes.js.map +0 -1
  84. package/src/react/useComputed.d.ts +0 -2
  85. package/src/react/useComputed.js +0 -16
  86. package/src/react/useComputed.js.map +0 -1
  87. package/src/react/useNewObservable.js +0 -33
  88. package/src/react/useNewObservable.js.map +0 -1
  89. package/src/react/useObservables.js +0 -114
  90. package/src/react/useObservables.js.map +0 -1
  91. package/src/react/usePrimitiveFunctions.d.ts +0 -4
  92. package/src/react/usePrimitiveFunctions.js +0 -21
  93. package/src/react/usePrimitiveFunctions.js.map +0 -1
@@ -1,69 +1,141 @@
1
+ import { symbolShallow, symbolShouldRender } from './globals';
1
2
  export declare type ObservableEventType = 'change' | 'changeShallow' | 'equals' | 'hasValue' | 'true';
2
- export declare type ObservableFnName = 'get' | 'set' | 'assign' | 'on' | 'prop' | 'delete';
3
- export interface ObservableBaseProps<T> {
3
+ export interface ObservableBaseFns<T> {
4
4
  get(): T;
5
+ onChange(cb: ListenerFn<T>): ObservableListener<T>;
6
+ onChangeShallow(cb: ListenerFn<T>): ObservableListener<T>;
7
+ onEquals(value: T, cb?: (value?: T) => void): OnReturnValue<T>;
8
+ onTrue(cb?: (value?: T) => void): OnReturnValue<T>;
9
+ onHasValue(cb?: (value?: T) => void): OnReturnValue<T>;
10
+ }
11
+ export interface ObservablePrimitiveFns<T> extends ObservableBaseFns<T> {
12
+ set(value: T): Observable<T>;
13
+ }
14
+ export interface ObservableFns<T> extends ObservablePrimitiveFns<T> {
5
15
  prop<K extends keyof T>(prop: K): Observable<T[K]>;
6
- on(eventType: 'change', cb: ListenerFn<T>): ObservableListener<T>;
7
- on(eventType: 'changeShallow', cb: ListenerFn<T>): ObservableListener<T>;
8
- on(eventType: 'equals', value: T, cb?: (value?: T) => void): {
9
- listener: ObservableListener<T>;
10
- promise: Promise<T>;
11
- };
12
- on(eventType: 'hasValue', cb?: (value?: T) => void): {
16
+ set(value: T): Observable<T>;
17
+ set<K extends keyof T>(key: K, value: T[K]): Observable<T[K]>;
18
+ set<V>(key: string | number, value: V): Observable<V>;
19
+ assign(value: T | Partial<T>): Observable<T>;
20
+ delete(): Observable<T>;
21
+ delete<K extends keyof T>(key: K | string | number): Observable<T>;
22
+ }
23
+ export interface ObservableComputedFns<T> {
24
+ get(): T;
25
+ onChange(cb: ListenerFn<T>): ObservableListener<T>;
26
+ onEquals(value: T, cb?: (value?: T) => void): {
13
27
  listener: ObservableListener<T>;
14
28
  promise: Promise<T>;
15
29
  };
16
- on(eventType: 'true', cb?: (value?: T) => void): {
30
+ onTrue(cb?: (value?: T) => void): {
17
31
  listener: ObservableListener<T>;
18
32
  promise: Promise<T>;
19
33
  };
20
- on(eventType: ObservableEventType, cb?: (value?: T) => void): ObservableListener<T> | {
34
+ onHasValue(cb?: (value?: T) => void): {
21
35
  listener: ObservableListener<T>;
22
36
  promise: Promise<T>;
23
37
  };
24
38
  }
25
- export interface ObservableProps<T> extends ObservableBaseProps<T> {
26
- set(value: ValidObservableParam<T>): Observable<T>;
27
- set<K extends keyof T>(key: K | string | number, value: ValidObservableParam<T[K]>): Observable<T[K]>;
28
- assign(value: ValidObservableParam<T> | Partial<ValidObservableParam<T>>): Observable<T>;
29
- delete(): Observable<T>;
30
- delete<K extends keyof T>(key: K | string | number): Observable<T>;
31
- }
32
- export declare type ObservablePropsUnsafe<T> = Partial<ObservableProps<T>>;
33
- export interface ObservableListener<T = any> {
34
- target: Observable<T>;
35
- callback: ListenerFn<T>;
36
- shallow: boolean;
37
- dispose: () => void;
38
- isDisposed: boolean;
39
+ declare type ArrayOverrideFnNames = 'every' | 'some' | 'filter' | 'reduce' | 'reduceRight' | 'forEach' | 'map';
40
+ export interface ObservableArrayOverride<T> extends Omit<Array<T>, ArrayOverrideFnNames> {
41
+ /**
42
+ * Determines whether all the members of an array satisfy the specified test.
43
+ * @param predicate A function that accepts up to three arguments. The every method calls
44
+ * the predicate function for each element in the array until the predicate returns a value
45
+ * which is coercible to the Boolean value false, or until the end of the array.
46
+ * @param thisArg An object to which the this keyword can refer in the predicate function.
47
+ * If thisArg is omitted, undefined is used as the this value.
48
+ */
49
+ every<S extends T>(predicate: (value: T, index: number, array: T[]) => value is S, thisArg?: any): this is S[];
50
+ /**
51
+ * Determines whether all the members of an array satisfy the specified test.
52
+ * @param predicate A function that accepts up to three arguments. The every method calls
53
+ * the predicate function for each element in the array until the predicate returns a value
54
+ * which is coercible to the Boolean value false, or until the end of the array.
55
+ * @param thisArg An object to which the this keyword can refer in the predicate function.
56
+ * If thisArg is omitted, undefined is used as the this value.
57
+ */
58
+ every(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): boolean;
59
+ /**
60
+ * Determines whether the specified callback function returns true for any element of an array.
61
+ * @param predicate A function that accepts up to three arguments. The some method calls
62
+ * the predicate function for each element in the array until the predicate returns a value
63
+ * which is coercible to the Boolean value true, or until the end of the array.
64
+ * @param thisArg An object to which the this keyword can refer in the predicate function.
65
+ * If thisArg is omitted, undefined is used as the this value.
66
+ */
67
+ some(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): boolean;
68
+ /**
69
+ * Performs the specified action for each element in an array.
70
+ * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.
71
+ * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
72
+ */
73
+ forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void;
74
+ /**
75
+ * Calls a defined callback function on each element of an array, and returns an array that contains the results.
76
+ * @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.
77
+ * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
78
+ */
79
+ map<U>(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[];
80
+ /**
81
+ * Returns the elements of an array that meet the condition specified in a callback function.
82
+ * @param predicate A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.
83
+ * @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
84
+ */
85
+ filter<S extends T>(predicate: (value: T, index: number, array: T[]) => value is S, thisArg?: any): S[];
86
+ /**
87
+ * Returns the elements of an array that meet the condition specified in a callback function.
88
+ * @param predicate A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.
89
+ * @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
90
+ */
91
+ filter(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): T[];
92
+ /**
93
+ * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
94
+ * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.
95
+ * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
96
+ */
97
+ reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T;
98
+ reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T;
99
+ /**
100
+ * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
101
+ * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.
102
+ * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
103
+ */
104
+ reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U;
105
+ /**
106
+ * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
107
+ * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.
108
+ * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
109
+ */
110
+ reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T;
111
+ reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T;
112
+ /**
113
+ * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
114
+ * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.
115
+ * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
116
+ */
117
+ reduceRight<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U;
39
118
  }
40
119
  export interface ObservableListenerInfo {
41
- changedValue: any;
120
+ value: any;
42
121
  prevValue: any;
43
122
  path: string[];
44
123
  }
45
- export declare type ListenerFn<T> = (value: T, info: ObservableListenerInfo) => void;
46
- declare type Recurse<T, K extends keyof T, TRecurse> = T[K] extends Function | Map<any, any> | WeakMap<any, any> | Set<any> | WeakSet<any> | Promise<any> ? T[K] : T[K] extends Array<any> ? T[K] & ObservableProps<T[K]> & {
47
- [n: number]: TRecurse extends Observable ? Observable<T[K][number]> : ObservableUnsafe<T[K][number]>;
48
- } : T extends object ? TRecurse : T[K];
49
- declare type ObservablePropsRecursiveUnsafe<T> = {
50
- [K in keyof T]: Recurse<T, K, ObservableUnsafe<T[K]>>;
51
- };
52
- declare type ObservablePropsRecursive<T> = {
124
+ export declare type ListenerFn<T = any> = (value: T, prev: T, path: (string | number)[], valueAtPath: any, prevAtPath: any) => void;
125
+ declare type Recurse<T, K extends keyof T, TRecurse> = T[K] extends Function | Map<any, any> | WeakMap<any, any> | Set<any> | WeakSet<any> | Promise<any> ? T[K] : T[K] extends number | boolean | string ? Observable<T[K]> : T[K] extends Array<any> ? Omit<T[K], ArrayOverrideFnNames> & ObservableFns<T[K]> & ObservableArrayOverride<Observable<T[K][number]>> : T extends object ? TRecurse : T[K];
126
+ declare type ObservableFnsRecursive<T> = {
53
127
  readonly [K in keyof T]: Recurse<T, K, Observable<T[K]>>;
54
128
  };
55
- export declare type ObservableUnsafe<T = any> = ObservablePropsRecursiveUnsafe<T> & ObservablePropsUnsafe<T>;
56
- export declare type Observable<T = any> = ObservablePropsRecursive<T> & ObservableProps<T>;
57
- export declare type ObservableComputed<T = any> = ObservableBaseProps<T>;
129
+ export declare type Observable<T = any> = ObservableFnsRecursive<T> & ObservableFns<T>;
58
130
  export interface ObservableEvent {
59
131
  fire(): void;
60
132
  on(cb?: () => void): ObservableListener<void>;
61
133
  on(eventType: 'change', cb?: () => void): ObservableListener<void>;
62
134
  }
63
- export declare type ObservableValue<T extends Observable | ObservableUnsafe | ObservableEvent | ObservableComputed> = T extends ObservableEvent ? void : T extends ObservableComputed<infer t> ? t : T;
64
- export declare type MappedObservableValue<T extends ObservableCheckerLoose | ObservableCheckerLoose[] | Record<string, ObservableCheckerLoose>> = T extends ObservableCheckerStrict ? ObservableValue<T> : T extends object | Array<any> ? {
65
- [K in keyof T]: ObservableValue<T[K]>;
66
- } : ObservableValue<T>;
135
+ export interface ObservableEvent3 {
136
+ fire(): void;
137
+ on(cb?: () => void): ObservableListener<void>;
138
+ }
67
139
  export declare type QueryByModified<T> = boolean | '*' | {
68
140
  '*': '*' | true;
69
141
  } | {
@@ -110,10 +182,6 @@ export interface ObservablePersistState {
110
182
  isLoadedRemote: boolean;
111
183
  clearLocal: () => Promise<void>;
112
184
  }
113
- export declare type ObservableCheckerLoose<T = any> = Observable<T> | ObservableComputed<T> | ObservableEvent | ObservableUnsafe<T>;
114
- export declare type ObservableCheckerStrict<T = any> = Observable<T> | ObservableComputed<T>;
115
- export declare type ObservableChecker<T = any> = Observable<T> | ObservableComputed<T> | ObservableUnsafe<T>;
116
- export declare type ObservableCheckerWriteable<T = any> = Observable<T> | ObservableUnsafe<T>;
117
185
  export declare type RecordValue<T> = T extends Record<string, infer t> ? t : never;
118
186
  export declare type ArrayValue<T> = T extends Array<infer t> ? t : never;
119
187
  declare type SameShapeWithStringsRecord<T> = {
@@ -146,13 +214,52 @@ declare type SameShapeWithStringsRecord<T> = {
146
214
  declare type SameShapeWithStrings<T> = T extends Record<string, Record<string, any>> ? {
147
215
  __dict: SameShapeWithStrings<RecordValue<T>>;
148
216
  } | SameShapeWithStringsRecord<T> : SameShapeWithStringsRecord<T>;
149
- declare type DisallowedAttributes<T extends string> = Partial<Record<T, void>>;
150
- export declare type ValidObservableParam<T> = T extends Record<string, any> ? T extends Map<any, any> | WeakMap<any, any> | Set<any> | WeakSet<any> ? T : T extends Observable ? never : {
151
- [K in keyof T]: ValidObservableParam<T[K]>;
152
- } & DisallowedAttributes<ObservableFnName> : T;
153
217
  export interface OnReturnValue<T> {
154
218
  promise: Promise<T>;
155
219
  listener: ObservableListener<T>;
156
220
  }
157
221
  export declare type ClassConstructor<I, Args extends any[] = any[]> = new (...args: Args) => I;
222
+ export declare type Shallow<T = any> = {
223
+ [symbolShallow]: Observable<T>;
224
+ };
225
+ export declare type ShouldRender<T = any> = {
226
+ [symbolShouldRender]: {
227
+ obs: Observable<T>;
228
+ fn: (value: any, prev: any) => any;
229
+ };
230
+ };
231
+ export interface ObservableListener<T = any> {
232
+ node: ProxyValue;
233
+ callback: ListenerFn<T>;
234
+ shallow: boolean;
235
+ dispose: () => void;
236
+ isDisposed?: boolean;
237
+ }
238
+ export interface ObservableWrapper {
239
+ _: Observable;
240
+ isPrimitive: boolean;
241
+ listenerMap: Map<string, Set<ObservableListener>>;
242
+ proxies: Map<string, object>;
243
+ proxyValues: Map<string, ProxyValue>;
244
+ }
245
+ export declare type ObservablePrimitiveChild<T = any> = ObservablePrimitiveFns<T>;
246
+ export declare type ObservablePrimitive<T = any> = {
247
+ readonly current: T;
248
+ } & ObservablePrimitiveFns<T>;
249
+ export declare type ObservableComputed<T = any> = {
250
+ readonly current: T;
251
+ } & ObservableComputedFns<T>;
252
+ export declare type ObservableOrPrimitive<T> = T extends boolean | string | number ? ObservablePrimitive<T> : Observable<T>;
253
+ export declare type ObservableChecker<T = any> = Observable<T> | ObservableComputed<T> | ObservablePrimitive<T> | ObservablePrimitiveChild<T>;
254
+ export declare type ObservableCheckerRender<T = any> = Shallow<T> | ShouldRender<T> | Observable<T> | ObservableComputed<T> | ObservablePrimitiveChild<T> | ObservablePrimitive<T>;
255
+ export interface ProxyValue {
256
+ path: string;
257
+ pathParent: string;
258
+ key: string | number;
259
+ root: ObservableWrapper;
260
+ }
261
+ export declare type ObservableValue<T> = T extends Shallow<infer t> ? t : T extends ShouldRender<infer t> ? t : T extends Observable<infer t> ? t : T extends ObservableComputed<infer t> ? t : T extends ObservablePrimitive<infer t> ? t : T;
262
+ export declare type MappedObservableValue<T extends ObservableCheckerRender | ObservableCheckerRender[] | Record<string, ObservableCheckerRender>> = T extends ObservableCheckerRender ? ObservableValue<T> : T extends object | Array<any> ? {
263
+ [K in keyof T]: ObservableValue<T[K]>;
264
+ } : ObservableValue<T>;
158
265
  export {};
package/src/on.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { ListenerFn, ObservableListener, OnReturnValue, ProxyValue } from './observableInterfaces';
2
+ export declare function disposeListener(listener: ObservableListener): void;
3
+ export declare function onEquals<T>(node: ProxyValue, value: T, callback: (value: T) => void): OnReturnValue<T>;
4
+ export declare function onHasValue<T>(node: ProxyValue, callback: (value: T) => void): OnReturnValue<T>;
5
+ export declare function onTrue<T extends boolean>(node: ProxyValue, callback?: () => void): OnReturnValue<T>;
6
+ export declare function onChange(node: ProxyValue, callback: ListenerFn<any>, shallow?: boolean): ObservableListener<any>;
7
+ export declare function onChangeShallow(node: ProxyValue, callback: ListenerFn<any>): ObservableListener<any>;
@@ -1,11 +1,10 @@
1
- import { ClassConstructor, ObservablePersistLocal, ObservablePersistRemote } from './observableInterfaces';
1
+ import type { ClassConstructor, ObservablePersistLocal, ObservablePersistRemote } from '../observableInterfaces';
2
2
  interface Config {
3
- extendPrototypes?: boolean;
4
3
  persistLocal?: ClassConstructor<ObservablePersistLocal>;
5
4
  persistRemote?: ClassConstructor<ObservablePersistRemote>;
6
5
  saveTimeout?: number;
7
6
  dateModifiedKey?: string;
8
7
  }
9
8
  export declare const observableConfiguration: Config;
10
- export declare function configureObservable(options?: Config): void;
9
+ export declare function configureObservablePersistence(options?: Config): void;
11
10
  export {};
@@ -0,0 +1,3 @@
1
+ export declare function removeNullUndefined<T extends Record<string, any>>(a: T): any;
2
+ export declare function replaceKeyInObject(obj: object, keySource: any, keyTarget: any, clone: boolean): Record<any, any>;
3
+ export declare function getDateModifiedKey(dateModifiedKey: string): string;
@@ -0,0 +1,3 @@
1
+ import type { Observable, ObservablePersistState, PersistOptions } from '../observableInterfaces';
2
+ export declare const mapPersistences: WeakMap<any, any>;
3
+ export declare function persistObservable<T>(obs: Observable<T>, persistOptions: PersistOptions<T>): Observable<ObservablePersistState>;
@@ -1,4 +1,4 @@
1
- import { Observable, ValidObservableParam, PersistOptions } from '../observableInterfaces';
1
+ import type { ObservableOrPrimitive } from '../observableInterfaces';
2
2
  /**
3
3
  * A React hook that creates a new observable and can optionally listen or persist its state.
4
4
  *
@@ -8,5 +8,4 @@ import { Observable, ValidObservableParam, PersistOptions } from '../observableI
8
8
  *
9
9
  * @see https://www.legendapp.com/dev/state/react/#usenewobservable
10
10
  */
11
- declare function useNewObservable<T>(value: (() => ValidObservableParam<T>) | ValidObservableParam<T>, observe?: boolean, persist?: PersistOptions<T>): [Observable<T>, T];
12
- export { useNewObservable };
11
+ export declare function useNewObservable<T>(value: T | (() => T), observe?: boolean): [ObservableOrPrimitive<T>, T];
@@ -1,4 +1,4 @@
1
- import { MappedObservableValue, ObservableCheckerLoose } from '../observableInterfaces';
1
+ import type { MappedObservableValue, ObservableCheckerRender } from '../observableInterfaces';
2
2
  /**
3
3
  * A React hook that listens to observables and returns their values.
4
4
  *
@@ -6,4 +6,4 @@ import { MappedObservableValue, ObservableCheckerLoose } from '../observableInte
6
6
  *
7
7
  * @see https://www.legendapp.com/dev/state/react/#useobservables
8
8
  */
9
- export declare function useObservables<T extends ObservableCheckerLoose | ObservableCheckerLoose[] | Record<string, ObservableCheckerLoose>>(fn: () => T): MappedObservableValue<T>;
9
+ export declare function useObservables<T extends ObservableCheckerRender | Record<string, ObservableCheckerRender> | ObservableCheckerRender[]>(fn: () => T): MappedObservableValue<T>;
package/src/state.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import type { ProxyValue } from './observableInterfaces';
2
+ export declare const tracking: {
3
+ is: boolean;
4
+ shallow: boolean;
5
+ should: (value: any, prev?: any) => any;
6
+ };
7
+ export declare const trackedNodes: {
8
+ node: ProxyValue;
9
+ shallow?: boolean;
10
+ shouldRender?: (value: any, prev?: any) => any;
11
+ value: any;
12
+ }[];
13
+ export declare function updateTracking(node: ProxyValue, value: any): void;
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.configureObservable = exports.observableConfiguration = void 0;
4
- const primitivePrototypes_1 = require("./primitivePrototypes");
5
- exports.observableConfiguration = { extendPrototypes: true };
6
- function configureObservable(options) {
7
- Object.assign(exports.observableConfiguration, options);
8
- if (exports.observableConfiguration.extendPrototypes) {
9
- (0, primitivePrototypes_1.extendPrototypes)();
10
- }
11
- }
12
- exports.configureObservable = configureObservable;
13
- //# sourceMappingURL=configureObservable.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"configureObservable.js","sourceRoot":"","sources":["../../src/configureObservable.ts"],"names":[],"mappings":";;;AAAA,+DAAyD;AAW5C,QAAA,uBAAuB,GAAW,EAAE,gBAAgB,EAAE,IAAI,EAAE,CAAC;AAE1E,SAAgB,mBAAmB,CAAC,OAAgB;IAChD,MAAM,CAAC,MAAM,CAAC,+BAAuB,EAAE,OAAO,CAAC,CAAC;IAChD,IAAI,+BAAuB,CAAC,gBAAgB,EAAE;QAC1C,IAAA,sCAAgB,GAAE,CAAC;KACtB;AACL,CAAC;AALD,kDAKC"}
package/src/globals.js DELETED
@@ -1,71 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.clone = exports.getDateModifiedKey = exports.isCollection = exports.isPrimitive = exports.replaceKeyInObject = exports.removeNullUndefined = exports.symbolValue = exports.symbolShallow = exports.symbolDateModified = void 0;
4
- const tools_1 = require("@legendapp/tools");
5
- const configureObservable_1 = require("./configureObservable");
6
- exports.symbolDateModified = Symbol('__dateModified');
7
- exports.symbolShallow = Symbol('__shallow');
8
- exports.symbolValue = Symbol('__value');
9
- function removeNullUndefined(a) {
10
- if (a === undefined)
11
- return null;
12
- Object.keys(a).forEach((key) => {
13
- const v = a[key];
14
- if (v === null || v === undefined) {
15
- delete a[key];
16
- }
17
- else if ((0, tools_1.isObject)(v)) {
18
- removeNullUndefined(v);
19
- }
20
- });
21
- }
22
- exports.removeNullUndefined = removeNullUndefined;
23
- function replaceKeyInObject(obj, keySource, keyTarget, clone) {
24
- if ((0, tools_1.isObject)(obj)) {
25
- const target = clone ? {} : obj;
26
- if (obj[keySource]) {
27
- target[keyTarget] = obj[keySource];
28
- delete target[keySource];
29
- }
30
- Object.keys(obj).forEach((key) => {
31
- if (key !== keySource) {
32
- target[key] = replaceKeyInObject(obj[key], keySource, keyTarget, clone);
33
- }
34
- });
35
- return target;
36
- }
37
- else {
38
- return obj;
39
- }
40
- }
41
- exports.replaceKeyInObject = replaceKeyInObject;
42
- function isPrimitive(val) {
43
- return (!(0, tools_1.isObject)(val) &&
44
- !(0, tools_1.isArray)(val) &&
45
- !(val instanceof WeakMap) &&
46
- !(val instanceof WeakSet) &&
47
- !(val instanceof Error) &&
48
- !(val instanceof Date) &&
49
- !(val instanceof String) &&
50
- !(val instanceof ArrayBuffer));
51
- }
52
- exports.isPrimitive = isPrimitive;
53
- function isCollection(obj) {
54
- return (0, tools_1.isArray)(obj) || obj instanceof Map || obj instanceof Set || obj instanceof WeakMap || obj instanceof WeakSet;
55
- }
56
- exports.isCollection = isCollection;
57
- function getDateModifiedKey(dateModifiedKey) {
58
- return dateModifiedKey || configureObservable_1.observableConfiguration.dateModifiedKey || '@';
59
- }
60
- exports.getDateModifiedKey = getDateModifiedKey;
61
- function clone(obj) {
62
- return obj === undefined || obj === null
63
- ? obj
64
- : (0, tools_1.isArray)(obj)
65
- ? obj.slice()
66
- : (0, tools_1.isObject)(obj)
67
- ? Object.assign({}, obj)
68
- : JSON.parse(JSON.stringify(obj));
69
- }
70
- exports.clone = clone;
71
- //# sourceMappingURL=globals.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"globals.js","sourceRoot":"","sources":["../../src/globals.ts"],"names":[],"mappings":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