@legendapp/state 3.0.0-beta.31 → 3.0.0-beta.33

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/README.md CHANGED
@@ -72,7 +72,7 @@ Legend-State includes a powerful [sync and persistence system](../../usage/persi
72
72
  Local persistence plugins for the browser and React Native are included, with sync plugins for [Keel](https://www.keel.so), [Supabase](https://www.supabase.com), [TanStack Query](https://tanstack.com/query), and `fetch`.
73
73
 
74
74
  ```js
75
- const state$ = observable(
75
+ const state$ = observable({
76
76
  users: syncedKeel({
77
77
  list: queries.getUsers,
78
78
  create: mutations.createUsers,
@@ -87,7 +87,7 @@ const state$ = observable(
87
87
  }),
88
88
  // direct link to my user within the users observable
89
89
  me: () => state$.users['myuid']
90
- )
90
+ })
91
91
 
92
92
  observe(() => {
93
93
  // get() activates through to state$.users and starts syncing.
package/index.d.mts CHANGED
@@ -1,13 +1,13 @@
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];
5
5
  };
6
- type BuiltIns = String | Boolean | Number | Date | Error | RegExp | Array<any> | Function | Promise<any>;
6
+ type BuiltIns = String | Boolean | Number | Date | Error | RegExp | Array<any> | Function | Promise<any> | OpaqueObject<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> {
@@ -111,6 +111,7 @@ declare function setNodeValue(node: NodeInfo, newValue: any): {
111
111
  parentValue: any;
112
112
  };
113
113
  declare function getNodeValue(node: NodeInfo): any;
114
+ declare function getChildNode(node: NodeInfo, key: string, asFunction?: Function): NodeInfo;
114
115
  declare function ensureNodeValue(node: NodeInfo): any;
115
116
  declare function findIDKey(obj: unknown | undefined, node: NodeInfo): string | ((value: any) => string) | undefined;
116
117
  declare function getKeys(obj: Record<any, any> | Array<any> | undefined, isArr: boolean, isMap: boolean, isSet: boolean): string[];
@@ -261,6 +262,9 @@ type Linked<T> = T;
261
262
  interface ObserveOptions {
262
263
  immediate?: boolean;
263
264
  }
265
+ interface ObservableSyncStateOptions {
266
+ resetLastSync?: boolean;
267
+ }
264
268
  interface ObservableSyncStateBase {
265
269
  isPersistLoaded: boolean;
266
270
  isPersistEnabled: boolean;
@@ -271,7 +275,7 @@ interface ObservableSyncStateBase {
271
275
  isSetting?: boolean;
272
276
  numPendingGets?: number;
273
277
  numPendingSets?: number;
274
- sync: () => Promise<void>;
278
+ sync: (options?: ObservableSyncStateOptions) => Promise<void>;
275
279
  getPendingChanges: () => Record<string, {
276
280
  p: any;
277
281
  v?: any;
@@ -418,6 +422,7 @@ declare const internal: {
418
422
  ensureNodeValue: typeof ensureNodeValue;
419
423
  findIDKey: typeof findIDKey;
420
424
  get: typeof get;
425
+ getChildNode: typeof getChildNode;
421
426
  getKeys: typeof getKeys;
422
427
  getNode: typeof getNode;
423
428
  getNodeValue: typeof getNodeValue;
@@ -459,4 +464,4 @@ declare const internal: {
459
464
  };
460
465
  };
461
466
 
462
- 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,13 +1,13 @@
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];
5
5
  };
6
- type BuiltIns = String | Boolean | Number | Date | Error | RegExp | Array<any> | Function | Promise<any>;
6
+ type BuiltIns = String | Boolean | Number | Date | Error | RegExp | Array<any> | Function | Promise<any> | OpaqueObject<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> {
@@ -111,6 +111,7 @@ declare function setNodeValue(node: NodeInfo, newValue: any): {
111
111
  parentValue: any;
112
112
  };
113
113
  declare function getNodeValue(node: NodeInfo): any;
114
+ declare function getChildNode(node: NodeInfo, key: string, asFunction?: Function): NodeInfo;
114
115
  declare function ensureNodeValue(node: NodeInfo): any;
115
116
  declare function findIDKey(obj: unknown | undefined, node: NodeInfo): string | ((value: any) => string) | undefined;
116
117
  declare function getKeys(obj: Record<any, any> | Array<any> | undefined, isArr: boolean, isMap: boolean, isSet: boolean): string[];
@@ -261,6 +262,9 @@ type Linked<T> = T;
261
262
  interface ObserveOptions {
262
263
  immediate?: boolean;
263
264
  }
265
+ interface ObservableSyncStateOptions {
266
+ resetLastSync?: boolean;
267
+ }
264
268
  interface ObservableSyncStateBase {
265
269
  isPersistLoaded: boolean;
266
270
  isPersistEnabled: boolean;
@@ -271,7 +275,7 @@ interface ObservableSyncStateBase {
271
275
  isSetting?: boolean;
272
276
  numPendingGets?: number;
273
277
  numPendingSets?: number;
274
- sync: () => Promise<void>;
278
+ sync: (options?: ObservableSyncStateOptions) => Promise<void>;
275
279
  getPendingChanges: () => Record<string, {
276
280
  p: any;
277
281
  v?: any;
@@ -418,6 +422,7 @@ declare const internal: {
418
422
  ensureNodeValue: typeof ensureNodeValue;
419
423
  findIDKey: typeof findIDKey;
420
424
  get: typeof get;
425
+ getChildNode: typeof getChildNode;
421
426
  getKeys: typeof getKeys;
422
427
  getNode: typeof getNode;
423
428
  getNodeValue: typeof getNodeValue;
@@ -459,4 +464,4 @@ declare const internal: {
459
464
  };
460
465
  };
461
466
 
462
- 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
- setNodeValue(node, value);
1560
+ if (ArrayModifiers.has(p))
1561
+ setNodeValue(node, value);
1561
1562
  vProp = value[p];
1562
1563
  }
1563
1564
  if (isFunction(vProp)) {
@@ -2434,10 +2435,13 @@ function syncState(obs) {
2434
2435
  syncCount: 0,
2435
2436
  resetPersistence: void 0,
2436
2437
  reset: () => Promise.resolve(),
2437
- sync: () => {
2438
- var _a;
2438
+ sync: (options) => {
2439
+ var _a, _b;
2440
+ if (options == null ? void 0 : options.resetLastSync) {
2441
+ (_a = node.state) == null ? void 0 : _a.lastSync.set(void 0);
2442
+ }
2439
2443
  obs.peek();
2440
- if ((_a = node.state) == null ? void 0 : _a.isGetting.peek()) {
2444
+ if ((_b = node.state) == null ? void 0 : _b.isGetting.peek()) {
2441
2445
  return when(node.state.isLoaded);
2442
2446
  }
2443
2447
  return Promise.resolve();
@@ -2460,6 +2464,7 @@ var internal = {
2460
2464
  ensureNodeValue,
2461
2465
  findIDKey,
2462
2466
  get,
2467
+ getChildNode,
2463
2468
  getKeys,
2464
2469
  getNode,
2465
2470
  getNodeValue,
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
- setNodeValue(node, value);
1558
+ if (ArrayModifiers.has(p))
1559
+ setNodeValue(node, value);
1559
1560
  vProp = value[p];
1560
1561
  }
1561
1562
  if (isFunction(vProp)) {
@@ -2432,10 +2433,13 @@ function syncState(obs) {
2432
2433
  syncCount: 0,
2433
2434
  resetPersistence: void 0,
2434
2435
  reset: () => Promise.resolve(),
2435
- sync: () => {
2436
- var _a;
2436
+ sync: (options) => {
2437
+ var _a, _b;
2438
+ if (options == null ? void 0 : options.resetLastSync) {
2439
+ (_a = node.state) == null ? void 0 : _a.lastSync.set(void 0);
2440
+ }
2437
2441
  obs.peek();
2438
- if ((_a = node.state) == null ? void 0 : _a.isGetting.peek()) {
2442
+ if ((_b = node.state) == null ? void 0 : _b.isGetting.peek()) {
2439
2443
  return when(node.state.isLoaded);
2440
2444
  }
2441
2445
  return Promise.resolve();
@@ -2458,6 +2462,7 @@ var internal = {
2458
2462
  ensureNodeValue,
2459
2463
  findIDKey,
2460
2464
  get,
2465
+ getChildNode,
2461
2466
  getKeys,
2462
2467
  getNode,
2463
2468
  getNodeValue,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legendapp/state",
3
- "version": "3.0.0-beta.31",
3
+ "version": "3.0.0-beta.33",
4
4
  "description": "legend-state",
5
5
  "sideEffects": false,
6
6
  "private": false,
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
- props[key] = useSelector(p, { skipCheck: true });
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, reactionOrOptions, options) {
521
+ function useObserve(selector, reactionOrOptionsOrDeps, options, deps) {
522
522
  let reaction;
523
- if (state.isFunction(reactionOrOptions)) {
524
- reaction = reactionOrOptions;
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 = reactionOrOptions;
529
+ options = reactionOrOptionsOrDeps;
527
530
  }
528
- const deps = options == null ? void 0 : options.deps;
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;
537
+ const ref = React.useRef({});
538
+ ref.current.selector = selector;
539
+ ref.current.reaction = reaction;
530
540
  if (depsObs$) {
531
541
  depsObs$.set(deps);
532
542
  }
533
- const ref = React.useRef({});
534
- ref.current.selector = deps ? () => {
535
- depsObs$ == null ? void 0 : depsObs$.get();
536
- return state.computeSelector(selector);
537
- } : selector;
538
- ref.current.reaction = reaction;
539
543
  if (!ref.current.dispose) {
540
544
  ref.current.dispose = state.observe(
541
- (e) => state.computeSelector(ref.current.selector, void 0, 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, reactionOrOptions, options) {
564
+ function useObserveEffect(selector, reactionOrOptionsOrDeps, options, deps) {
556
565
  let reaction;
557
- if (state.isFunction(reactionOrOptions)) {
558
- reaction = reactionOrOptions;
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 = reactionOrOptions;
572
+ options = reactionOrOptionsOrDeps;
573
+ }
574
+ if (reaction && Array.isArray(options)) {
575
+ deps = options;
576
+ options = void 0;
561
577
  }
562
- const deps = options == null ? void 0 : options.deps;
578
+ deps = deps || (options == null ? void 0 : options.deps);
579
+ const ref = React.useRef({});
563
580
  const depsObs$ = deps ? useObservable(deps) : void 0;
581
+ ref.current.selector = selector;
582
+ ref.current.reaction = reaction;
564
583
  if (depsObs$) {
565
584
  depsObs$.set(deps);
566
585
  }
567
- const ref = React.useRef({ selector });
568
- ref.current = { selector, reaction };
569
586
  useMountOnce(
570
587
  () => state.observe(
571
588
  (e) => {
572
- const { selector: selector2 } = ref.current;
589
+ var _a;
573
590
  depsObs$ == null ? void 0 : depsObs$.get();
574
- return state.isFunction(selector2) ? selector2(e) : selector2;
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
- props[key] = useSelector(p, { skipCheck: true });
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, reactionOrOptions, options) {
515
+ function useObserve(selector, reactionOrOptionsOrDeps, options, deps) {
516
516
  let reaction;
517
- if (isFunction(reactionOrOptions)) {
518
- reaction = reactionOrOptions;
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 = reactionOrOptions;
523
+ options = reactionOrOptionsOrDeps;
521
524
  }
522
- const deps = options == null ? void 0 : options.deps;
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;
531
+ const ref = useRef({});
532
+ ref.current.selector = selector;
533
+ ref.current.reaction = reaction;
524
534
  if (depsObs$) {
525
535
  depsObs$.set(deps);
526
536
  }
527
- const ref = useRef({});
528
- ref.current.selector = deps ? () => {
529
- depsObs$ == null ? void 0 : depsObs$.get();
530
- return computeSelector(selector);
531
- } : selector;
532
- ref.current.reaction = reaction;
533
537
  if (!ref.current.dispose) {
534
538
  ref.current.dispose = observe(
535
- (e) => computeSelector(ref.current.selector, void 0, 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, reactionOrOptions, options) {
558
+ function useObserveEffect(selector, reactionOrOptionsOrDeps, options, deps) {
550
559
  let reaction;
551
- if (isFunction(reactionOrOptions)) {
552
- reaction = reactionOrOptions;
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 = reactionOrOptions;
566
+ options = reactionOrOptionsOrDeps;
567
+ }
568
+ if (reaction && Array.isArray(options)) {
569
+ deps = options;
570
+ options = void 0;
555
571
  }
556
- const deps = options == null ? void 0 : options.deps;
572
+ deps = deps || (options == null ? void 0 : options.deps);
573
+ const ref = useRef({});
557
574
  const depsObs$ = deps ? useObservable(deps) : void 0;
575
+ ref.current.selector = selector;
576
+ ref.current.reaction = reaction;
558
577
  if (depsObs$) {
559
578
  depsObs$.set(deps);
560
579
  }
561
- const ref = useRef({ selector });
562
- ref.current = { selector, reaction };
563
580
  useMountOnce(
564
581
  () => observe(
565
582
  (e) => {
566
- const { selector: selector2 } = ref.current;
583
+ var _a;
567
584
  depsObs$ == null ? void 0 : depsObs$.get();
568
- return isFunction(selector2) ? selector2(e) : selector2;
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;
@@ -4,16 +4,18 @@ var state = require('@legendapp/state');
4
4
  var sync = require('@legendapp/state/sync');
5
5
 
6
6
  // src/sync-plugins/crud.ts
7
- var { clone, getKeys } = state.internal;
7
+ var { clone, getKeys, setNodeValue, getChildNode } = state.internal;
8
8
  var { waitForSet, runWithRetry } = sync.internal;
9
9
  function transformOut(data, transform) {
10
10
  return transform ? transform(clone(data)) : data;
11
11
  }
12
- function ensureId(obj, fieldId, generateId) {
12
+ function ensureId(obj, fieldId, generateId, node) {
13
13
  if (!obj[fieldId]) {
14
14
  obj[fieldId] = generateId();
15
+ if (node) {
16
+ setNodeValue(node, obj);
17
+ }
15
18
  }
16
- return obj[fieldId];
17
19
  }
18
20
  function computeLastSync(data, fieldUpdatedAt, fieldCreatedAt) {
19
21
  let newLastSync = 0;
@@ -210,11 +212,11 @@ function syncedCrud(props) {
210
212
  const { path, prevAtPath, valueAtPath, pathTypes } = change;
211
213
  if (asType === "value") {
212
214
  if (value) {
213
- let id = value == null ? void 0 : value[fieldId];
214
215
  let isCreate = fieldCreatedAt ? !value[fieldCreatedAt] : !prevAtPath;
215
- if (state.isNullOrUndefined(id) && generateId) {
216
- id = ensureId(value, fieldId, generateId);
216
+ if (state.isNullOrUndefined(value[fieldId]) && generateId) {
217
+ ensureId(value, fieldId, generateId, node);
217
218
  }
219
+ const id = value[fieldId];
218
220
  if (!state.isNullOrUndefined(id)) {
219
221
  changesById.set(id, change);
220
222
  if (pendingCreates.has(id)) {
@@ -253,6 +255,14 @@ function syncedCrud(props) {
253
255
  } else {
254
256
  let itemsChanged = [];
255
257
  if (path.length === 0) {
258
+ if (asArray && generateId) {
259
+ for (let i = 0; i < valueAtPath.length; i++) {
260
+ const value2 = valueAtPath[i];
261
+ if (value2 && !value2[fieldId]) {
262
+ ensureId(value2, fieldId, generateId, getChildNode(node, i + ""));
263
+ }
264
+ }
265
+ }
256
266
  const valueAsObject = asArray ? arrayToRecord(valueAtPath, fieldId) : valueAtPath;
257
267
  const prevAsObject = asArray ? arrayToRecord(prevAtPath, fieldId) : prevAtPath;
258
268
  const keys = getKeys(valueAsObject, false, asMap, false);
@@ -289,6 +299,9 @@ function syncedCrud(props) {
289
299
  changesById.set(prevAtPath[fieldId], change);
290
300
  }
291
301
  } else {
302
+ if (generateId) {
303
+ ensureId(itemValue, fieldId, generateId, getChildNode(node, itemKey + ""));
304
+ }
292
305
  const previous = state.setAtPath(
293
306
  clone(itemValue),
294
307
  path.slice(1),
@@ -301,9 +314,6 @@ function syncedCrud(props) {
301
314
  itemsChanged == null ? void 0 : itemsChanged.forEach(([item, prev, fullValue]) => {
302
315
  const isCreate = !pendingCreates.has(item[fieldId]) && (fieldCreatedAt ? !item[fieldCreatedAt] && !(prev == null ? void 0 : prev[fieldCreatedAt]) : fieldUpdatedAt ? !item[fieldUpdatedAt] && !(prev == null ? void 0 : prev[fieldCreatedAt]) : state.isNullOrUndefined(prev));
303
316
  if (isCreate) {
304
- if (generateId) {
305
- ensureId(item, fieldId, generateId);
306
- }
307
317
  if (!item[fieldId]) {
308
318
  console.error("[legend-state]: added item without an id");
309
319
  }
@@ -2,16 +2,18 @@ import { isPromise, isNullOrUndefined, applyChanges, setAtPath, symbolDelete, is
2
2
  import { synced, deepEqual, internal as internal$1, diffObjects } from '@legendapp/state/sync';
3
3
 
4
4
  // src/sync-plugins/crud.ts
5
- var { clone, getKeys } = internal;
5
+ var { clone, getKeys, setNodeValue, getChildNode } = internal;
6
6
  var { waitForSet, runWithRetry } = internal$1;
7
7
  function transformOut(data, transform) {
8
8
  return transform ? transform(clone(data)) : data;
9
9
  }
10
- function ensureId(obj, fieldId, generateId) {
10
+ function ensureId(obj, fieldId, generateId, node) {
11
11
  if (!obj[fieldId]) {
12
12
  obj[fieldId] = generateId();
13
+ if (node) {
14
+ setNodeValue(node, obj);
15
+ }
13
16
  }
14
- return obj[fieldId];
15
17
  }
16
18
  function computeLastSync(data, fieldUpdatedAt, fieldCreatedAt) {
17
19
  let newLastSync = 0;
@@ -208,11 +210,11 @@ function syncedCrud(props) {
208
210
  const { path, prevAtPath, valueAtPath, pathTypes } = change;
209
211
  if (asType === "value") {
210
212
  if (value) {
211
- let id = value == null ? void 0 : value[fieldId];
212
213
  let isCreate = fieldCreatedAt ? !value[fieldCreatedAt] : !prevAtPath;
213
- if (isNullOrUndefined(id) && generateId) {
214
- id = ensureId(value, fieldId, generateId);
214
+ if (isNullOrUndefined(value[fieldId]) && generateId) {
215
+ ensureId(value, fieldId, generateId, node);
215
216
  }
217
+ const id = value[fieldId];
216
218
  if (!isNullOrUndefined(id)) {
217
219
  changesById.set(id, change);
218
220
  if (pendingCreates.has(id)) {
@@ -251,6 +253,14 @@ function syncedCrud(props) {
251
253
  } else {
252
254
  let itemsChanged = [];
253
255
  if (path.length === 0) {
256
+ if (asArray && generateId) {
257
+ for (let i = 0; i < valueAtPath.length; i++) {
258
+ const value2 = valueAtPath[i];
259
+ if (value2 && !value2[fieldId]) {
260
+ ensureId(value2, fieldId, generateId, getChildNode(node, i + ""));
261
+ }
262
+ }
263
+ }
254
264
  const valueAsObject = asArray ? arrayToRecord(valueAtPath, fieldId) : valueAtPath;
255
265
  const prevAsObject = asArray ? arrayToRecord(prevAtPath, fieldId) : prevAtPath;
256
266
  const keys = getKeys(valueAsObject, false, asMap, false);
@@ -287,6 +297,9 @@ function syncedCrud(props) {
287
297
  changesById.set(prevAtPath[fieldId], change);
288
298
  }
289
299
  } else {
300
+ if (generateId) {
301
+ ensureId(itemValue, fieldId, generateId, getChildNode(node, itemKey + ""));
302
+ }
290
303
  const previous = setAtPath(
291
304
  clone(itemValue),
292
305
  path.slice(1),
@@ -299,9 +312,6 @@ function syncedCrud(props) {
299
312
  itemsChanged == null ? void 0 : itemsChanged.forEach(([item, prev, fullValue]) => {
300
313
  const isCreate = !pendingCreates.has(item[fieldId]) && (fieldCreatedAt ? !item[fieldCreatedAt] && !(prev == null ? void 0 : prev[fieldCreatedAt]) : fieldUpdatedAt ? !item[fieldUpdatedAt] && !(prev == null ? void 0 : prev[fieldCreatedAt]) : isNullOrUndefined(prev));
301
314
  if (isCreate) {
302
- if (generateId) {
303
- ensureId(item, fieldId, generateId);
304
- }
305
315
  if (!item[fieldId]) {
306
316
  console.error("[legend-state]: added item without an id");
307
317
  }
package/sync.js CHANGED
@@ -283,7 +283,7 @@ function transformLoadData(value, { transform }, doUserTransform, method) {
283
283
  }
284
284
  return value;
285
285
  }
286
- async function updateMetadataImmediate(value$, localState, syncState2, syncOptions, newMetadata) {
286
+ async function updateMetadataImmediate(value$, localState, syncState$, syncOptions, newMetadata) {
287
287
  const saves = Array.from(promisesLocalSaves);
288
288
  if (saves.length > 0) {
289
289
  await Promise.all(saves);
@@ -298,7 +298,7 @@ async function updateMetadataImmediate(value$, localState, syncState2, syncOptio
298
298
  await pluginPersist.setMetadata(table, metadata, config);
299
299
  }
300
300
  if (lastSync) {
301
- syncState2.assign({
301
+ syncState$.assign({
302
302
  lastSync
303
303
  });
304
304
  }
@@ -935,8 +935,7 @@ function syncObservable(obs$, syncOptionsOrSynced) {
935
935
  };
936
936
  const { get, subscribe } = syncOptions;
937
937
  if (get || subscribe) {
938
- sync = async () => {
939
- var _a;
938
+ sync = async (options) => {
940
939
  if (isSynced && (!getNodeValue(getNode(syncState$)).isSyncEnabled || state.shouldIgnoreUnobserved(node, sync))) {
941
940
  if (unsubscribe) {
942
941
  isSubscribed = false;
@@ -945,11 +944,16 @@ function syncObservable(obs$, syncOptionsOrSynced) {
945
944
  }
946
945
  return;
947
946
  }
948
- const lastSync = (_a = metadatas.get(obs$)) == null ? void 0 : _a.lastSync;
947
+ const metadata = metadatas.get(obs$);
948
+ if (metadata && (options == null ? void 0 : options.resetLastSync)) {
949
+ metadata.lastSync = void 0;
950
+ syncState$.lastSync.set(void 0);
951
+ }
952
+ const lastSync = metadata == null ? void 0 : metadata.lastSync;
949
953
  const pending = localState.pendingChanges;
950
954
  const { waitFor } = syncOptions;
951
955
  const runGet = () => {
952
- var _a2;
956
+ var _a;
953
957
  const onChange = async ({ value, mode, lastSync: lastSync2 }) => {
954
958
  mode = mode || syncOptions.mode || "set";
955
959
  if (value !== void 0) {
@@ -1065,7 +1069,7 @@ function syncObservable(obs$, syncOptionsOrSynced) {
1065
1069
  }
1066
1070
  );
1067
1071
  },
1068
- refresh: () => state.when(syncState$.isLoaded, sync),
1072
+ refresh: () => state.when(syncState$.isLoaded, () => sync()),
1069
1073
  onError: (error) => onGetError(error, {
1070
1074
  source: "subscribe",
1071
1075
  subscribeParams,
@@ -1120,14 +1124,14 @@ function syncObservable(obs$, syncOptionsOrSynced) {
1120
1124
  });
1121
1125
  },
1122
1126
  resetCache: () => {
1123
- var _a3;
1127
+ var _a2;
1124
1128
  modeBeforeReset = getParams.mode;
1125
1129
  getParams.mode = "set";
1126
- return (_a3 = syncStateValue.resetPersistence) == null ? void 0 : _a3.call(syncStateValue);
1130
+ return (_a2 = syncStateValue.resetPersistence) == null ? void 0 : _a2.call(syncStateValue);
1127
1131
  },
1128
1132
  cancel: false
1129
1133
  };
1130
- (_a2 = syncOptions.onBeforeGet) == null ? void 0 : _a2.call(syncOptions, beforeGetParams);
1134
+ (_a = syncOptions.onBeforeGet) == null ? void 0 : _a.call(syncOptions, beforeGetParams);
1131
1135
  if (!beforeGetParams.cancel) {
1132
1136
  syncState$.assign({
1133
1137
  numPendingGets: (syncStateValue.numPendingGets || 0) + 1,
@@ -1175,9 +1179,9 @@ function syncObservable(obs$, syncOptionsOrSynced) {
1175
1179
  }
1176
1180
  };
1177
1181
  if (waitFor) {
1178
- state.whenReady(waitFor, () => state.trackSelector(runGet, sync));
1182
+ state.whenReady(waitFor, () => state.trackSelector(runGet, () => sync()));
1179
1183
  } else {
1180
- state.trackSelector(runGet, sync);
1184
+ state.trackSelector(runGet, () => sync());
1181
1185
  }
1182
1186
  if (!isSynced) {
1183
1187
  isSynced = true;
@@ -1201,7 +1205,7 @@ function syncObservable(obs$, syncOptionsOrSynced) {
1201
1205
  if (metadata) {
1202
1206
  Object.assign(metadata, { lastSync: void 0, pending: void 0 });
1203
1207
  }
1204
- Object.assign(syncStateValue, {
1208
+ const newState = {
1205
1209
  isPersistEnabled: false,
1206
1210
  isSyncEnabled: false,
1207
1211
  lastSync: void 0,
@@ -1211,7 +1215,8 @@ function syncObservable(obs$, syncOptionsOrSynced) {
1211
1215
  isSetting: false,
1212
1216
  numPendingSets: 0,
1213
1217
  syncCount: 0
1214
- });
1218
+ };
1219
+ Object.assign(syncStateValue, newState);
1215
1220
  isSynced = false;
1216
1221
  isSubscribed = false;
1217
1222
  unsubscribe == null ? void 0 : unsubscribe();
package/sync.mjs CHANGED
@@ -281,7 +281,7 @@ function transformLoadData(value, { transform }, doUserTransform, method) {
281
281
  }
282
282
  return value;
283
283
  }
284
- async function updateMetadataImmediate(value$, localState, syncState2, syncOptions, newMetadata) {
284
+ async function updateMetadataImmediate(value$, localState, syncState$, syncOptions, newMetadata) {
285
285
  const saves = Array.from(promisesLocalSaves);
286
286
  if (saves.length > 0) {
287
287
  await Promise.all(saves);
@@ -296,7 +296,7 @@ async function updateMetadataImmediate(value$, localState, syncState2, syncOptio
296
296
  await pluginPersist.setMetadata(table, metadata, config);
297
297
  }
298
298
  if (lastSync) {
299
- syncState2.assign({
299
+ syncState$.assign({
300
300
  lastSync
301
301
  });
302
302
  }
@@ -933,8 +933,7 @@ function syncObservable(obs$, syncOptionsOrSynced) {
933
933
  };
934
934
  const { get, subscribe } = syncOptions;
935
935
  if (get || subscribe) {
936
- sync = async () => {
937
- var _a;
936
+ sync = async (options) => {
938
937
  if (isSynced && (!getNodeValue(getNode(syncState$)).isSyncEnabled || shouldIgnoreUnobserved(node, sync))) {
939
938
  if (unsubscribe) {
940
939
  isSubscribed = false;
@@ -943,11 +942,16 @@ function syncObservable(obs$, syncOptionsOrSynced) {
943
942
  }
944
943
  return;
945
944
  }
946
- const lastSync = (_a = metadatas.get(obs$)) == null ? void 0 : _a.lastSync;
945
+ const metadata = metadatas.get(obs$);
946
+ if (metadata && (options == null ? void 0 : options.resetLastSync)) {
947
+ metadata.lastSync = void 0;
948
+ syncState$.lastSync.set(void 0);
949
+ }
950
+ const lastSync = metadata == null ? void 0 : metadata.lastSync;
947
951
  const pending = localState.pendingChanges;
948
952
  const { waitFor } = syncOptions;
949
953
  const runGet = () => {
950
- var _a2;
954
+ var _a;
951
955
  const onChange = async ({ value, mode, lastSync: lastSync2 }) => {
952
956
  mode = mode || syncOptions.mode || "set";
953
957
  if (value !== void 0) {
@@ -1063,7 +1067,7 @@ function syncObservable(obs$, syncOptionsOrSynced) {
1063
1067
  }
1064
1068
  );
1065
1069
  },
1066
- refresh: () => when(syncState$.isLoaded, sync),
1070
+ refresh: () => when(syncState$.isLoaded, () => sync()),
1067
1071
  onError: (error) => onGetError(error, {
1068
1072
  source: "subscribe",
1069
1073
  subscribeParams,
@@ -1118,14 +1122,14 @@ function syncObservable(obs$, syncOptionsOrSynced) {
1118
1122
  });
1119
1123
  },
1120
1124
  resetCache: () => {
1121
- var _a3;
1125
+ var _a2;
1122
1126
  modeBeforeReset = getParams.mode;
1123
1127
  getParams.mode = "set";
1124
- return (_a3 = syncStateValue.resetPersistence) == null ? void 0 : _a3.call(syncStateValue);
1128
+ return (_a2 = syncStateValue.resetPersistence) == null ? void 0 : _a2.call(syncStateValue);
1125
1129
  },
1126
1130
  cancel: false
1127
1131
  };
1128
- (_a2 = syncOptions.onBeforeGet) == null ? void 0 : _a2.call(syncOptions, beforeGetParams);
1132
+ (_a = syncOptions.onBeforeGet) == null ? void 0 : _a.call(syncOptions, beforeGetParams);
1129
1133
  if (!beforeGetParams.cancel) {
1130
1134
  syncState$.assign({
1131
1135
  numPendingGets: (syncStateValue.numPendingGets || 0) + 1,
@@ -1173,9 +1177,9 @@ function syncObservable(obs$, syncOptionsOrSynced) {
1173
1177
  }
1174
1178
  };
1175
1179
  if (waitFor) {
1176
- whenReady(waitFor, () => trackSelector(runGet, sync));
1180
+ whenReady(waitFor, () => trackSelector(runGet, () => sync()));
1177
1181
  } else {
1178
- trackSelector(runGet, sync);
1182
+ trackSelector(runGet, () => sync());
1179
1183
  }
1180
1184
  if (!isSynced) {
1181
1185
  isSynced = true;
@@ -1199,7 +1203,7 @@ function syncObservable(obs$, syncOptionsOrSynced) {
1199
1203
  if (metadata) {
1200
1204
  Object.assign(metadata, { lastSync: void 0, pending: void 0 });
1201
1205
  }
1202
- Object.assign(syncStateValue, {
1206
+ const newState = {
1203
1207
  isPersistEnabled: false,
1204
1208
  isSyncEnabled: false,
1205
1209
  lastSync: void 0,
@@ -1209,7 +1213,8 @@ function syncObservable(obs$, syncOptionsOrSynced) {
1209
1213
  isSetting: false,
1210
1214
  numPendingSets: 0,
1211
1215
  syncCount: 0
1212
- });
1216
+ };
1217
+ Object.assign(syncStateValue, newState);
1213
1218
  isSynced = false;
1214
1219
  isSubscribed = false;
1215
1220
  unsubscribe == null ? void 0 : unsubscribe();