-
-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Limiting state writing #110
Comments
It's worth mentioning that a solution here could possibly relate partially to #35, as changing how we retrieve values could potentially also change how we treat constants versus state. |
Another idea I like, though it doesn't address all the motivating problems, is the ability for value objects to give away write control over their value, turning the object itself read-only: local foo = Value(5)
local access = foo:giveMeExclusiveWriteControl()
access:set(10)
print(peek(foo)) -- 10
foo:set(2) -- error |
I think it makes more sense to do that as |
Mostly I'm thinking of use cases where you pass a value into a function call with the expectation that the function call starts maintaining that value for you, in which case it becomes a way of enforcing strongly that two agents don't have write access at the same time. Think e.g. |
Currently, set and get operations are present as methods on a single state object:
However, this poses a problem: what if we don't want to give full write permissions to someone we're giving our state objects to?
Users end up having to get inventive with weird solutions like passthrough Computed objects, which aren't really great:
It might be worth investigating some way of separating out the reading and writing abilities of a state object.
One solution could be adopting React/Solid-like setter/getter splitting (open question: how does this translate to objects with more complex setting behaviour, for example a spring where we might want to read and write aspects like velocity and position?)
Another solution, perhaps more Fusion-like, would be introducing a utility ReadOnly function that creates a limited version of a state object for the user - this would almost certainly be optimised under the hood:
The text was updated successfully, but these errors were encountered: