[atom] Why is there no method getIn? #487
-
Greetings Why is there no method getIn ? I am looking for a simple solution to get the value in Atom by path
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @bit-app-3000 — apologies I forgot to respond to this, in case you're still needing an answer: The deep accessor functionality like So to use import { defAtom } from "@thi.ng/atom";
import { getIn, getInUnsafe } from "@thi.ng/paths";
const db = defAtom({ a: { b: { c: 42 } } });
// access via type checked path
console.log(getIn(db.deref(), ["a","b","c"]));
// or unchecked path
console.log(getInUnsafe(db.deref(), ["a","b","c"]));
// or path as string
console.log(getInUnsafe(db.deref(), "a.b.c")); |
Beta Was this translation helpful? Give feedback.
Hi @bit-app-3000 — apologies I forgot to respond to this, in case you're still needing an answer: The deep accessor functionality like
getIn
,setIn
,updateIn
was alwyas meant to be kept a separate feature (so it can also be used with other data structures, incl. vanilla JS objects) and therefore is available as separate package: thi.ng/paths. In my experience I found updating nested values in an atom is much more common than reading nested values directly. For the latter it's much more common to have (reactive) views or cursors defined, and so atoms only provide nested-value update functions likeresetIn
,updateIn
, but not nested readonly accessors likegetIn
... so far no one else has bro…