Skip to content

Commit

Permalink
part 08
Browse files Browse the repository at this point in the history
  • Loading branch information
rwieruch committed Sep 1, 2017
1 parent 8714f0a commit 6fb0386
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
7 changes: 3 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './components/App';
import storyStore from './stores/storyStore';
import archiveStore from './stores/archiveStore';
import store from './stores';
import registerServiceWorker from './registerServiceWorker';

ReactDOM.render(
<App
stories={storyStore.stories}
onArchive={(objectID) => archiveStore.archivedStoryIds.push(objectID)}
stories={store.storyStore.readableStories}
onArchive={(objectID) => store.archiveStore.archivedStoryIds.push(objectID)}
/>,
document.getElementById('root')
);
Expand Down
8 changes: 5 additions & 3 deletions src/stores/archiveStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { observable } from 'mobx';

class ArchiveStore {
@observable archivedStoryIds = [];
}

const archiveStore = new ArchiveStore();
constructor(rootStore) {
this.rootStore = rootStore;
}
}

export default archiveStore;
export default ArchiveStore;
13 changes: 13 additions & 0 deletions src/stores/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import StoryStore from './storyStore';
import ArchiveStore from './archiveStore';

class RootStore {
constructor() {
this.storyStore = new StoryStore(this);
this.archiveStore = new ArchiveStore(this);
}
}

const rootStore = new RootStore();

export default rootStore;
18 changes: 14 additions & 4 deletions src/stores/storyStore.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { observable } from 'mobx';
import { observable, computed } from 'mobx';

const INITIAL_STATE = [
{
Expand All @@ -18,10 +18,20 @@ const INITIAL_STATE = [
},
];

const isNotArchived = (archivedStoryIds) => (story) =>
archivedStoryIds.indexOf(story.objectID) === -1;

class StoryStore {
@observable stories = INITIAL_STATE;
}

const storyStore = new StoryStore();
constructor(rootStore) {
this.rootStore = rootStore;
}

@computed get readableStories() {
const { archivedStoryIds } = this.rootStore.archiveStore;
return this.stories.filter(isNotArchived(archivedStoryIds));
}
}

export default storyStore;
export default StoryStore;

0 comments on commit 6fb0386

Please sign in to comment.