About a week ago Jotai https://jotai.pmnd.rs/ introduced an api change in v1.0.1 where writable atoms can specify an optional boolean like the following:
import { atom } from "jotai";
let valueAtom = atom(5);
let multiplyByAtom = atom(
get => get(valueAtom),
(get, set, multiplier) => {
let value = get(valueAtom, false); // Newly added second arg is given, defaults to true
set(valueAtom, value * multiplier);
}
)
In the Jotai bindings I’m working with, get is defined like:
@ocaml.doc("Under the hood, getter is a function that takes an atom and returns a value for this atom.
Must be used with the `get` function.")
type getter
@ocaml.doc("Unlike the original API, and in order to keep the flexibility, derived atoms requires some light runtime code and small changes to the semantic: `get` is now `getter` (see `derivedAtom` and `derivedAsyncAtom` for more).
// Inside a derived atom
let value = getter->Jotai.Atom.get(atom)
")
let get = (type value, get: getter, atom: t<value, _, [> Permissions.r]>): value =>
Obj.magic(get, atom)
Is Obj.magic calling get(atom) behind the scenes? How would I work with it now that get takes two arguments? Would I store the output of Obj.magic as a value and apply another argument?
Any help here would be highly appreciated!
If it helps the repo is at GitHub - eccentric-j/re-jotai at stable