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?
Solution:
return function()
return atom()
end
return function()
return atom()
end
...
Jump to solution
14 Replies
alice
alice6d ago
have you considered returning a function that reads the atom
Solution
alice
alice6d ago
return function()
return atom()
end
return function()
return atom()
end
Dadamo
DadamoOP6d ago
is it still possible to subscribe to the atom?
Tesmi
Tesmi6d ago
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
Dadamo
DadamoOP6d ago
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
Tesmi
Tesmi6d ago
yes this is what you need, just cast it to this type
runic
runic6d ago
just do what alice said const myReadonly = () => myAtom();
Dadamo
DadamoOP6d ago
ok but is it still interpreted as a selector?
Tesmi
Tesmi6d ago
yes, selector is a type of function that returns a date and takes no arguments
Dadamo
DadamoOP6d ago
but so i am not able anymore place subscription on it?
Tesmi
Tesmi6d ago
You can subscribe using the subscribe function An atom is a function, not a table in the usual sense
Dadamo
DadamoOP6d ago
so as an analogy it could be adding a layer on the atom that make the real atom unreachable? and so readonly
Tesmi
Tesmi6d ago
yes
Dadamo
DadamoOP6d ago
ok, Thank you all for your help!

Did you find this page helpful?