Skip to content

Commit

Permalink
Remove reassigmenment
Browse files Browse the repository at this point in the history
  • Loading branch information
jvliwanag committed Jan 6, 2025
1 parent e7abb6f commit e6264c9
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/rx/src/Rx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1026,23 +1026,23 @@ export const family = typeof WeakRef === "undefined" || typeof FinalizationRegis
<Arg, T extends object>(
f: (arg: Arg) => T
): (arg: Arg) => T => {
let atoms = MutableHashMap.empty<Arg, T>()
const atoms = MutableHashMap.empty<Arg, T>()
return function(arg) {
const atomEntry = MutableHashMap.get(atoms, arg)
if (atomEntry._tag === "Some") {
return atomEntry.value
}
const newAtom = f(arg)
atoms = MutableHashMap.set(atoms, arg, newAtom)
MutableHashMap.set(atoms, arg, newAtom)
return newAtom
}
} :
<Arg, T extends object>(
f: (arg: Arg) => T
): (arg: Arg) => T => {
let atoms = MutableHashMap.empty<Arg, WeakRef<T>>()
const atoms = MutableHashMap.empty<Arg, WeakRef<T>>()
const registry = new FinalizationRegistry<Arg>((arg) => {
atoms = MutableHashMap.remove(atoms, arg)
MutableHashMap.remove(atoms, arg)
})
return function(arg) {
const atomEntry = MutableHashMap.get(atoms, arg).pipe(
Expand All @@ -1053,7 +1053,7 @@ export const family = typeof WeakRef === "undefined" || typeof FinalizationRegis
return atomEntry.value
}
const newAtom = f(arg)
atoms = MutableHashMap.set(atoms, arg, new WeakRef(newAtom))
MutableHashMap.set(atoms, arg, new WeakRef(newAtom))
registry.register(newAtom, arg)
return newAtom
}
Expand Down

0 comments on commit e6264c9

Please sign in to comment.