Repository navigation
Expand file tree
/
Copy pathEditorApi.js
More file actions
64 lines (61 loc) · 1.54 KB
/
Copy pathEditorApi.js
File metadata and controls
64 lines (61 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import stampit from '@stamp/it'
import { createBuffer, openEditorById, selectVisibleBuffers, swapBufferEditors, changeBufferText, changeMetaData, deleteBuffer } from 'store/editorReducer'
import { ANONYMOUS_BUFFER_PREFIX } from 'consts'
let id = 1
function getNextBufferId () {
return ANONYMOUS_BUFFER_PREFIX + '-' + id++
}
let EditorApi = stampit().deepProps({
dispatch: undefined,
getState: undefined
}).methods({
init({dispatch, getState}) {
this.dispatch = dispatch
this.getState = getState
},
createFunctionBuffer(text, metaData) {
let id = getNextBufferId()
this.dispatch(createBuffer({
id,
text
}))
this.dispatch(changeMetaData({
id,
newMetaData: metaData
}))
return id
},
openBuffer(id) {
this.dispatch(openEditorById({
id
}))
},
isBufferVisible(id) {
let visibleBuffers = selectVisibleBuffers(this.getState())
return !!visibleBuffers[id]
},
swapBufferEditors(oldId, newId) {
this.dispatch(swapBufferEditors({
oldId,
newId
}))
},
changeBufferText(id, newText) {
this.dispatch(changeBufferText({
id,
newText
}))
},
changeMetaData(id, newMetaData) {
this.dispatch(changeMetaData({
id,
newMetaData
}))
},
deleteBuffer(id) {
this.dispatch(deleteBuffer({
id
}))
}
})
export default EditorApi