1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-01-19 14:27:07 +01:00
slate/docs/concepts/statelessness-and-immutability.md
Ian Storm Taylor 351c05785e update docsg
2016-07-13 17:04:23 -07:00

1.6 KiB

Statelessness & Immutability

All of the data in Slate is immutable, thanks to Immutable.js. This makes it much easier to reason about complex editing logic, and it makes maintaining a history of changes for undo/redo much simpler.

To learn more, check out the State model reference.

The onChange Handler

Because of Slate's immutability, you don't actually "set" itself a new state when something changes.

Instead, the new state is propagated to the Slate editor's parent component, who decides what to do with it. Usually, you'll simply give the new state right back to the editor via React's this.setState() method, similarly to other internal component state. But that's up to you!

To learn more, check out the <Editor> component reference.

Transforms

All of the changes in Slate are applied via Transforms. This makes it possible to enforce some of the constraints that Slate needs to enforce, like requiring that all leaf nodes be text nodes. This also makes it possible to implement collaborative editing, where information about changes must be serialized and sent over the network to other editors.

You should never update the selection or document of an editor other than by using the transform() method of a State.

To learn more, check out the Transform model reference.