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 Jul 20, 2020
1 parent 3554e2c commit 1a80243
Show file tree
Hide file tree
Showing 11 changed files with 271 additions and 212 deletions.
6 changes: 6 additions & 0 deletions src/boot/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ const migrations: { [string]: (GlobalState) => GlobalState } = {
typeof a.zulipVersion === 'string' ? new ZulipVersion(a.zulipVersion) : a.zulipVersion,
})),
}),

// narrows is now an Immutable.Map, not an object-as-map
'14': state => ({
...state,
narrows: Immutable.Map(state.narrows),
}),
};

/**
Expand Down
Loading

0 comments on commit 1a80243

Please sign in to comment.