|
1 | | -import { autorun, observable } from 'mobx'; |
| 1 | +import { action, autorun, observable, runInAction } from 'mobx'; |
2 | 2 | import { IS_DEV, IS_TEST } from 'config'; |
3 | 3 | import AppStorage from 'util/appStorage'; |
4 | 4 | import CsvExporter from 'util/csv'; |
@@ -65,30 +65,37 @@ export class Store { |
65 | 65 | /** |
66 | 66 | * load initial data to populate the store |
67 | 67 | */ |
| 68 | + @action.bound |
68 | 69 | async init() { |
69 | 70 | this.settingsStore.init(); |
70 | 71 | await this.authStore.init(); |
71 | | - this.initialized = true; |
| 72 | + runInAction('init', () => { |
| 73 | + this.initialized = true; |
| 74 | + }); |
72 | 75 |
|
73 | 76 | // this function will automatically run whenever the authenticated |
74 | 77 | // flag is changed |
75 | | - autorun(async () => { |
76 | | - if (this.authStore.authenticated) { |
77 | | - // go to the Loop page when the user is authenticated. it can be from |
78 | | - // entering a password or from loading the credentials from storage |
79 | | - this.uiStore.goToLoop(); |
80 | | - // also fetch all the data we need |
81 | | - this.fetchAllData(); |
82 | | - } else { |
83 | | - // go to auth page if we are not authenticated |
84 | | - this.uiStore.gotoAuth(); |
85 | | - } |
86 | | - }); |
| 78 | + autorun( |
| 79 | + async () => { |
| 80 | + if (this.authStore.authenticated) { |
| 81 | + // go to the Loop page when the user is authenticated. it can be from |
| 82 | + // entering a password or from loading the credentials from storage |
| 83 | + this.uiStore.goToLoop(); |
| 84 | + // also fetch all the data we need |
| 85 | + this.fetchAllData(); |
| 86 | + } else { |
| 87 | + // go to auth page if we are not authenticated |
| 88 | + this.uiStore.gotoAuth(); |
| 89 | + } |
| 90 | + }, |
| 91 | + { name: 'authenticatedAutorun' }, |
| 92 | + ); |
87 | 93 | } |
88 | 94 |
|
89 | 95 | /** |
90 | 96 | * makes the initial API calls to fetch the data we need to display in the app |
91 | 97 | */ |
| 98 | + @action.bound |
92 | 99 | async fetchAllData() { |
93 | 100 | await this.nodeStore.fetchInfo(); |
94 | 101 | await this.channelStore.fetchChannels(); |
|
0 commit comments