-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
Todo.js
63 lines (58 loc) · 1.37 KB
/
Todo.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
54
55
56
57
58
59
60
61
62
63
/* This is a mst-sql generated file */
import { addDisposer, onSnapshot, getSnapshot } from "mobx-state-tree"
/* #region type-imports */
import { types } from "mobx-state-tree"
import { MSTGQLObject, MSTGQLRef } from "mst-gql"
import { RootStore } from "./index"
/* #endregion */
/* #region fragments */
export const todoPrimitives = `
__typename
createdAt
done
id
isPublished
title
updatedAt
`
/* #endregion */
/* #region type-def */
/**
* Todo
*/
export const Todo = MSTGQLObject
.named('Todo')
.props({
__typename: types.optional(types.literal("Todo"), "Todo"),
createdAt: types.frozen(),
done: types.boolean,
id: types.identifier,
/** Indicates if the record is published */
isPublished: types.boolean,
title: types.string,
updatedAt: types.frozen(),
})
.views(self => ({
get store() {
return self.__getStore()
}
})) /* #endregion */
.actions(self => ({
// TODO: should these operations (afterAttach, save remove) be standardized into a mixin?
afterAttach() {
addDisposer(self, onSnapshot(self, self.save))
},
save() {
const snapshot = getSnapshot(self)
return self.store.mutateUpdateTodo(snapshot)
},
remove() {
return self.store.mutateDeleteTodo({ id: self.id })
},
toggle() {
self.done = !self.done
},
changeTitle(title) {
self.title = title
}
}))