Readonly Charm atom
Hello,
For the context I am creating a service that manage goals as abstract as possible, having a progress and goal numeric value, getting completed when progress reach goal.
So I want other services creating the goal to be able to know when this goal progress and so I thought about using atom for progress value (why not also goal value) but returning the atom would mean the other service could change the atom value, is it possible to have a readonly version of this atom?
14 Replies
have you considered returning a function that reads the atom
Solution
is it still possible to subscribe to the atom?
you can create an interface yourself that will return a read-only atom or you can simply make a method that will return the date from the atom
I am not sure to understand what would be a readonly atom
I saw the mention of selector that seems to be that but I don't how to create one from an atom
yes this is what you need, just cast it to this type
just do what alice said
const myReadonly = () => myAtom();
ok but is it still interpreted as a selector?
yes, selector is a type of function that returns a date and takes no arguments
but so i am not able anymore place subscription on it?
You can subscribe using the subscribe function
An atom is a function, not a table in the usual sense
so as an analogy it could be adding a layer on the atom that make the real atom unreachable? and so readonly
yes
ok, Thank you all for your help!