static set()

in src/model/immutable/EditorState.js [200:255]


  static set(
    editorState: EditorState,
    put: EditorStateChangeConfigType,
  ): EditorState {
    const map = editorState.getImmutable().withMutations(state => {
      const existingDecorator = state.get('decorator');
      let decorator: ?DraftDecoratorType = existingDecorator;
      if (put.decorator === null) {
        decorator = null;
      } else if (put.decorator) {
        decorator = put.decorator;
      }

      const newContent = put.currentContent || editorState.getCurrentContent();

      if (decorator !== existingDecorator) {
        const treeMap: OrderedMap<string, any> = state.get('treeMap');
        let newTreeMap;
        if (decorator && existingDecorator) {
          newTreeMap = regenerateTreeForNewDecorator(
            newContent,
            newContent.getBlockMap(),
            treeMap,
            decorator,
            existingDecorator,
          );
        } else {
          newTreeMap = generateNewTreeMap(newContent, decorator);
        }

        state.merge({
          decorator,
          treeMap: newTreeMap,
          nativelyRenderedContent: null,
        });
        return;
      }

      const existingContent = editorState.getCurrentContent();
      if (newContent !== existingContent) {
        state.set(
          'treeMap',
          regenerateTreeForNewBlocks(
            editorState,
            newContent.getBlockMap(),
            newContent.getEntityMap(),
            decorator,
          ),
        );
      }

      state.merge(put);
    });

    return new EditorState(map);
  }