Skip to content
This repository was archived by the owner on Feb 6, 2023. It is now read-only.

Commit c336ae2

Browse files
Connor Jenningsfacebook-github-bot
authored andcommitted
Update documentation concerning immutable updates (#1884)
Summary: **Summary** Adding some inline examples in the documentation around immutable updates for `EditorState`, `ContentState` and `SelectionState` based on the suggestions of #1445. Let me know if there's more areas in the documentation that could use similar examples or if some editing needs to be done to what I've added. **Test Plan** N/A, but I did view in online markdown editor and it looks ok Pull Request resolved: #1884 Differential Revision: D10188040 fbshipit-source-id: c91d935d3ffdb7aee9ccf826af68c91cf1596a0a
1 parent 2ff0c7e commit c336ae2

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

docs/APIReference-ContentState.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ objects.
142142

143143
> Use [Immutable Map API](http://facebook.github.io/immutable-js/docs/#/Map) to
144144
> set properties.
145+
>
146+
> **Example**
147+
> ```
148+
> const editorState = EditorState.createEmpty();
149+
> const contentState = editorState.getCurrentContent();
150+
> const contentStateWithSelectionBefore = contentState.set('selectionBefore', SelectionState.createEmpty(contentState.getBlockForKey('1pu4d')));
151+
> ```
145152
146153
<ul class="apiIndex">
147154
<li>

docs/APIReference-EditorState.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,14 @@ The list below includes the most commonly used instance methods for `EditorState
118118
> Note
119119
>
120120
> Use the static `EditorState` methods to set properties, rather than using
121-
> the Immutable API directly.
121+
> the Immutable API directly. This means using `EditorState.set` to pass
122+
> new options to an EditorState instance.
123+
>
124+
> **Example**
125+
> ```
126+
> const editorState = EditorState.createEmpty();
127+
> const editorStateWithoutUndo = EditorState.set(editorState, {allowUndo: false});
128+
> ```
122129
123130
<ul class="apiIndex">
124131
<li>

docs/APIReference-SelectionState.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ _Start_ and _end_ values are derived.
141141

142142
> Use [Immutable Map API](http://facebook.github.io/immutable-js/docs/#/Record/Record) to
143143
> set properties.
144+
>
145+
> **Example**
146+
> ```
147+
> const selectionState = SelectionState.createEmpty();
148+
> const selectionStateWithNewFocusOffset = selection.set('focusOffset', 1);
149+
> ```
150+
144151
145152
<ul class="apiIndex">
146153
<li>

0 commit comments

Comments
 (0)