Skip to content

Commit

Permalink
redux: Store state.narrows as an Immutable.Map, not object-as-map.
Browse files Browse the repository at this point in the history
An instance of zulip#3949 and zulip#3950.

When I wrote the commit message for e834f33, I was most interested
in the exciting new ability to serialize/deserialize custom,
hand-made data types: in particular, ZulipVersion instances.

An important thing that *also* happened in that commit was the new
ability to store data structures from Immutable in Redux, without
any additional setup! `remotedev-serialize` comes with off-the-shelf
support for this. I gave this fact a brief shout-out near the end of
the commit message for a4c29e9.

So, do this, for the first time, paying careful attention to the
instructions in a4c29e9 for writing a migration (copied here, as
that commit message is quite long):

"""
    For making a value "live", where it wasn't before, the migration
    needs to:

    1) As input, take the previous shape of the data. Don't confuse this
    with the *current* way of storing the "dead" shape. Just like any
    other migration, the previous shape is the input.

    2) As output, give the "live" form of the data. Once it's in Redux,
    the replacer will take care of persisting it in the correct "dead"
    form.
"""

The previous shape of the data was an object-as-map, which
`Immutable.Map` takes as input quite cheerfully, and gives us our
"live" Immutable.Map instance.
  • Loading branch information
Chris Bobbe authored and chrisbobbe committed Nov 18, 2020
1 parent 5fb6057 commit a67c782
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 194 deletions.
6 changes: 6 additions & 0 deletions src/boot/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ const migrations: { [string]: (GlobalState) => GlobalState } = {
})),
}),

// Convert `narrows` from object-as-map to `Immutable.Map`.
'16': state => ({
...state,
narrows: Immutable.Map(state.narrows),
}),

// TIP: When adding a migration, consider just using `dropCache`.
};

Expand Down
Loading

0 comments on commit a67c782

Please sign in to comment.