substance / substance

A JavaScript library for web-based content editing.

Home Page:https://substance.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EditorSession State API

obuchtala opened this issue · comments

Introduction

When developing Substance applications it is often necessary to store volatile, not persisted information along with nodes. These updates should behave similar as real document changes with respect to the EditorSession update flow.

For model changes editorSession.transaction() is used that records all changes, and applies them as a batch to the model, analyzing the change marking resources (paths) as dirty, and triggering listeners in an efficient way.

A similar approach is desired for state changes, however, this should not be mixed with model updates to avoid an inconsistency in how the changes are treated and persisted.

Lately we have been experimenting with using stub changes and marking nodes as dirty to leverage EditorSessions existing update mechanism. This plays well with EditorSession flows and how listeners get triggered.

Proposal:

editorSession.updateState((state) => {
  state.get(path)
  state.set(path, values)
  state.extend(path, values)  
})
  • similar to editorSession.transaction((tx) => {})
  • similar observation mechanism:
    editorSession.onRender('state', this._onStateChange, this, { path: [this.props.node.id]})
    

Obsolete.