@legendapp/state 3.0.0-beta.32 → 3.0.0-beta.34
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/index.d.mts +7 -4
- package/index.d.ts +7 -4
- package/index.js +2 -1
- package/index.mjs +2 -1
- package/package.json +1 -1
- package/react.d.mts +8 -0
- package/react.d.ts +8 -0
- package/react.js +38 -20
- package/react.mjs +38 -20
- package/sync.d.mts +2 -1
- package/sync.d.ts +2 -1
- package/sync.js +39 -17
- package/sync.mjs +39 -18
package/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type Primitive$1 = string | number | boolean | symbol | bigint | undefined | null | Date
|
|
1
|
+
type Primitive$1 = string | number | boolean | symbol | bigint | undefined | null | Date | OpaqueObject<unknown>;
|
|
2
2
|
type ArrayOverrideFnNames = 'find' | 'findIndex' | 'every' | 'some' | 'filter' | 'reduce' | 'reduceRight' | 'forEach' | 'map' | 'sort';
|
|
3
3
|
type RemoveIndex<T> = {
|
|
4
4
|
[K in keyof T as string extends K ? never : number extends K ? never : K]: T[K];
|
|
@@ -7,7 +7,7 @@ type BuiltIns = String | Boolean | Number | Date | Error | RegExp | Array<any> |
|
|
|
7
7
|
type IsUserDefinedObject<T> = T extends Function | BuiltIns | any[] ? false : T extends object ? true : false;
|
|
8
8
|
type RemoveObservables<T> = T extends ImmutableObservableBase<infer t> ? t : T extends ImmutableObservableBase<infer t>[] ? t[] : IsUserDefinedObject<T> extends true ? {
|
|
9
9
|
[K in keyof T]: RemoveObservables<T[K]>;
|
|
10
|
-
} : T extends ImmutableObservableBase<infer TObs> ? TObs : T extends () => infer TRet ? RemoveObservables<TRet> & T : T extends (key: infer TKey extends string | number) => infer TRet ? Record<TKey, RemoveObservables<TRet>> & T : T;
|
|
10
|
+
} : T extends ImmutableObservableBase<infer TObs> ? TObs : T extends () => infer TRet ? RemoveObservables<TRet> & T : T extends (key: infer TKey extends string | number) => infer TRet ? Record<TKey, RemoveObservables<TRet>> & T : T extends OpaqueObject<infer TObj> ? TObj : T;
|
|
11
11
|
interface ObservableArray<T, U> extends ObservablePrimitive<T>, Pick<Array<Observable<U>>, ArrayOverrideFnNames>, Omit<RemoveIndex<Array<U>>, ArrayOverrideFnNames> {
|
|
12
12
|
}
|
|
13
13
|
interface ObservableObjectFns<T> {
|
|
@@ -262,6 +262,9 @@ type Linked<T> = T;
|
|
|
262
262
|
interface ObserveOptions {
|
|
263
263
|
immediate?: boolean;
|
|
264
264
|
}
|
|
265
|
+
interface ObservableSyncStateOptions {
|
|
266
|
+
resetLastSync?: boolean;
|
|
267
|
+
}
|
|
265
268
|
interface ObservableSyncStateBase {
|
|
266
269
|
isPersistLoaded: boolean;
|
|
267
270
|
isPersistEnabled: boolean;
|
|
@@ -272,7 +275,7 @@ interface ObservableSyncStateBase {
|
|
|
272
275
|
isSetting?: boolean;
|
|
273
276
|
numPendingGets?: number;
|
|
274
277
|
numPendingSets?: number;
|
|
275
|
-
sync: () => Promise<void>;
|
|
278
|
+
sync: (options?: ObservableSyncStateOptions) => Promise<void>;
|
|
276
279
|
getPendingChanges: () => Record<string, {
|
|
277
280
|
p: any;
|
|
278
281
|
v?: any;
|
|
@@ -461,4 +464,4 @@ declare const internal: {
|
|
|
461
464
|
};
|
|
462
465
|
};
|
|
463
466
|
|
|
464
|
-
export { type ArrayValue, type Change, type ChildNodeInfo, type ClassConstructor, type GetMode, type GetOptions, type ImmutableObservableBase, type Linked, type LinkedOptions, type ListenerFn, type ListenerParams, type NodeInfo, type NodeListener, type NotPrimitive, type Observable, type ObservableBoolean, type ObservableEvent, ObservableHint, type ObservableListenerDispose, type ObservableMap, type ObservableObject, type ObservableObjectFns, type ObservableParam, type ObservablePrimitive, type ObservableRoot, type ObservableState, type ObservableSyncState, type ObservableSyncStateBase, type ObservableValue, type ObserveEvent, type ObserveEventCallback, type ObserveOptions, type OpaqueObject, type PlainObject, type Primitive, type RecordValue, type RecursiveValueOrFunction, type RemoveObservables, type RetryOptions, type RootNodeInfo, type Selector, type SetParams, type TrackingNode, type TrackingState, type TrackingType, type TypeAtPath, type UpdateFn, type UpdateFnParams, type UpdateSetFn, type UpdateSetFnParams, type WaitForSet, type WaitForSetFnParams, applyChange, applyChanges, batch, beginBatch, computeSelector, computed, constructObjectWithPath, deconstructObjectWithPath, endBatch, event, getObservableIndex, hasOwnProperty, internal, isArray, isBoolean, isDate, isEmpty, isFunction, isMap, isNullOrUndefined, isNumber, isObject, isObservable, isObservableValueReady, isObserved, isPlainObject, isPrimitive, isPromise, isSet, isString, isSymbol, linked, mergeIntoObservable, observable, observablePrimitive, observe, opaqueObject, proxy, setAtPath, setSilently, shouldIgnoreUnobserved, syncState, trackSelector, when, whenReady };
|
|
467
|
+
export { type ArrayValue, type Change, type ChildNodeInfo, type ClassConstructor, type GetMode, type GetOptions, type ImmutableObservableBase, type Linked, type LinkedOptions, type ListenerFn, type ListenerParams, type NodeInfo, type NodeListener, type NotPrimitive, type Observable, type ObservableBoolean, type ObservableEvent, ObservableHint, type ObservableListenerDispose, type ObservableMap, type ObservableObject, type ObservableObjectFns, type ObservableParam, type ObservablePrimitive, type ObservableRoot, type ObservableState, type ObservableSyncState, type ObservableSyncStateBase, type ObservableSyncStateOptions, type ObservableValue, type ObserveEvent, type ObserveEventCallback, type ObserveOptions, type OpaqueObject, type PlainObject, type Primitive, type RecordValue, type RecursiveValueOrFunction, type RemoveObservables, type RetryOptions, type RootNodeInfo, type Selector, type SetParams, type TrackingNode, type TrackingState, type TrackingType, type TypeAtPath, type UpdateFn, type UpdateFnParams, type UpdateSetFn, type UpdateSetFnParams, type WaitForSet, type WaitForSetFnParams, applyChange, applyChanges, batch, beginBatch, computeSelector, computed, constructObjectWithPath, deconstructObjectWithPath, endBatch, event, getObservableIndex, hasOwnProperty, internal, isArray, isBoolean, isDate, isEmpty, isFunction, isMap, isNullOrUndefined, isNumber, isObject, isObservable, isObservableValueReady, isObserved, isPlainObject, isPrimitive, isPromise, isSet, isString, isSymbol, linked, mergeIntoObservable, observable, observablePrimitive, observe, opaqueObject, proxy, setAtPath, setSilently, shouldIgnoreUnobserved, syncState, trackSelector, when, whenReady };
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type Primitive$1 = string | number | boolean | symbol | bigint | undefined | null | Date
|
|
1
|
+
type Primitive$1 = string | number | boolean | symbol | bigint | undefined | null | Date | OpaqueObject<unknown>;
|
|
2
2
|
type ArrayOverrideFnNames = 'find' | 'findIndex' | 'every' | 'some' | 'filter' | 'reduce' | 'reduceRight' | 'forEach' | 'map' | 'sort';
|
|
3
3
|
type RemoveIndex<T> = {
|
|
4
4
|
[K in keyof T as string extends K ? never : number extends K ? never : K]: T[K];
|
|
@@ -7,7 +7,7 @@ type BuiltIns = String | Boolean | Number | Date | Error | RegExp | Array<any> |
|
|
|
7
7
|
type IsUserDefinedObject<T> = T extends Function | BuiltIns | any[] ? false : T extends object ? true : false;
|
|
8
8
|
type RemoveObservables<T> = T extends ImmutableObservableBase<infer t> ? t : T extends ImmutableObservableBase<infer t>[] ? t[] : IsUserDefinedObject<T> extends true ? {
|
|
9
9
|
[K in keyof T]: RemoveObservables<T[K]>;
|
|
10
|
-
} : T extends ImmutableObservableBase<infer TObs> ? TObs : T extends () => infer TRet ? RemoveObservables<TRet> & T : T extends (key: infer TKey extends string | number) => infer TRet ? Record<TKey, RemoveObservables<TRet>> & T : T;
|
|
10
|
+
} : T extends ImmutableObservableBase<infer TObs> ? TObs : T extends () => infer TRet ? RemoveObservables<TRet> & T : T extends (key: infer TKey extends string | number) => infer TRet ? Record<TKey, RemoveObservables<TRet>> & T : T extends OpaqueObject<infer TObj> ? TObj : T;
|
|
11
11
|
interface ObservableArray<T, U> extends ObservablePrimitive<T>, Pick<Array<Observable<U>>, ArrayOverrideFnNames>, Omit<RemoveIndex<Array<U>>, ArrayOverrideFnNames> {
|
|
12
12
|
}
|
|
13
13
|
interface ObservableObjectFns<T> {
|
|
@@ -262,6 +262,9 @@ type Linked<T> = T;
|
|
|
262
262
|
interface ObserveOptions {
|
|
263
263
|
immediate?: boolean;
|
|
264
264
|
}
|
|
265
|
+
interface ObservableSyncStateOptions {
|
|
266
|
+
resetLastSync?: boolean;
|
|
267
|
+
}
|
|
265
268
|
interface ObservableSyncStateBase {
|
|
266
269
|
isPersistLoaded: boolean;
|
|
267
270
|
isPersistEnabled: boolean;
|
|
@@ -272,7 +275,7 @@ interface ObservableSyncStateBase {
|
|
|
272
275
|
isSetting?: boolean;
|
|
273
276
|
numPendingGets?: number;
|
|
274
277
|
numPendingSets?: number;
|
|
275
|
-
sync: () => Promise<void>;
|
|
278
|
+
sync: (options?: ObservableSyncStateOptions) => Promise<void>;
|
|
276
279
|
getPendingChanges: () => Record<string, {
|
|
277
280
|
p: any;
|
|
278
281
|
v?: any;
|
|
@@ -461,4 +464,4 @@ declare const internal: {
|
|
|
461
464
|
};
|
|
462
465
|
};
|
|
463
466
|
|
|
464
|
-
export { type ArrayValue, type Change, type ChildNodeInfo, type ClassConstructor, type GetMode, type GetOptions, type ImmutableObservableBase, type Linked, type LinkedOptions, type ListenerFn, type ListenerParams, type NodeInfo, type NodeListener, type NotPrimitive, type Observable, type ObservableBoolean, type ObservableEvent, ObservableHint, type ObservableListenerDispose, type ObservableMap, type ObservableObject, type ObservableObjectFns, type ObservableParam, type ObservablePrimitive, type ObservableRoot, type ObservableState, type ObservableSyncState, type ObservableSyncStateBase, type ObservableValue, type ObserveEvent, type ObserveEventCallback, type ObserveOptions, type OpaqueObject, type PlainObject, type Primitive, type RecordValue, type RecursiveValueOrFunction, type RemoveObservables, type RetryOptions, type RootNodeInfo, type Selector, type SetParams, type TrackingNode, type TrackingState, type TrackingType, type TypeAtPath, type UpdateFn, type UpdateFnParams, type UpdateSetFn, type UpdateSetFnParams, type WaitForSet, type WaitForSetFnParams, applyChange, applyChanges, batch, beginBatch, computeSelector, computed, constructObjectWithPath, deconstructObjectWithPath, endBatch, event, getObservableIndex, hasOwnProperty, internal, isArray, isBoolean, isDate, isEmpty, isFunction, isMap, isNullOrUndefined, isNumber, isObject, isObservable, isObservableValueReady, isObserved, isPlainObject, isPrimitive, isPromise, isSet, isString, isSymbol, linked, mergeIntoObservable, observable, observablePrimitive, observe, opaqueObject, proxy, setAtPath, setSilently, shouldIgnoreUnobserved, syncState, trackSelector, when, whenReady };
|
|
467
|
+
export { type ArrayValue, type Change, type ChildNodeInfo, type ClassConstructor, type GetMode, type GetOptions, type ImmutableObservableBase, type Linked, type LinkedOptions, type ListenerFn, type ListenerParams, type NodeInfo, type NodeListener, type NotPrimitive, type Observable, type ObservableBoolean, type ObservableEvent, ObservableHint, type ObservableListenerDispose, type ObservableMap, type ObservableObject, type ObservableObjectFns, type ObservableParam, type ObservablePrimitive, type ObservableRoot, type ObservableState, type ObservableSyncState, type ObservableSyncStateBase, type ObservableSyncStateOptions, type ObservableValue, type ObserveEvent, type ObserveEventCallback, type ObserveOptions, type OpaqueObject, type PlainObject, type Primitive, type RecordValue, type RecursiveValueOrFunction, type RemoveObservables, type RetryOptions, type RootNodeInfo, type Selector, type SetParams, type TrackingNode, type TrackingState, type TrackingType, type TypeAtPath, type UpdateFn, type UpdateFnParams, type UpdateSetFn, type UpdateSetFnParams, type WaitForSet, type WaitForSetFnParams, applyChange, applyChanges, batch, beginBatch, computeSelector, computed, constructObjectWithPath, deconstructObjectWithPath, endBatch, event, getObservableIndex, hasOwnProperty, internal, isArray, isBoolean, isDate, isEmpty, isFunction, isMap, isNullOrUndefined, isNumber, isObject, isObservable, isObservableValueReady, isObserved, isPlainObject, isPrimitive, isPromise, isSet, isString, isSymbol, linked, mergeIntoObservable, observable, observablePrimitive, observe, opaqueObject, proxy, setAtPath, setSilently, shouldIgnoreUnobserved, syncState, trackSelector, when, whenReady };
|
package/index.js
CHANGED
|
@@ -1557,7 +1557,8 @@ var proxyHandler = {
|
|
|
1557
1557
|
}
|
|
1558
1558
|
if (isNullOrUndefined(value) && vProp === void 0 && (ArrayModifiers.has(p) || ArrayLoopers.has(p))) {
|
|
1559
1559
|
value = [];
|
|
1560
|
-
|
|
1560
|
+
if (ArrayModifiers.has(p))
|
|
1561
|
+
setNodeValue(node, value);
|
|
1561
1562
|
vProp = value[p];
|
|
1562
1563
|
}
|
|
1563
1564
|
if (isFunction(vProp)) {
|
package/index.mjs
CHANGED
|
@@ -1555,7 +1555,8 @@ var proxyHandler = {
|
|
|
1555
1555
|
}
|
|
1556
1556
|
if (isNullOrUndefined(value) && vProp === void 0 && (ArrayModifiers.has(p) || ArrayLoopers.has(p))) {
|
|
1557
1557
|
value = [];
|
|
1558
|
-
|
|
1558
|
+
if (ArrayModifiers.has(p))
|
|
1559
|
+
setNodeValue(node, value);
|
|
1559
1560
|
vProp = value[p];
|
|
1560
1561
|
}
|
|
1561
1562
|
if (isFunction(vProp)) {
|
package/package.json
CHANGED
package/react.d.mts
CHANGED
|
@@ -158,11 +158,19 @@ declare function useObservableReducer<R extends Reducer<any, any>>(reducer: R, i
|
|
|
158
158
|
interface UseObserveOptions extends ObserveOptions {
|
|
159
159
|
deps?: any[];
|
|
160
160
|
}
|
|
161
|
+
declare function useObserve<T>(run: (e: ObserveEvent<T>) => T | void): () => void;
|
|
162
|
+
declare function useObserve<T>(run: (e: ObserveEvent<T>) => T | void, deps?: any[]): () => void;
|
|
161
163
|
declare function useObserve<T>(run: (e: ObserveEvent<T>) => T | void, options?: UseObserveOptions): () => void;
|
|
164
|
+
declare function useObserve<T>(run: (e: ObserveEvent<T>) => T | void, options?: UseObserveOptions, deps?: any[]): () => void;
|
|
162
165
|
declare function useObserve<T>(selector: Selector<T>, reaction?: (e: ObserveEventCallback<T>) => any, options?: UseObserveOptions): () => void;
|
|
166
|
+
declare function useObserve<T>(selector: Selector<T>, reaction?: (e: ObserveEventCallback<T>) => any, options?: UseObserveOptions, deps?: any[]): () => void;
|
|
163
167
|
|
|
168
|
+
declare function useObserveEffect<T>(run: (e: ObserveEvent<T>) => T | void): void;
|
|
169
|
+
declare function useObserveEffect<T>(run: (e: ObserveEvent<T>) => T | void, deps?: any[]): void;
|
|
164
170
|
declare function useObserveEffect<T>(run: (e: ObserveEvent<T>) => T | void, options?: UseObserveOptions): void;
|
|
171
|
+
declare function useObserveEffect<T>(run: (e: ObserveEvent<T>) => T | void, options?: UseObserveOptions, deps?: any[]): void;
|
|
165
172
|
declare function useObserveEffect<T>(selector: Selector<T>, reaction?: (e: ObserveEventCallback<T>) => any, options?: UseObserveOptions): void;
|
|
173
|
+
declare function useObserveEffect<T>(selector: Selector<T>, reaction?: (e: ObserveEventCallback<T>) => any, options?: UseObserveOptions, deps?: any[]): void;
|
|
166
174
|
|
|
167
175
|
declare function useSelector<T>(selector: Selector<T>, options?: UseSelectorOptions): T;
|
|
168
176
|
|
package/react.d.ts
CHANGED
|
@@ -158,11 +158,19 @@ declare function useObservableReducer<R extends Reducer<any, any>>(reducer: R, i
|
|
|
158
158
|
interface UseObserveOptions extends ObserveOptions {
|
|
159
159
|
deps?: any[];
|
|
160
160
|
}
|
|
161
|
+
declare function useObserve<T>(run: (e: ObserveEvent<T>) => T | void): () => void;
|
|
162
|
+
declare function useObserve<T>(run: (e: ObserveEvent<T>) => T | void, deps?: any[]): () => void;
|
|
161
163
|
declare function useObserve<T>(run: (e: ObserveEvent<T>) => T | void, options?: UseObserveOptions): () => void;
|
|
164
|
+
declare function useObserve<T>(run: (e: ObserveEvent<T>) => T | void, options?: UseObserveOptions, deps?: any[]): () => void;
|
|
162
165
|
declare function useObserve<T>(selector: Selector<T>, reaction?: (e: ObserveEventCallback<T>) => any, options?: UseObserveOptions): () => void;
|
|
166
|
+
declare function useObserve<T>(selector: Selector<T>, reaction?: (e: ObserveEventCallback<T>) => any, options?: UseObserveOptions, deps?: any[]): () => void;
|
|
163
167
|
|
|
168
|
+
declare function useObserveEffect<T>(run: (e: ObserveEvent<T>) => T | void): void;
|
|
169
|
+
declare function useObserveEffect<T>(run: (e: ObserveEvent<T>) => T | void, deps?: any[]): void;
|
|
164
170
|
declare function useObserveEffect<T>(run: (e: ObserveEvent<T>) => T | void, options?: UseObserveOptions): void;
|
|
171
|
+
declare function useObserveEffect<T>(run: (e: ObserveEvent<T>) => T | void, options?: UseObserveOptions, deps?: any[]): void;
|
|
165
172
|
declare function useObserveEffect<T>(selector: Selector<T>, reaction?: (e: ObserveEventCallback<T>) => any, options?: UseObserveOptions): void;
|
|
173
|
+
declare function useObserveEffect<T>(selector: Selector<T>, reaction?: (e: ObserveEventCallback<T>) => any, options?: UseObserveOptions, deps?: any[]): void;
|
|
166
174
|
|
|
167
175
|
declare function useSelector<T>(selector: Selector<T>, options?: UseSelectorOptions): T;
|
|
168
176
|
|
package/react.js
CHANGED
|
@@ -182,7 +182,7 @@ function createReactiveComponent(component, observe3, reactive2, keysReactive, b
|
|
|
182
182
|
const p = props[key];
|
|
183
183
|
const isReactiveKey = keysReactiveSet && keysReactiveSet.has(key);
|
|
184
184
|
if (key === "children" && (state.isFunction(p) || state.isObservable(p))) {
|
|
185
|
-
|
|
185
|
+
propsOut[key] = useSelector(p, { skipCheck: true });
|
|
186
186
|
} else if (isReactiveKey || key.startsWith("$") || key.endsWith("$")) {
|
|
187
187
|
if (process.env.NODE_ENV === "development" && !didWarnProps && key.endsWith("$")) {
|
|
188
188
|
didWarnProps = true;
|
|
@@ -518,27 +518,36 @@ function useObservableReducer(reducer, initializerArg, initializer) {
|
|
|
518
518
|
};
|
|
519
519
|
return [obs, dispatch];
|
|
520
520
|
}
|
|
521
|
-
function useObserve(selector,
|
|
521
|
+
function useObserve(selector, reactionOrOptionsOrDeps, options, deps) {
|
|
522
522
|
let reaction;
|
|
523
|
-
if (state.isFunction(
|
|
524
|
-
reaction =
|
|
523
|
+
if (state.isFunction(reactionOrOptionsOrDeps)) {
|
|
524
|
+
reaction = reactionOrOptionsOrDeps;
|
|
525
|
+
} else if (Array.isArray(reactionOrOptionsOrDeps)) {
|
|
526
|
+
deps = reactionOrOptionsOrDeps;
|
|
527
|
+
options = void 0;
|
|
525
528
|
} else {
|
|
526
|
-
options =
|
|
529
|
+
options = reactionOrOptionsOrDeps;
|
|
527
530
|
}
|
|
528
|
-
|
|
531
|
+
if (reaction && Array.isArray(options)) {
|
|
532
|
+
deps = options;
|
|
533
|
+
options = void 0;
|
|
534
|
+
}
|
|
535
|
+
deps = deps || (options == null ? void 0 : options.deps);
|
|
529
536
|
const depsObs$ = deps ? useObservable(deps) : void 0;
|
|
530
537
|
const ref = React.useRef({});
|
|
531
|
-
ref.current.selector =
|
|
532
|
-
depsObs$ == null ? void 0 : depsObs$.get();
|
|
533
|
-
return state.computeSelector(selector);
|
|
534
|
-
} : selector;
|
|
538
|
+
ref.current.selector = selector;
|
|
535
539
|
ref.current.reaction = reaction;
|
|
536
540
|
if (depsObs$) {
|
|
537
541
|
depsObs$.set(deps);
|
|
538
542
|
}
|
|
539
543
|
if (!ref.current.dispose) {
|
|
540
544
|
ref.current.dispose = state.observe(
|
|
541
|
-
(e) =>
|
|
545
|
+
(e) => {
|
|
546
|
+
var _a;
|
|
547
|
+
depsObs$ == null ? void 0 : depsObs$.get();
|
|
548
|
+
const selector2 = (_a = ref.current) == null ? void 0 : _a.selector;
|
|
549
|
+
return state.computeSelector(selector2, void 0, e);
|
|
550
|
+
},
|
|
542
551
|
(e) => {
|
|
543
552
|
var _a, _b;
|
|
544
553
|
return (_b = (_a = ref.current).reaction) == null ? void 0 : _b.call(_a, e);
|
|
@@ -552,26 +561,35 @@ function useObserve(selector, reactionOrOptions, options) {
|
|
|
552
561
|
});
|
|
553
562
|
return ref.current.dispose;
|
|
554
563
|
}
|
|
555
|
-
function useObserveEffect(selector,
|
|
564
|
+
function useObserveEffect(selector, reactionOrOptionsOrDeps, options, deps) {
|
|
556
565
|
let reaction;
|
|
557
|
-
if (state.isFunction(
|
|
558
|
-
reaction =
|
|
566
|
+
if (state.isFunction(reactionOrOptionsOrDeps)) {
|
|
567
|
+
reaction = reactionOrOptionsOrDeps;
|
|
568
|
+
} else if (Array.isArray(reactionOrOptionsOrDeps)) {
|
|
569
|
+
deps = reactionOrOptionsOrDeps;
|
|
570
|
+
options = void 0;
|
|
559
571
|
} else {
|
|
560
|
-
options =
|
|
572
|
+
options = reactionOrOptionsOrDeps;
|
|
561
573
|
}
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
574
|
+
if (reaction && Array.isArray(options)) {
|
|
575
|
+
deps = options;
|
|
576
|
+
options = void 0;
|
|
577
|
+
}
|
|
578
|
+
deps = deps || (options == null ? void 0 : options.deps);
|
|
579
|
+
const ref = React.useRef({});
|
|
565
580
|
const depsObs$ = deps ? useObservable(deps) : void 0;
|
|
581
|
+
ref.current.selector = selector;
|
|
582
|
+
ref.current.reaction = reaction;
|
|
566
583
|
if (depsObs$) {
|
|
567
584
|
depsObs$.set(deps);
|
|
568
585
|
}
|
|
569
586
|
useMountOnce(
|
|
570
587
|
() => state.observe(
|
|
571
588
|
(e) => {
|
|
572
|
-
|
|
589
|
+
var _a;
|
|
573
590
|
depsObs$ == null ? void 0 : depsObs$.get();
|
|
574
|
-
|
|
591
|
+
const selector2 = (_a = ref.current) == null ? void 0 : _a.selector;
|
|
592
|
+
return state.computeSelector(selector2, void 0, e);
|
|
575
593
|
},
|
|
576
594
|
(e) => {
|
|
577
595
|
var _a, _b;
|
package/react.mjs
CHANGED
|
@@ -176,7 +176,7 @@ function createReactiveComponent(component, observe3, reactive2, keysReactive, b
|
|
|
176
176
|
const p = props[key];
|
|
177
177
|
const isReactiveKey = keysReactiveSet && keysReactiveSet.has(key);
|
|
178
178
|
if (key === "children" && (isFunction(p) || isObservable(p))) {
|
|
179
|
-
|
|
179
|
+
propsOut[key] = useSelector(p, { skipCheck: true });
|
|
180
180
|
} else if (isReactiveKey || key.startsWith("$") || key.endsWith("$")) {
|
|
181
181
|
if (process.env.NODE_ENV === "development" && !didWarnProps && key.endsWith("$")) {
|
|
182
182
|
didWarnProps = true;
|
|
@@ -512,27 +512,36 @@ function useObservableReducer(reducer, initializerArg, initializer) {
|
|
|
512
512
|
};
|
|
513
513
|
return [obs, dispatch];
|
|
514
514
|
}
|
|
515
|
-
function useObserve(selector,
|
|
515
|
+
function useObserve(selector, reactionOrOptionsOrDeps, options, deps) {
|
|
516
516
|
let reaction;
|
|
517
|
-
if (isFunction(
|
|
518
|
-
reaction =
|
|
517
|
+
if (isFunction(reactionOrOptionsOrDeps)) {
|
|
518
|
+
reaction = reactionOrOptionsOrDeps;
|
|
519
|
+
} else if (Array.isArray(reactionOrOptionsOrDeps)) {
|
|
520
|
+
deps = reactionOrOptionsOrDeps;
|
|
521
|
+
options = void 0;
|
|
519
522
|
} else {
|
|
520
|
-
options =
|
|
523
|
+
options = reactionOrOptionsOrDeps;
|
|
521
524
|
}
|
|
522
|
-
|
|
525
|
+
if (reaction && Array.isArray(options)) {
|
|
526
|
+
deps = options;
|
|
527
|
+
options = void 0;
|
|
528
|
+
}
|
|
529
|
+
deps = deps || (options == null ? void 0 : options.deps);
|
|
523
530
|
const depsObs$ = deps ? useObservable(deps) : void 0;
|
|
524
531
|
const ref = useRef({});
|
|
525
|
-
ref.current.selector =
|
|
526
|
-
depsObs$ == null ? void 0 : depsObs$.get();
|
|
527
|
-
return computeSelector(selector);
|
|
528
|
-
} : selector;
|
|
532
|
+
ref.current.selector = selector;
|
|
529
533
|
ref.current.reaction = reaction;
|
|
530
534
|
if (depsObs$) {
|
|
531
535
|
depsObs$.set(deps);
|
|
532
536
|
}
|
|
533
537
|
if (!ref.current.dispose) {
|
|
534
538
|
ref.current.dispose = observe(
|
|
535
|
-
(e) =>
|
|
539
|
+
(e) => {
|
|
540
|
+
var _a;
|
|
541
|
+
depsObs$ == null ? void 0 : depsObs$.get();
|
|
542
|
+
const selector2 = (_a = ref.current) == null ? void 0 : _a.selector;
|
|
543
|
+
return computeSelector(selector2, void 0, e);
|
|
544
|
+
},
|
|
536
545
|
(e) => {
|
|
537
546
|
var _a, _b;
|
|
538
547
|
return (_b = (_a = ref.current).reaction) == null ? void 0 : _b.call(_a, e);
|
|
@@ -546,26 +555,35 @@ function useObserve(selector, reactionOrOptions, options) {
|
|
|
546
555
|
});
|
|
547
556
|
return ref.current.dispose;
|
|
548
557
|
}
|
|
549
|
-
function useObserveEffect(selector,
|
|
558
|
+
function useObserveEffect(selector, reactionOrOptionsOrDeps, options, deps) {
|
|
550
559
|
let reaction;
|
|
551
|
-
if (isFunction(
|
|
552
|
-
reaction =
|
|
560
|
+
if (isFunction(reactionOrOptionsOrDeps)) {
|
|
561
|
+
reaction = reactionOrOptionsOrDeps;
|
|
562
|
+
} else if (Array.isArray(reactionOrOptionsOrDeps)) {
|
|
563
|
+
deps = reactionOrOptionsOrDeps;
|
|
564
|
+
options = void 0;
|
|
553
565
|
} else {
|
|
554
|
-
options =
|
|
566
|
+
options = reactionOrOptionsOrDeps;
|
|
555
567
|
}
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
568
|
+
if (reaction && Array.isArray(options)) {
|
|
569
|
+
deps = options;
|
|
570
|
+
options = void 0;
|
|
571
|
+
}
|
|
572
|
+
deps = deps || (options == null ? void 0 : options.deps);
|
|
573
|
+
const ref = useRef({});
|
|
559
574
|
const depsObs$ = deps ? useObservable(deps) : void 0;
|
|
575
|
+
ref.current.selector = selector;
|
|
576
|
+
ref.current.reaction = reaction;
|
|
560
577
|
if (depsObs$) {
|
|
561
578
|
depsObs$.set(deps);
|
|
562
579
|
}
|
|
563
580
|
useMountOnce(
|
|
564
581
|
() => observe(
|
|
565
582
|
(e) => {
|
|
566
|
-
|
|
583
|
+
var _a;
|
|
567
584
|
depsObs$ == null ? void 0 : depsObs$.get();
|
|
568
|
-
|
|
585
|
+
const selector2 = (_a = ref.current) == null ? void 0 : _a.selector;
|
|
586
|
+
return computeSelector(selector2, void 0, e);
|
|
569
587
|
},
|
|
570
588
|
(e) => {
|
|
571
589
|
var _a, _b;
|
package/sync.d.mts
CHANGED
|
@@ -211,6 +211,7 @@ declare const mapSyncPlugins: WeakMap<ClassConstructor<ObservablePersistPlugin>
|
|
|
211
211
|
declare function onChangeRemote(cb: () => void): void;
|
|
212
212
|
declare function syncObservable<T>(obs$: ObservableParam<T>, syncOptions: SyncedOptions<T>): Observable<ObservableSyncState>;
|
|
213
213
|
declare function syncObservable<T>(obs$: ObservableParam<T>, syncOptions: Synced<T>): Observable<ObservableSyncState>;
|
|
214
|
+
declare function getAllSyncStates(): readonly [Observable<ObservableSyncState>, NodeInfo][];
|
|
214
215
|
|
|
215
216
|
declare function synced<TRemote, TLocal = TRemote>(params: SyncedOptions<TRemote, TLocal> | (() => TRemote)): Synced<TLocal>;
|
|
216
217
|
|
|
@@ -230,4 +231,4 @@ declare const internal: {
|
|
|
230
231
|
runWithRetry: typeof runWithRetry;
|
|
231
232
|
};
|
|
232
233
|
|
|
233
|
-
export { type FieldTransforms, type FieldTransformsInner, type ObservablePersistAsyncStoragePluginOptions, type ObservablePersistIndexedDBPluginOptions, type ObservablePersistPlugin, type ObservablePersistPluginOptions, type ObservableSyncFunctions, type ObservableSyncSetParams, type OnErrorRetryParams, type PendingChanges, type PersistMetadata, type PersistOptions, type QueryByModified, type StringToDate, type SubscribeOptions, type SyncTransform, type SyncTransformMethod, type Synced, type SyncedErrorParams, type SyncedGetParams, type SyncedGetSetBaseParams, type SyncedGetSetSubscribeBaseParams, type SyncedOptions, type SyncedOptionsGlobal, type SyncedSetParams, type SyncedSubscribeParams, type TransformStringifyKeys, type TransformStringifyOptions, type TransformStringsToDates, combineTransforms, configureObservableSync, configureSynced, createRevertChanges, deepEqual, diffObjects, internal, mapSyncPlugins, onChangeRemote, removeNullUndefined, syncObservable, synced, transformStringifyDates, transformStringifyKeys };
|
|
234
|
+
export { type FieldTransforms, type FieldTransformsInner, type ObservablePersistAsyncStoragePluginOptions, type ObservablePersistIndexedDBPluginOptions, type ObservablePersistPlugin, type ObservablePersistPluginOptions, type ObservableSyncFunctions, type ObservableSyncSetParams, type OnErrorRetryParams, type PendingChanges, type PersistMetadata, type PersistOptions, type QueryByModified, type StringToDate, type SubscribeOptions, type SyncTransform, type SyncTransformMethod, type Synced, type SyncedErrorParams, type SyncedGetParams, type SyncedGetSetBaseParams, type SyncedGetSetSubscribeBaseParams, type SyncedOptions, type SyncedOptionsGlobal, type SyncedSetParams, type SyncedSubscribeParams, type TransformStringifyKeys, type TransformStringifyOptions, type TransformStringsToDates, combineTransforms, configureObservableSync, configureSynced, createRevertChanges, deepEqual, diffObjects, getAllSyncStates, internal, mapSyncPlugins, onChangeRemote, removeNullUndefined, syncObservable, synced, transformStringifyDates, transformStringifyKeys };
|
package/sync.d.ts
CHANGED
|
@@ -211,6 +211,7 @@ declare const mapSyncPlugins: WeakMap<ClassConstructor<ObservablePersistPlugin>
|
|
|
211
211
|
declare function onChangeRemote(cb: () => void): void;
|
|
212
212
|
declare function syncObservable<T>(obs$: ObservableParam<T>, syncOptions: SyncedOptions<T>): Observable<ObservableSyncState>;
|
|
213
213
|
declare function syncObservable<T>(obs$: ObservableParam<T>, syncOptions: Synced<T>): Observable<ObservableSyncState>;
|
|
214
|
+
declare function getAllSyncStates(): readonly [Observable<ObservableSyncState>, NodeInfo][];
|
|
214
215
|
|
|
215
216
|
declare function synced<TRemote, TLocal = TRemote>(params: SyncedOptions<TRemote, TLocal> | (() => TRemote)): Synced<TLocal>;
|
|
216
217
|
|
|
@@ -230,4 +231,4 @@ declare const internal: {
|
|
|
230
231
|
runWithRetry: typeof runWithRetry;
|
|
231
232
|
};
|
|
232
233
|
|
|
233
|
-
export { type FieldTransforms, type FieldTransformsInner, type ObservablePersistAsyncStoragePluginOptions, type ObservablePersistIndexedDBPluginOptions, type ObservablePersistPlugin, type ObservablePersistPluginOptions, type ObservableSyncFunctions, type ObservableSyncSetParams, type OnErrorRetryParams, type PendingChanges, type PersistMetadata, type PersistOptions, type QueryByModified, type StringToDate, type SubscribeOptions, type SyncTransform, type SyncTransformMethod, type Synced, type SyncedErrorParams, type SyncedGetParams, type SyncedGetSetBaseParams, type SyncedGetSetSubscribeBaseParams, type SyncedOptions, type SyncedOptionsGlobal, type SyncedSetParams, type SyncedSubscribeParams, type TransformStringifyKeys, type TransformStringifyOptions, type TransformStringsToDates, combineTransforms, configureObservableSync, configureSynced, createRevertChanges, deepEqual, diffObjects, internal, mapSyncPlugins, onChangeRemote, removeNullUndefined, syncObservable, synced, transformStringifyDates, transformStringifyKeys };
|
|
234
|
+
export { type FieldTransforms, type FieldTransformsInner, type ObservablePersistAsyncStoragePluginOptions, type ObservablePersistIndexedDBPluginOptions, type ObservablePersistPlugin, type ObservablePersistPluginOptions, type ObservableSyncFunctions, type ObservableSyncSetParams, type OnErrorRetryParams, type PendingChanges, type PersistMetadata, type PersistOptions, type QueryByModified, type StringToDate, type SubscribeOptions, type SyncTransform, type SyncTransformMethod, type Synced, type SyncedErrorParams, type SyncedGetParams, type SyncedGetSetBaseParams, type SyncedGetSetSubscribeBaseParams, type SyncedOptions, type SyncedOptionsGlobal, type SyncedSetParams, type SyncedSubscribeParams, type TransformStringifyKeys, type TransformStringifyOptions, type TransformStringsToDates, combineTransforms, configureObservableSync, configureSynced, createRevertChanges, deepEqual, diffObjects, getAllSyncStates, internal, mapSyncPlugins, onChangeRemote, removeNullUndefined, syncObservable, synced, transformStringifyDates, transformStringifyKeys };
|
package/sync.js
CHANGED
|
@@ -243,7 +243,8 @@ var {
|
|
|
243
243
|
getValueAtPath,
|
|
244
244
|
globalState,
|
|
245
245
|
registerMiddleware,
|
|
246
|
-
symbolLinked
|
|
246
|
+
symbolLinked,
|
|
247
|
+
setNodeValue
|
|
247
248
|
} = state.internal;
|
|
248
249
|
var mapSyncPlugins = /* @__PURE__ */ new WeakMap();
|
|
249
250
|
var allSyncStates = /* @__PURE__ */ new Map();
|
|
@@ -283,7 +284,7 @@ function transformLoadData(value, { transform }, doUserTransform, method) {
|
|
|
283
284
|
}
|
|
284
285
|
return value;
|
|
285
286
|
}
|
|
286
|
-
async function updateMetadataImmediate(value$, localState,
|
|
287
|
+
async function updateMetadataImmediate(value$, localState, syncState$, syncOptions, newMetadata) {
|
|
287
288
|
const saves = Array.from(promisesLocalSaves);
|
|
288
289
|
if (saves.length > 0) {
|
|
289
290
|
await Promise.all(saves);
|
|
@@ -298,7 +299,7 @@ async function updateMetadataImmediate(value$, localState, syncState2, syncOptio
|
|
|
298
299
|
await pluginPersist.setMetadata(table, metadata, config);
|
|
299
300
|
}
|
|
300
301
|
if (lastSync) {
|
|
301
|
-
|
|
302
|
+
syncState$.assign({
|
|
302
303
|
lastSync
|
|
303
304
|
});
|
|
304
305
|
}
|
|
@@ -935,8 +936,7 @@ function syncObservable(obs$, syncOptionsOrSynced) {
|
|
|
935
936
|
};
|
|
936
937
|
const { get, subscribe } = syncOptions;
|
|
937
938
|
if (get || subscribe) {
|
|
938
|
-
sync = async () => {
|
|
939
|
-
var _a;
|
|
939
|
+
sync = async (options) => {
|
|
940
940
|
if (isSynced && (!getNodeValue(getNode(syncState$)).isSyncEnabled || state.shouldIgnoreUnobserved(node, sync))) {
|
|
941
941
|
if (unsubscribe) {
|
|
942
942
|
isSubscribed = false;
|
|
@@ -945,12 +945,18 @@ function syncObservable(obs$, syncOptionsOrSynced) {
|
|
|
945
945
|
}
|
|
946
946
|
return;
|
|
947
947
|
}
|
|
948
|
-
const
|
|
948
|
+
const metadata = metadatas.get(obs$);
|
|
949
|
+
if (metadata && (options == null ? void 0 : options.resetLastSync)) {
|
|
950
|
+
metadata.lastSync = void 0;
|
|
951
|
+
syncState$.lastSync.set(void 0);
|
|
952
|
+
}
|
|
953
|
+
const lastSync = metadata == null ? void 0 : metadata.lastSync;
|
|
949
954
|
const pending = localState.pendingChanges;
|
|
950
955
|
const { waitFor } = syncOptions;
|
|
951
956
|
const runGet = () => {
|
|
952
|
-
var
|
|
957
|
+
var _a;
|
|
953
958
|
const onChange = async ({ value, mode, lastSync: lastSync2 }) => {
|
|
959
|
+
var _a2;
|
|
954
960
|
mode = mode || syncOptions.mode || "set";
|
|
955
961
|
if (value !== void 0) {
|
|
956
962
|
value = transformLoadData(value, syncOptions, true, "get");
|
|
@@ -1007,6 +1013,9 @@ function syncObservable(obs$, syncOptionsOrSynced) {
|
|
|
1007
1013
|
});
|
|
1008
1014
|
}
|
|
1009
1015
|
}
|
|
1016
|
+
if (options == null ? void 0 : options.resetLastSync) {
|
|
1017
|
+
setNodeValue(node, (_a2 = syncOptions.initial) != null ? _a2 : void 0);
|
|
1018
|
+
}
|
|
1010
1019
|
onChangeRemote2(() => {
|
|
1011
1020
|
if (state.isPlainObject(value)) {
|
|
1012
1021
|
value = state.ObservableHint.plain(value);
|
|
@@ -1065,7 +1074,7 @@ function syncObservable(obs$, syncOptionsOrSynced) {
|
|
|
1065
1074
|
}
|
|
1066
1075
|
);
|
|
1067
1076
|
},
|
|
1068
|
-
refresh: () => state.when(syncState$.isLoaded, sync),
|
|
1077
|
+
refresh: () => state.when(syncState$.isLoaded, () => sync()),
|
|
1069
1078
|
onError: (error) => onGetError(error, {
|
|
1070
1079
|
source: "subscribe",
|
|
1071
1080
|
subscribeParams,
|
|
@@ -1120,14 +1129,14 @@ function syncObservable(obs$, syncOptionsOrSynced) {
|
|
|
1120
1129
|
});
|
|
1121
1130
|
},
|
|
1122
1131
|
resetCache: () => {
|
|
1123
|
-
var
|
|
1132
|
+
var _a2;
|
|
1124
1133
|
modeBeforeReset = getParams.mode;
|
|
1125
1134
|
getParams.mode = "set";
|
|
1126
|
-
return (
|
|
1135
|
+
return (_a2 = syncStateValue.resetPersistence) == null ? void 0 : _a2.call(syncStateValue);
|
|
1127
1136
|
},
|
|
1128
1137
|
cancel: false
|
|
1129
1138
|
};
|
|
1130
|
-
(
|
|
1139
|
+
(_a = syncOptions.onBeforeGet) == null ? void 0 : _a.call(syncOptions, beforeGetParams);
|
|
1131
1140
|
if (!beforeGetParams.cancel) {
|
|
1132
1141
|
syncState$.assign({
|
|
1133
1142
|
numPendingGets: (syncStateValue.numPendingGets || 0) + 1,
|
|
@@ -1175,9 +1184,9 @@ function syncObservable(obs$, syncOptionsOrSynced) {
|
|
|
1175
1184
|
}
|
|
1176
1185
|
};
|
|
1177
1186
|
if (waitFor) {
|
|
1178
|
-
state.whenReady(waitFor, () => state.trackSelector(runGet, sync));
|
|
1187
|
+
state.whenReady(waitFor, () => state.trackSelector(runGet, () => sync()));
|
|
1179
1188
|
} else {
|
|
1180
|
-
state.trackSelector(runGet, sync);
|
|
1189
|
+
state.trackSelector(runGet, () => sync());
|
|
1181
1190
|
}
|
|
1182
1191
|
if (!isSynced) {
|
|
1183
1192
|
isSynced = true;
|
|
@@ -1201,7 +1210,7 @@ function syncObservable(obs$, syncOptionsOrSynced) {
|
|
|
1201
1210
|
if (metadata) {
|
|
1202
1211
|
Object.assign(metadata, { lastSync: void 0, pending: void 0 });
|
|
1203
1212
|
}
|
|
1204
|
-
|
|
1213
|
+
const newState = {
|
|
1205
1214
|
isPersistEnabled: false,
|
|
1206
1215
|
isSyncEnabled: false,
|
|
1207
1216
|
lastSync: void 0,
|
|
@@ -1211,7 +1220,8 @@ function syncObservable(obs$, syncOptionsOrSynced) {
|
|
|
1211
1220
|
isSetting: false,
|
|
1212
1221
|
numPendingSets: 0,
|
|
1213
1222
|
syncCount: 0
|
|
1214
|
-
}
|
|
1223
|
+
};
|
|
1224
|
+
Object.assign(syncStateValue, newState);
|
|
1215
1225
|
isSynced = false;
|
|
1216
1226
|
isSubscribed = false;
|
|
1217
1227
|
unsubscribe == null ? void 0 : unsubscribe();
|
|
@@ -1227,6 +1237,14 @@ function syncObservable(obs$, syncOptionsOrSynced) {
|
|
|
1227
1237
|
node.dirtyFn = sync;
|
|
1228
1238
|
await promise;
|
|
1229
1239
|
};
|
|
1240
|
+
syncState$.lastSync.onChange(({ value }) => {
|
|
1241
|
+
const metadata = metadatas.get(obs$);
|
|
1242
|
+
if (metadata && metadata.lastSync !== value) {
|
|
1243
|
+
updateMetadataImmediate(obs$, localState, syncState$, syncOptions, {
|
|
1244
|
+
lastSync: value
|
|
1245
|
+
});
|
|
1246
|
+
}
|
|
1247
|
+
});
|
|
1230
1248
|
const onAllPersistLoaded = () => {
|
|
1231
1249
|
var _a, _b;
|
|
1232
1250
|
let parentNode = node;
|
|
@@ -1250,7 +1268,10 @@ function syncObservable(obs$, syncOptionsOrSynced) {
|
|
|
1250
1268
|
});
|
|
1251
1269
|
return syncState$;
|
|
1252
1270
|
}
|
|
1253
|
-
|
|
1271
|
+
function getAllSyncStates() {
|
|
1272
|
+
return Array.from(allSyncStates.entries());
|
|
1273
|
+
}
|
|
1274
|
+
var { getProxy, globalState: globalState2, setNodeValue: setNodeValue2, getNodeValue: getNodeValue2 } = state.internal;
|
|
1254
1275
|
function enableActivateSyncedNode() {
|
|
1255
1276
|
globalState2.activateSyncedNode = function activateSyncedNode(node, newValue) {
|
|
1256
1277
|
const obs$ = getProxy(node);
|
|
@@ -1273,7 +1294,7 @@ function enableActivateSyncedNode() {
|
|
|
1273
1294
|
} else {
|
|
1274
1295
|
newValue = initial;
|
|
1275
1296
|
}
|
|
1276
|
-
|
|
1297
|
+
setNodeValue2(node, promiseReturn ? void 0 : newValue);
|
|
1277
1298
|
syncObservable(obs$, { ...node.activationState, get, set });
|
|
1278
1299
|
return { update: onChange, value: newValue };
|
|
1279
1300
|
} else {
|
|
@@ -1334,6 +1355,7 @@ exports.configureSynced = configureSynced;
|
|
|
1334
1355
|
exports.createRevertChanges = createRevertChanges;
|
|
1335
1356
|
exports.deepEqual = deepEqual;
|
|
1336
1357
|
exports.diffObjects = diffObjects;
|
|
1358
|
+
exports.getAllSyncStates = getAllSyncStates;
|
|
1337
1359
|
exports.internal = internal5;
|
|
1338
1360
|
exports.mapSyncPlugins = mapSyncPlugins;
|
|
1339
1361
|
exports.onChangeRemote = onChangeRemote2;
|
package/sync.mjs
CHANGED
|
@@ -241,7 +241,8 @@ var {
|
|
|
241
241
|
getValueAtPath,
|
|
242
242
|
globalState,
|
|
243
243
|
registerMiddleware,
|
|
244
|
-
symbolLinked
|
|
244
|
+
symbolLinked,
|
|
245
|
+
setNodeValue
|
|
245
246
|
} = internal;
|
|
246
247
|
var mapSyncPlugins = /* @__PURE__ */ new WeakMap();
|
|
247
248
|
var allSyncStates = /* @__PURE__ */ new Map();
|
|
@@ -281,7 +282,7 @@ function transformLoadData(value, { transform }, doUserTransform, method) {
|
|
|
281
282
|
}
|
|
282
283
|
return value;
|
|
283
284
|
}
|
|
284
|
-
async function updateMetadataImmediate(value$, localState,
|
|
285
|
+
async function updateMetadataImmediate(value$, localState, syncState$, syncOptions, newMetadata) {
|
|
285
286
|
const saves = Array.from(promisesLocalSaves);
|
|
286
287
|
if (saves.length > 0) {
|
|
287
288
|
await Promise.all(saves);
|
|
@@ -296,7 +297,7 @@ async function updateMetadataImmediate(value$, localState, syncState2, syncOptio
|
|
|
296
297
|
await pluginPersist.setMetadata(table, metadata, config);
|
|
297
298
|
}
|
|
298
299
|
if (lastSync) {
|
|
299
|
-
|
|
300
|
+
syncState$.assign({
|
|
300
301
|
lastSync
|
|
301
302
|
});
|
|
302
303
|
}
|
|
@@ -933,8 +934,7 @@ function syncObservable(obs$, syncOptionsOrSynced) {
|
|
|
933
934
|
};
|
|
934
935
|
const { get, subscribe } = syncOptions;
|
|
935
936
|
if (get || subscribe) {
|
|
936
|
-
sync = async () => {
|
|
937
|
-
var _a;
|
|
937
|
+
sync = async (options) => {
|
|
938
938
|
if (isSynced && (!getNodeValue(getNode(syncState$)).isSyncEnabled || shouldIgnoreUnobserved(node, sync))) {
|
|
939
939
|
if (unsubscribe) {
|
|
940
940
|
isSubscribed = false;
|
|
@@ -943,12 +943,18 @@ function syncObservable(obs$, syncOptionsOrSynced) {
|
|
|
943
943
|
}
|
|
944
944
|
return;
|
|
945
945
|
}
|
|
946
|
-
const
|
|
946
|
+
const metadata = metadatas.get(obs$);
|
|
947
|
+
if (metadata && (options == null ? void 0 : options.resetLastSync)) {
|
|
948
|
+
metadata.lastSync = void 0;
|
|
949
|
+
syncState$.lastSync.set(void 0);
|
|
950
|
+
}
|
|
951
|
+
const lastSync = metadata == null ? void 0 : metadata.lastSync;
|
|
947
952
|
const pending = localState.pendingChanges;
|
|
948
953
|
const { waitFor } = syncOptions;
|
|
949
954
|
const runGet = () => {
|
|
950
|
-
var
|
|
955
|
+
var _a;
|
|
951
956
|
const onChange = async ({ value, mode, lastSync: lastSync2 }) => {
|
|
957
|
+
var _a2;
|
|
952
958
|
mode = mode || syncOptions.mode || "set";
|
|
953
959
|
if (value !== void 0) {
|
|
954
960
|
value = transformLoadData(value, syncOptions, true, "get");
|
|
@@ -1005,6 +1011,9 @@ function syncObservable(obs$, syncOptionsOrSynced) {
|
|
|
1005
1011
|
});
|
|
1006
1012
|
}
|
|
1007
1013
|
}
|
|
1014
|
+
if (options == null ? void 0 : options.resetLastSync) {
|
|
1015
|
+
setNodeValue(node, (_a2 = syncOptions.initial) != null ? _a2 : void 0);
|
|
1016
|
+
}
|
|
1008
1017
|
onChangeRemote2(() => {
|
|
1009
1018
|
if (isPlainObject(value)) {
|
|
1010
1019
|
value = ObservableHint.plain(value);
|
|
@@ -1063,7 +1072,7 @@ function syncObservable(obs$, syncOptionsOrSynced) {
|
|
|
1063
1072
|
}
|
|
1064
1073
|
);
|
|
1065
1074
|
},
|
|
1066
|
-
refresh: () => when(syncState$.isLoaded, sync),
|
|
1075
|
+
refresh: () => when(syncState$.isLoaded, () => sync()),
|
|
1067
1076
|
onError: (error) => onGetError(error, {
|
|
1068
1077
|
source: "subscribe",
|
|
1069
1078
|
subscribeParams,
|
|
@@ -1118,14 +1127,14 @@ function syncObservable(obs$, syncOptionsOrSynced) {
|
|
|
1118
1127
|
});
|
|
1119
1128
|
},
|
|
1120
1129
|
resetCache: () => {
|
|
1121
|
-
var
|
|
1130
|
+
var _a2;
|
|
1122
1131
|
modeBeforeReset = getParams.mode;
|
|
1123
1132
|
getParams.mode = "set";
|
|
1124
|
-
return (
|
|
1133
|
+
return (_a2 = syncStateValue.resetPersistence) == null ? void 0 : _a2.call(syncStateValue);
|
|
1125
1134
|
},
|
|
1126
1135
|
cancel: false
|
|
1127
1136
|
};
|
|
1128
|
-
(
|
|
1137
|
+
(_a = syncOptions.onBeforeGet) == null ? void 0 : _a.call(syncOptions, beforeGetParams);
|
|
1129
1138
|
if (!beforeGetParams.cancel) {
|
|
1130
1139
|
syncState$.assign({
|
|
1131
1140
|
numPendingGets: (syncStateValue.numPendingGets || 0) + 1,
|
|
@@ -1173,9 +1182,9 @@ function syncObservable(obs$, syncOptionsOrSynced) {
|
|
|
1173
1182
|
}
|
|
1174
1183
|
};
|
|
1175
1184
|
if (waitFor) {
|
|
1176
|
-
whenReady(waitFor, () => trackSelector(runGet, sync));
|
|
1185
|
+
whenReady(waitFor, () => trackSelector(runGet, () => sync()));
|
|
1177
1186
|
} else {
|
|
1178
|
-
trackSelector(runGet, sync);
|
|
1187
|
+
trackSelector(runGet, () => sync());
|
|
1179
1188
|
}
|
|
1180
1189
|
if (!isSynced) {
|
|
1181
1190
|
isSynced = true;
|
|
@@ -1199,7 +1208,7 @@ function syncObservable(obs$, syncOptionsOrSynced) {
|
|
|
1199
1208
|
if (metadata) {
|
|
1200
1209
|
Object.assign(metadata, { lastSync: void 0, pending: void 0 });
|
|
1201
1210
|
}
|
|
1202
|
-
|
|
1211
|
+
const newState = {
|
|
1203
1212
|
isPersistEnabled: false,
|
|
1204
1213
|
isSyncEnabled: false,
|
|
1205
1214
|
lastSync: void 0,
|
|
@@ -1209,7 +1218,8 @@ function syncObservable(obs$, syncOptionsOrSynced) {
|
|
|
1209
1218
|
isSetting: false,
|
|
1210
1219
|
numPendingSets: 0,
|
|
1211
1220
|
syncCount: 0
|
|
1212
|
-
}
|
|
1221
|
+
};
|
|
1222
|
+
Object.assign(syncStateValue, newState);
|
|
1213
1223
|
isSynced = false;
|
|
1214
1224
|
isSubscribed = false;
|
|
1215
1225
|
unsubscribe == null ? void 0 : unsubscribe();
|
|
@@ -1225,6 +1235,14 @@ function syncObservable(obs$, syncOptionsOrSynced) {
|
|
|
1225
1235
|
node.dirtyFn = sync;
|
|
1226
1236
|
await promise;
|
|
1227
1237
|
};
|
|
1238
|
+
syncState$.lastSync.onChange(({ value }) => {
|
|
1239
|
+
const metadata = metadatas.get(obs$);
|
|
1240
|
+
if (metadata && metadata.lastSync !== value) {
|
|
1241
|
+
updateMetadataImmediate(obs$, localState, syncState$, syncOptions, {
|
|
1242
|
+
lastSync: value
|
|
1243
|
+
});
|
|
1244
|
+
}
|
|
1245
|
+
});
|
|
1228
1246
|
const onAllPersistLoaded = () => {
|
|
1229
1247
|
var _a, _b;
|
|
1230
1248
|
let parentNode = node;
|
|
@@ -1248,7 +1266,10 @@ function syncObservable(obs$, syncOptionsOrSynced) {
|
|
|
1248
1266
|
});
|
|
1249
1267
|
return syncState$;
|
|
1250
1268
|
}
|
|
1251
|
-
|
|
1269
|
+
function getAllSyncStates() {
|
|
1270
|
+
return Array.from(allSyncStates.entries());
|
|
1271
|
+
}
|
|
1272
|
+
var { getProxy, globalState: globalState2, setNodeValue: setNodeValue2, getNodeValue: getNodeValue2 } = internal;
|
|
1252
1273
|
function enableActivateSyncedNode() {
|
|
1253
1274
|
globalState2.activateSyncedNode = function activateSyncedNode(node, newValue) {
|
|
1254
1275
|
const obs$ = getProxy(node);
|
|
@@ -1271,7 +1292,7 @@ function enableActivateSyncedNode() {
|
|
|
1271
1292
|
} else {
|
|
1272
1293
|
newValue = initial;
|
|
1273
1294
|
}
|
|
1274
|
-
|
|
1295
|
+
setNodeValue2(node, promiseReturn ? void 0 : newValue);
|
|
1275
1296
|
syncObservable(obs$, { ...node.activationState, get, set });
|
|
1276
1297
|
return { update: onChange, value: newValue };
|
|
1277
1298
|
} else {
|
|
@@ -1326,4 +1347,4 @@ var internal5 = {
|
|
|
1326
1347
|
runWithRetry
|
|
1327
1348
|
};
|
|
1328
1349
|
|
|
1329
|
-
export { combineTransforms, configureObservableSync, configureSynced, createRevertChanges, deepEqual, diffObjects, internal5 as internal, mapSyncPlugins, onChangeRemote2 as onChangeRemote, removeNullUndefined, syncObservable, synced, transformStringifyDates, transformStringifyKeys };
|
|
1350
|
+
export { combineTransforms, configureObservableSync, configureSynced, createRevertChanges, deepEqual, diffObjects, getAllSyncStates, internal5 as internal, mapSyncPlugins, onChangeRemote2 as onChangeRemote, removeNullUndefined, syncObservable, synced, transformStringifyDates, transformStringifyKeys };
|