File tree 4 files changed +35
-11
lines changed
4 files changed +35
-11
lines changed Original file line number Diff line number Diff line change @@ -2,14 +2,13 @@ import React from 'react';
2
2
import ReactDOM from 'react-dom' ;
3
3
import './index.css' ;
4
4
import App from './components/App' ;
5
- import storyStore from './stores/storyStore' ;
6
- import archiveStore from './stores/archiveStore' ;
5
+ import store from './stores' ;
7
6
import registerServiceWorker from './registerServiceWorker' ;
8
7
9
8
ReactDOM . render (
10
9
< App
11
- stories = { storyStore . stories }
12
- onArchive = { ( objectID ) => archiveStore . archivedStoryIds . push ( objectID ) }
10
+ stories = { store . storyStore . readableStories }
11
+ onArchive = { ( objectID ) => store . archiveStore . archivedStoryIds . push ( objectID ) }
13
12
/> ,
14
13
document . getElementById ( 'root' )
15
14
) ;
Original file line number Diff line number Diff line change @@ -2,8 +2,10 @@ import { observable } from 'mobx';
2
2
3
3
class ArchiveStore {
4
4
@observable archivedStoryIds = [ ] ;
5
- }
6
5
7
- const archiveStore = new ArchiveStore ( ) ;
6
+ constructor ( rootStore ) {
7
+ this . rootStore = rootStore ;
8
+ }
9
+ }
8
10
9
- export default archiveStore ;
11
+ export default ArchiveStore ;
Original file line number Diff line number Diff line change
1
+ import StoryStore from './storyStore' ;
2
+ import ArchiveStore from './archiveStore' ;
3
+
4
+ class RootStore {
5
+ constructor ( ) {
6
+ this . storyStore = new StoryStore ( this ) ;
7
+ this . archiveStore = new ArchiveStore ( this ) ;
8
+ }
9
+ }
10
+
11
+ const rootStore = new RootStore ( ) ;
12
+
13
+ export default rootStore ;
Original file line number Diff line number Diff line change 1
- import { observable } from 'mobx' ;
1
+ import { observable , computed } from 'mobx' ;
2
2
3
3
const INITIAL_STATE = [
4
4
{
@@ -18,10 +18,20 @@ const INITIAL_STATE = [
18
18
} ,
19
19
] ;
20
20
21
+ const isNotArchived = ( archivedStoryIds ) => ( story ) =>
22
+ archivedStoryIds . indexOf ( story . objectID ) === - 1 ;
23
+
21
24
class StoryStore {
22
25
@observable stories = INITIAL_STATE ;
23
- }
24
26
25
- const storyStore = new StoryStore ( ) ;
27
+ constructor ( rootStore ) {
28
+ this . rootStore = rootStore ;
29
+ }
30
+
31
+ @computed get readableStories ( ) {
32
+ const { archivedStoryIds } = this . rootStore . archiveStore ;
33
+ return this . stories . filter ( isNotArchived ( archivedStoryIds ) ) ;
34
+ }
35
+ }
26
36
27
- export default storyStore ;
37
+ export default StoryStore ;
You can’t perform that action at this time.
0 commit comments