File tree Expand file tree Collapse file tree 4 files changed +35
-11
lines changed Expand file tree Collapse file tree 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';
22import ReactDOM from 'react-dom' ;
33import './index.css' ;
44import App from './components/App' ;
5- import storyStore from './stores/storyStore' ;
6- import archiveStore from './stores/archiveStore' ;
5+ import store from './stores' ;
76import registerServiceWorker from './registerServiceWorker' ;
87
98ReactDOM . render (
109 < 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 ) }
1312 /> ,
1413 document . getElementById ( 'root' )
1514) ;
Original file line number Diff line number Diff line change @@ -2,8 +2,10 @@ import { observable } from 'mobx';
22
33class ArchiveStore {
44 @observable archivedStoryIds = [ ] ;
5- }
65
7- const archiveStore = new ArchiveStore ( ) ;
6+ constructor ( rootStore ) {
7+ this . rootStore = rootStore ;
8+ }
9+ }
810
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' ;
22
33const INITIAL_STATE = [
44 {
@@ -18,10 +18,20 @@ const INITIAL_STATE = [
1818 } ,
1919] ;
2020
21+ const isNotArchived = ( archivedStoryIds ) => ( story ) =>
22+ archivedStoryIds . indexOf ( story . objectID ) === - 1 ;
23+
2124class StoryStore {
2225 @observable stories = INITIAL_STATE ;
23- }
2426
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+ }
2636
27- export default storyStore ;
37+ export default StoryStore ;
You can’t perform that action at this time.
0 commit comments