experiment with a Store<K> parameter for Reflectors - #102 #220
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
in an effort to solve #102 we try to factor out the implicit data store inside
Reflector<K>
as a trait object that can be customised. Currently, have tried to do this asGenericReflector<S, K>
whereS: Store<K>
andStore
is a trait.The abstraction, feels very rigid, and not sure how usable it is, but throwing it out here before I go all out on it. It currently doesn't fully compile.
Ultimately, I wanted:
a nicer interface for users of library that wasn't "give me a CLONE of ALL state" or "give me one thing with a matching ID" (both while waiting for the internal reflector state lock).
allow transformation to the underlying data when storing it
The second was super awkward with the old Reflector setup because you'd effectively force two whole clones of the two types, and you'd have to recreate your shadow tree every time you asked for the state (which was ALL of the input).
Sidenotes
The ownership model of the store could potentially be inverted with this setup. Maybe the user passes it in, but then they probably want a different storing interface? Supporting async operations with Result? (This is why callbacks now are awkward).
The Store feels very tied to BTreeMap or HashMap atm due to add/modify/clear/get/delete requirement, but not sure that's a problem. We also already have a free Into on K so we are guaranteed to have a key.