Skip to content

Commit 1b9a1df

Browse files
author
Zaydek Michels-Gualtieri
committed
Added basic virtual DOM
1 parent 30e993d commit 1b9a1df

File tree

2 files changed

+44
-10
lines changed

2 files changed

+44
-10
lines changed

src/Editor/Editor.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,23 @@ const Editor = ({
298298
)
299299
}
300300

301-
export default Editor
301+
const tabSize = n => ({
302+
MozTabSize: n,
303+
tabSize: n,
304+
})
305+
306+
const EditorWithDebugger = ({ state, dispatch }) => (
307+
<>
308+
<Editor
309+
state={state}
310+
dispatch={dispatch}
311+
/>
312+
{process.env.NODE_ENV !== "production" && (
313+
<pre className="mt-6 text-xs whitespace-pre-wrap break-words" style={tabSize(2)}>
314+
{JSON.stringify(state, null, "\t")}
315+
</pre>
316+
)}
317+
</>
318+
)
319+
320+
export default EditorWithDebugger

src/Editor/useEditor.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,40 @@
11
import { useImmerReducer } from "use-immer"
22

33
const createInitialState = initialValueMarkdown => ({
4-
// ...
4+
readOnlyMode: false,
5+
6+
focused: false,
7+
content: [],
8+
cursors: {
9+
start: {
10+
key: "",
11+
offset: 0,
12+
},
13+
end: {
14+
key: "",
15+
offset: 0,
16+
},
17+
},
18+
19+
shouldRerender: 0,
520
})
621

722
const actions = state => ({
8-
a() {
9-
23+
focus() {
24+
state.focused = true
1025
},
11-
b() {
12-
26+
blur() {
27+
state.focused = false
1328
},
1429
})
1530

1631
function EditorReducer(state, action) {
1732
switch (action.type) {
18-
case "A":
19-
actions(state).a()
33+
case "FOCUS":
34+
actions(state).focus()
2035
return
21-
case "B":
22-
actions(state).a()
36+
case "BLUR":
37+
actions(state).blur()
2338
return
2439
default:
2540
throw new Error(`EditorReducer: type mismatch; action.type=${action.type}`)

0 commit comments

Comments
 (0)