Skip to content

Commit

Permalink
fix: replace 'mergeUpdate' w shallow-merge to not break Observable
Browse files Browse the repository at this point in the history
  • Loading branch information
trevor-anderson committed May 13, 2023
1 parent 72f6215 commit 2baa88f
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/app/apolloCache/reactiveVars/ReactiveStore.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { makeVar, type ReactiveVar } from "@apollo/client/cache";
import { useReactiveVar } from "@apollo/client/react/hooks";
import deepMerge from "lodash.merge";
import { storage, type LocalStorageWrapperKey } from "@utils/storage";
import type { PartialDeep } from "type-fest";

/**
* A handy wrapper around apollo's reactive-var functionality.
Expand Down Expand Up @@ -63,12 +61,18 @@ export class ReactiveStore<T extends ReactiveStoreValueType> {
}

/**
* Deep-merges the provided value with the current value of the reactive-var.
* Shallow-merges the provided value with the current value of the reactive-var.
* If a `storageKey` was provided, the value is also updated in localStorage.
*
* > Note: This method is only available for reactive-vars with object values,
* and must only be called with an object value.
*/
mergeUpdate(partialNewValue?: PartialDeep<T>) {
const newValue = deepMerge(this.reactiveVar(), partialNewValue);
return this.set(newValue);
mergeUpdate(partialNewValue: Partial<T>) {
const currentValue = this.get();
return this.set({
...(currentValue && typeof currentValue === "object" && currentValue),
...(partialNewValue && partialNewValue),
} as T);
}

/**
Expand Down

0 comments on commit 2baa88f

Please sign in to comment.