Always create a new instance of DocumentScene's store

This commit is contained in:
Jori Lallo
2016-07-06 22:04:31 -07:00
parent e3d21ba882
commit f7092e7665
2 changed files with 28 additions and 17 deletions

View File

@@ -1,9 +1,9 @@
import _isEqual from 'lodash/isEqual';
import { observable, action, computed } from 'mobx';
import { observable, action, computed, runInAction } from 'mobx';
import { client } from 'utils/ApiClient';
import { browserHistory } from 'react-router';
const store = new class DocumentSceneStore {
class DocumentSceneStore {
@observable document;
@observable isFetching = true;
@@ -25,7 +25,9 @@ const store = new class DocumentSceneStore {
try {
const res = await client.post('/documents.info', { id: id });
const { data } = res;
this.document = data;
runInAction('fetchDocument', () => {
this.document = data;
});
} catch (e) {
console.error("Something went wrong");
}
@@ -57,13 +59,15 @@ const store = new class DocumentSceneStore {
id: this.document.atlas.id,
tree: tree,
});
const { data } = res;
this.document.atlas = data;
runInAction('updateNavigationTree', () => {
const { data } = res;
this.document.atlas = data;
});
} catch (e) {
console.error("Something went wrong");
}
this.isFetching = false;
}
}();
};
export default store;
export default DocumentSceneStore;