Skip to content

Commit

Permalink
remove updateLastSync and applyRemoteChange - it's supposed to just s…
Browse files Browse the repository at this point in the history
…end changes, dateModified through persist set
  • Loading branch information
jmeistrich committed Oct 28, 2023
1 parent 8ec4fbd commit baf447a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
1 change: 0 additions & 1 deletion persist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ persistActivateNode();
declare module '@legendapp/state' {
interface ActivateParams<T> {
cache: (cacheOptions: CacheOptions<T> | (() => CacheOptions<T>)) => void;
updateLastSync: (lastSync: number) => void;
retry: (options?: RetryOptions) => void;
}
interface OnSetExtra {}
Expand Down
6 changes: 0 additions & 6 deletions src/ObservableObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -865,11 +865,6 @@ function createNodeActivationParams(node: NodeValue): ActivateProxyParams {
const onSet: ActivateParams['onSet'] = (onSetFnParam) => {
state.onSetFn = onSetFnParam;
};
// The onSet function handles the observable being set
// and forwards the set elsewhere
const updateLastSync: ActivateParams['updateLastSync'] = (fn) => {
state.lastSync.value = fn;
};
// The subscribe function runs a function that listens to
// a data source and sends updates into the observable
const subscribe: ActivateParams['subscribe'] = (fn) => {
Expand Down Expand Up @@ -900,7 +895,6 @@ function createNodeActivationParams(node: NodeValue): ActivateProxyParams {
cache,
retry,
subscribe,
updateLastSync,
obs$: getProxy(node),
};
}
Expand Down
19 changes: 8 additions & 11 deletions src/persist/persistActivateNode.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import type {
CacheOptions,
ListenerParams,
NodeValue,
ObservableOnChangeParams,
ObservablePersistRemoteFunctions,
ObservablePersistRemoteGetParams,
ObservablePersistRemoteSetParams,
ObservablePersistStateBase,
RetryOptions,
UpdateFn,
} from '@legendapp/state';
import { internal, isPromise } from '@legendapp/state';
import { onChangeRemote, persistObservable } from './persistObservable';
import { persistObservable } from './persistObservable';
const { getProxy, globalState } = internal;

export function persistActivateNode() {
Expand Down Expand Up @@ -43,12 +40,13 @@ export function persistActivateNode() {
// TODO: Work out these types better
pluginRemote.set = (params: ObservablePersistRemoteSetParams<any>) => {
if (node.state?.isLoaded.get()) {
onSetFn(params as unknown as ListenerParams, {
update: onChange as UpdateFn,
updateLastSync: () => {
console.log('TODO updateLastSync');
},
applyRemoteChange: onChangeRemote,
return new Promise((resolve) => {
onSetFn(params as unknown as ListenerParams, {
update: (params) => {
const { value, dateModified } = params;
resolve({ changes: value as object, dateModified });
},
});
});
}
};
Expand All @@ -64,7 +62,6 @@ export function persistActivateNode() {
}
},
refresh,
applyRemoteChange: onChangeRemote,
});
}
persistObservable(getProxy(node), {
Expand Down

0 comments on commit baf447a

Please sign in to comment.