re-hydrate Values which have been serialized into LocalStorage

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2018-07-15 20:28:41 +01:00
parent 7405c5eff2
commit 59a14f2c0b
No known key found for this signature in database
GPG key ID: 3F879DA5AD802A5E

View file

@ -1,5 +1,5 @@
/* /*
Copyright 2017 Vector Creations Ltd Copyright 2017, 2018 Vector Creations Ltd
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -15,6 +15,7 @@ limitations under the License.
*/ */
import dis from '../dispatcher'; import dis from '../dispatcher';
import { Store } from 'flux/utils'; import { Store } from 'flux/utils';
import { Value } from 'slate';
const INITIAL_STATE = { const INITIAL_STATE = {
// a map of room_id to rich text editor composer state // a map of room_id to rich text editor composer state
@ -65,7 +66,15 @@ class MessageComposerStore extends Store {
} }
getEditorState(roomId) { getEditorState(roomId) {
return this._state.editorStateMap[roomId]; const editorStateMap = this._state.editorStateMap;
// const entry = this._state.editorStateMap[roomId];
if (editorStateMap[roomId] && !Value.isValue(editorStateMap[roomId].editor_state)) {
// rehydrate lazily to prevent massive churn at launch and cache it
editorStateMap[roomId].editor_state = Value.fromJSON(editorStateMap[roomId].editor_state);
}
// explicitly don't setState here because the value didn't actually change, we just hydrated it,
// if a listener received an update they too would call this method and have a hydrated Value
return editorStateMap[roomId];
} }
reset() { reset() {