Skip to content
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

experiment with a Store<K> parameter for Reflectors - #102 #220

Closed
wants to merge 1 commit into from

Conversation

clux
Copy link
Member

@clux clux commented Apr 8, 2020

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 as GenericReflector<S, K> where S: Store<K> and Store 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.

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 customized.

The abstraction, feels very rigid, and not sure how useable it is.
Ultimately, I wanted a nicer interface for users of library that wasnt
"give me a CLONE of ALL state" or "give me one thing with a matching
ID".

It's potentially possible to take type that implemented iterator with
this approach, as well as MAYBE handing out an arc'd clone to users
(provided they are told not to keep it locked for ages).

Another problem I wanted to solve was having the stored state be a
simplified version of the underlying data (i.e. add/modify would perform
some kind of transformation before storing it). This 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).
@clux
Copy link
Member Author

clux commented Jul 17, 2020

Replaced by #258

@clux clux closed this Jul 17, 2020
@clux clux deleted the reflector-redesign branch July 17, 2020 21:08
@clux clux restored the reflector-redesign branch September 16, 2024 21:55
@clux clux deleted the reflector-redesign branch October 2, 2024 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant