Skip to content

Commit

Permalink
Try solving computed immediate with sideEffects: false
Browse files Browse the repository at this point in the history
  • Loading branch information
jmeistrich committed Nov 8, 2023
1 parent c6453ac commit a8a8a2c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ObservableObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ const activateNodeBase = (globalState.activateNode = function activateNodeBase(
let isSettingFromSubscribe = false;
let _mode: 'assign' | 'set' = 'set';
if (node.activationState) {
const { onSet, subscribe, get, initial, retry, waitFor } = node.activationState;
const { onSet, subscribe, get, initial, retry, waitFor, sideEffects } = node.activationState;
// @ts-expect-error asdf
const run = () => get!({ updateLastSync: noop, setMode: (mode) => (_mode = mode) });
value = get
Expand Down Expand Up @@ -1063,7 +1063,7 @@ const activateNodeBase = (globalState.activateNode = function activateNodeBase(
}
};

onChange(node, doSet as any, wasPromise ? undefined : { immediate: true });
onChange(node, doSet as any, sideEffects === false || wasPromise ? undefined : { immediate: true });
}
if (process.env.NODE_ENV === 'development' && node.activationState!.cache) {
// TODO Better message
Expand Down
1 change: 1 addition & 0 deletions src/observableInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export interface ActivateParams<T = any> {
get?: (params: ActivateGetParams) => T;
retry?: RetryOptions;
mode?: 'assign' | 'set' | 'dateModified';
sideEffects?: boolean;
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export interface ActivateParamsWithLookup<T extends Record<string, any> = Record<string, any>>
Expand Down

0 comments on commit a8a8a2c

Please sign in to comment.