Cursor support?
mikera opened this issue · 2 comments
There are a few instances where I've found myself wanting something like Om's cursors for the purposes of updating a system without having to do everything at the top level, i.e the component doesn't need to know anything about the context in which it is being used.
Slightly contrived example:
(defn add-user [user-component user-id user-data]
(update! user-component assoc-in [:users user-id] user-data))
Here the update!
function does something like Om's transact!
to the whole system, and assumes that user-component is a cursor over the underlying component.
Is this something that component could reasonably support? I think cursors could be implemented in a way that:
- Maintains a path into the component tree
- Allows different update semantics to be provided, so that it can be hooked into whatever top-level state management is being used
- Is otherwise fairly transparent to functions that work with components
Could you not solve this by mounting sub-systems?
My goal is that the system object should never be used to store or update state. Instead, components can keep local state in Atoms/Refs/etc. Functions which needs to update that state should receive the component as an argument, optionally by closing over it.