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

Commit

Permalink
Update documentation concerning immutable updates (#1884)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Connor Jennings authored and facebook-github-bot committed Oct 4, 2018
1 parent 2ff0c7e commit c336ae2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docs/APIReference-ContentState.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ objects.

> Use [Immutable Map API](http://facebook.github.io/immutable-js/docs/#/Map) to
> set properties.
>
> **Example**
> ```
> const editorState = EditorState.createEmpty();
> const contentState = editorState.getCurrentContent();
> const contentStateWithSelectionBefore = contentState.set('selectionBefore', SelectionState.createEmpty(contentState.getBlockForKey('1pu4d')));
> ```
<ul class="apiIndex">
<li>
Expand Down
9 changes: 8 additions & 1 deletion docs/APIReference-EditorState.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,14 @@ The list below includes the most commonly used instance methods for `EditorState
> Note
>
> Use the static `EditorState` methods to set properties, rather than using
> the Immutable API directly.
> the Immutable API directly. This means using `EditorState.set` to pass
> new options to an EditorState instance.
>
> **Example**
> ```
> const editorState = EditorState.createEmpty();
> const editorStateWithoutUndo = EditorState.set(editorState, {allowUndo: false});
> ```
<ul class="apiIndex">
<li>
Expand Down
7 changes: 7 additions & 0 deletions docs/APIReference-SelectionState.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ _Start_ and _end_ values are derived.

> Use [Immutable Map API](http://facebook.github.io/immutable-js/docs/#/Record/Record) to
> set properties.
>
> **Example**
> ```
> const selectionState = SelectionState.createEmpty();
> const selectionStateWithNewFocusOffset = selection.set('focusOffset', 1);
> ```
<ul class="apiIndex">
<li>
Expand Down

0 comments on commit c336ae2

Please sign in to comment.