Closed
Conversation
added 4 commits
July 7, 2019 19:19
…d overwrite parameter in listeners
…r ; corrected missunderstood tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
A Mutation system for Unistore.
Introduction
Why : I wanted to bind a listener to the store to synchronise every state change online. As for today, we only retrieve updated state and the update that triggered this.
Now here lies the problem, when we use a list of elements, that update contains the entire list of elements; So sending this trough was not really a good idea.
What : I needed to retrieve only the few parameters that were actually added to the store. Hence, the easiest way to achieve this was to change the actions so they don't return the update, but rather which mutation it should call and it's parameters.
So what changed to be short ?
Listeners receive a "mutation command" rather than the full update
They are in the form
The first key of the object is used a a mutation key, while it's data is used as args. Every other key is
used as an additional parameter to pass trough to the listeners.
Mutations are in the form
Oh boy you want to break all of our apps ?
Mutation is an optional paradigm that is enabled only if a mutation parameter is sent to createStore.
Even if mutations are passed to the store, setState should work as intended as it received no change.
Unfortunately mutation usage is rather radical since any action return would then be considered as a mutation ; .setState can still be used to make a direct change in the store.
A new mutate function is also available, it can only work if a mutation object is passed to the store.
Cost
full/preact.js : 760b to 818b = 58b
full/unistore.js : 400b to 412b = 12b
Total : 70b
Example
Before
Output
After
Output