mirror of
https://github.com/element-hq/element-web
synced 2024-11-27 19:56:47 +03:00
re-hydrate Values which have been serialized into LocalStorage
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
7405c5eff2
commit
59a14f2c0b
1 changed files with 11 additions and 2 deletions
|
@ -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");
|
||||
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 { Store } from 'flux/utils';
|
||||
import { Value } from 'slate';
|
||||
|
||||
const INITIAL_STATE = {
|
||||
// a map of room_id to rich text editor composer state
|
||||
|
@ -65,7 +66,15 @@ class MessageComposerStore extends Store {
|
|||
}
|
||||
|
||||
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() {
|
||||
|
|
Loading…
Reference in a new issue