Skip to content

Commit

Permalink
revert(vanilla): reverts pmndrs#2186
Browse files Browse the repository at this point in the history
  • Loading branch information
yf-yang committed Jan 22, 2024
1 parent b5c3808 commit 83731ed
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
15 changes: 6 additions & 9 deletions src/vanilla/atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,19 @@ export function atom<Value, Args extends unknown[], Result>(
config.read = read as Read<Value, SetAtom<Args, Result>>
} else {
config.init = read
config.read = function (get) {
return get(this)
}
config.write = function (
this: PrimitiveAtom<Value>,
config.read = (get) => get(config)
config.write = ((
get: Getter,
set: Setter,
arg: SetStateAction<Value>,
) {
) => {
return set(
this,
config as unknown as PrimitiveAtom<Value>,
typeof arg === 'function'
? (arg as (prev: Value) => Value)(get(this))
? (arg as (prev: Value) => Value)(get(config))
: arg,
)
} as unknown as Write<Args, Result>
}) as unknown as Write<Args, Result>
}
if (write) {
config.write = write
Expand Down
4 changes: 1 addition & 3 deletions src/vanilla/utils/freezeAtom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ export function freezeAtomCreator<
return ((...params: any[]) => {
const anAtom = createAtom(...params)
const origRead = anAtom.read
anAtom.read = function (get, options) {
return deepFreeze(origRead.call(this, get, options))
}
anAtom.read = (get, options) => deepFreeze(origRead(get, options))
return anAtom
}) as CreateAtom
}
3 changes: 1 addition & 2 deletions src/vanilla/utils/unwrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ export function unwrap<Value, Args extends unknown[], Result, PendingValue>(
}
return state.v
},
(_get, set, ...args) =>
set(anAtom as WritableAtom<Value, unknown[], unknown>, ...args),
(anAtom as WritableAtom<Value, unknown[], unknown>).write
)
},
anAtom,
Expand Down

0 comments on commit 83731ed

Please sign in to comment.