Skip to content

Commit 9e11337

Browse files
committed
add an update method to documents and pass it to device store
1 parent 8eef5e9 commit 9e11337

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

plugins/editor/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ function editor(app, opts, done){
109109

110110
keyExtension.setup(app);
111111
editorStore.cm = codeEditor;
112-
fileStore.documents = new DocumentsStore(codeEditor);
113-
deviceStore.cm = codeEditor;
112+
const documents = new DocumentsStore(codeEditor);
113+
fileStore.documents = documents;
114+
deviceStore.documents = documents;
114115
}
115116

116117

src/stores/device.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class DeviceStore {
7676

7777
onUpdateSelected(device) {
7878

79-
const { workspace, cm } = this.getInstance();
79+
const { workspace, documents } = this.getInstance();
8080
const { noneMatched } = this.messages;
8181

8282
if(this.state.message === noneMatched) {
@@ -88,12 +88,10 @@ class DeviceStore {
8888

8989
const pre = source.substring(0, TargetStart);
9090
const post = source.substring(end, source.length);
91-
const newsource = pre + name + post;
92-
93-
//TODO: action -> action dispatch error
94-
//editor should be set with new source
95-
cm.getDoc().setValue(newsource);
91+
const newSource = pre + name + post;
9692

93+
documents.update(newSource);
94+
workspace.updateContent(newSource);
9795
}
9896

9997
this.setState({

src/stores/documents.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,22 @@ class DocumentsStore {
88
constructor(editor){
99
this._editor = editor;
1010

11+
this._filename = null;
1112
this._documents = {};
1213
}
1314

1415
focus(){
1516
this._editor.focus();
1617
}
1718

19+
update(text){
20+
if(!this._filename){
21+
return;
22+
}
23+
24+
return this.create(this._filename, text);
25+
}
26+
1827
create(filename, text){
1928
const mode = 'pbasic';
2029

@@ -24,6 +33,8 @@ class DocumentsStore {
2433
}
2534

2635
swap(filename) {
36+
this._filename = filename;
37+
2738
const doc = this._documents[filename];
2839

2940
if(!doc){

0 commit comments

Comments
 (0)