Fix transitions of Microstate Arrays #127
Merged
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.
One of the features of Microstates is the ability to organize data into arrays. When you create an array microstate, you can use special transitions to manipulate this array in immutable way. For example,
create([Number], [1, 2, 3]).push(4)
will return a new array with item 4 added to the end.Previously, we implemented
map
,filter
,push
,pop
and others, but they were not implemented correctly. When you used one of these operations, the created microstate did not have a properly formed data structure. This PR fixes this problem allowing all of the supported transitions to be used.Notable Changes
Removed splice
Previously, splice was used to implement most of the array transitions. This was removed and so was splice. We can re-add it if the need arises.
map microstates
Previously,
map
would call the mapping function with state for each element of the array. This was necessary because there was no easy way to get the state of each individual array item. Unfortunately, this also meant that there was no obvious way to perform microstate transitions inside of map operations. There are several issues effected by this #76 and #75.Fortunately, #113 branch introduced the ability to get state for each composed microstate. This means that we're able to get state inside of map and allow transitions to happen. In this PR, I completed the change to allow performing transitions inside of map.
You can call transitions,
Or you can change the type by returning a new microstate.
added
clear
transitionclear
transition is equivalent to calling.set([])
Closes #125, #75 & #76