Skip to content
This repository was archived by the owner on May 31, 2020. It is now read-only.

Commit 78d89ba

Browse files
committed
optimize structure for undo-example
1 parent 2d54161 commit 78d89ba

File tree

4 files changed

+31
-22
lines changed

4 files changed

+31
-22
lines changed

examples/undo-example/src/RedoButton.js renamed to examples/undo-example/src/Undo/components/Redo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type Props = {
88
setEditorState: EditorState => void,
99
}
1010

11-
class RedoButton extends Component<Props> {
11+
class Redo extends Component<Props> {
1212
onClick = event => {
1313
event.stopPropagation()
1414
this.props.setEditorState(EditorState.redo(this.props.editorState))
@@ -29,4 +29,4 @@ class RedoButton extends Component<Props> {
2929
}
3030
}
3131

32-
export default RedoButton
32+
export default Redo

examples/undo-example/src/UndoButton.js renamed to examples/undo-example/src/Undo/components/Undo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type Props = {
88
setEditorState: EditorState => void,
99
}
1010

11-
class UndoButton extends Component<Props> {
11+
class Undo extends Component<Props> {
1212
onClick = event => {
1313
event.stopPropagation()
1414
this.props.setEditorState(EditorState.undo(this.props.editorState))
@@ -29,4 +29,4 @@ class UndoButton extends Component<Props> {
2929
}
3030
}
3131

32-
export default UndoButton
32+
export default Undo
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react'
2+
import { Plugin } from '@djsp/core'
3+
import Redo from './components/Redo'
4+
import Undo from './components/Undo'
5+
6+
const RedoButton = () => (
7+
<Plugin>
8+
{({ editorState, setEditorState }) => (
9+
<Redo editorState={editorState} setEditorState={setEditorState} />
10+
)}
11+
</Plugin>
12+
)
13+
14+
const UndoButton = () => (
15+
<Plugin>
16+
{({ editorState, setEditorState }) => (
17+
<Undo editorState={editorState} setEditorState={setEditorState} />
18+
)}
19+
</Plugin>
20+
)
21+
22+
export { RedoButton, UndoButton }

examples/undo-example/src/index.js

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import React, { Component, Fragment } from 'react'
1+
import React, { Component } from 'react'
22
import ReactDOM from 'react-dom'
33

44
import { EditorState, ContentState } from 'draft-js'
5-
import { EditorContainer, Editor, Plugin } from '@djsp/core'
6-
import UndoButton from './UndoButton.js'
7-
import RedoButton from './RedoButton.js'
5+
import { EditorContainer, Editor } from '@djsp/core'
6+
import { RedoButton, UndoButton } from './Undo'
87
import './styles.css'
98

109
class App extends Component {
@@ -24,20 +23,8 @@ class App extends Component {
2423
<EditorContainer
2524
editorState={this.state.editorState}
2625
onChange={this.onChange}>
27-
<Plugin>
28-
{({ editorState, setEditorState }) => (
29-
<Fragment>
30-
<UndoButton
31-
editorState={editorState}
32-
setEditorState={setEditorState}
33-
/>
34-
<RedoButton
35-
editorState={editorState}
36-
setEditorState={setEditorState}
37-
/>
38-
</Fragment>
39-
)}
40-
</Plugin>
26+
<RedoButton />
27+
<UndoButton />
4128
<Editor />
4229
</EditorContainer>
4330
</div>

0 commit comments

Comments
 (0)