-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathstore.js
54 lines (41 loc) · 961 Bytes
/
store.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* Data store, managed by Mobx - https://mobx.js.org
*
* Currently just holds our list of movies.
*/
import { observable, computed, action, decorate } from "mobx";
// import { onError } from "mobx-react"
class MyStore {
constructor() {
this.movielist = [];
}
// a property for count
get count() {
return this.movielist.length;
}
// replace the whole movielist
set_movies(array) {
this.movielist = array || [];
}
// add a single movie
add_movie(obj) {
this.movielist.push(obj);
}
}
// attach mobx to the store
// (not using decorators since they require extra babel)
decorate(MyStore, {
// our data
movielist: observable,
count: computed,
// actions
set_movies: action,
add_movie: action
});
// log mobx errors
// onError(error => {
// console.log(error)
// });
// export singleton store
const store = new MyStore();
export default store;