Skip to content

Commit 6fb0386

Browse files
committed
part 08
1 parent 8714f0a commit 6fb0386

File tree

4 files changed

+35
-11
lines changed

4 files changed

+35
-11
lines changed

src/index.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@ import React from 'react';
22
import ReactDOM from 'react-dom';
33
import './index.css';
44
import App from './components/App';
5-
import storyStore from './stores/storyStore';
6-
import archiveStore from './stores/archiveStore';
5+
import store from './stores';
76
import registerServiceWorker from './registerServiceWorker';
87

98
ReactDOM.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
);

src/stores/archiveStore.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import { observable } from 'mobx';
22

33
class 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;

src/stores/index.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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;

src/stores/storyStore.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { observable } from 'mobx';
1+
import { observable, computed } from 'mobx';
22

33
const 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+
2124
class 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;

0 commit comments

Comments
 (0)