Skip to content

Commit

Permalink
fix getFn passing noop functions when not in persist
Browse files Browse the repository at this point in the history
  • Loading branch information
jmeistrich committed Nov 21, 2023
1 parent 6090f19 commit 7baaa12
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/ObservableObject.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { noop } from '@babel/types';
import { batch, beginBatch, endBatch, isArraySubset, notify } from './batching';
import { createObservable } from './createObservable';
import {
Expand Down Expand Up @@ -46,11 +45,13 @@ import type {
import { Observable, ObservableState } from './observableTypes';
import { observe } from './observe';
import { onChange } from './onChange';
import { ObservablePersistState, ObservablePersistStateInternal } from './persistTypes';
import { ObservablePersistStateInternal } from './persistTypes';
import { setupRetry } from './retry';
import { updateTracking } from './tracking';
import { whenReady } from './when';

const noop = () => {};

const ArrayModifiers = new Set([
'copyWithin',
'fill',
Expand Down Expand Up @@ -951,9 +952,14 @@ function activateNodeFunction(node: NodeValue, lazyFn: () => void) {
} else if (node.activationState) {
if (!node.activationState!.persistedRetry && !node.activationState.waitFor) {
const activated = node.activationState!;
// TODO
// @ts-expect-error asdf
value = activated.get?.({ updateLastSync: noop, setMode: noop }) ?? activated.initial;
// TODO Should this have lastSync and value somehow?
value =
activated.get?.({
updateLastSync: noop,
setMode: noop,
lastSync: undefined,
value: undefined,
}) ?? activated.initial;
}
}
wasPromise = wasPromise || isPromise(value);
Expand Down Expand Up @@ -1044,8 +1050,11 @@ const activateNodeBase = (globalState.activateNode = function activateNodeBase(
let _mode: 'assign' | 'set' = 'set';
if (node.activationState) {
const { onSet, subscribe, get: getFn, initial, retry, waitFor } = node.activationState;
// @ts-expect-error asdf
const run = () => getFn!({ updateLastSync: noop, setMode: (mode) => (_mode = mode) });

// TODO Should this have lastSync and value somehow?
const run = () =>
getFn!({ updateLastSync: noop, setMode: (mode) => (_mode = mode), lastSync: undefined, value: undefined });

value = getFn
? waitFor
? new Promise((resolve) => {
Expand Down

0 comments on commit 7baaa12

Please sign in to comment.