This repository has been archived by the owner on May 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
abstract.js
88 lines (71 loc) · 1.91 KB
/
abstract.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import Dep from '../utils/Dep'
export type PathType = Array<string>
function pass() {
}
// Dep used instead of define/Class to prevent cross-dependencies
@Dep({isClass: true})
export default class AbstractCursor<State> {
__notify: (path: string, isSynced: ?bool) => void = null
_prefix: PathType
constructor(
state: object,
prefix: ?PathType,
notify: ?(path: string, isSynced: ?bool) => void
) {
this._state = state || {}
this._prefix = prefix || []
this.setNotify(notify)
this.commit = ::this.commit
this.get = ::this.get
this.set = ::this.set
this.select = ::this.select
this.apply = ::this.apply
this.assign = ::this.assign
this.toJSON = ::this.toJSON
this.diff = ::this.diff
this.patch = ::this.patch
}
setNotify(notify: (path: string, isSynced: ?bool) => void) {
this.__notify = notify
}
_update(isSynced) {
this.__notify(this._prefix, isSynced)
}
commit() {
this._update(true)
return this
}
select(path: PathType = []): AbstractCursor<State> {
return new this.constructor(
this._state,
this._prefix.concat(path),
this.__notify
)
}
/* eslint-disable no-unused-vars */
toJSON(): string {
throw new Error('implement')
}
snap(): object {
throw new Error('implement')
}
diff(prevState: object): object {
throw new Error('implement')
}
patch(patches: Array) {
throw new Error('implement')
}
get(): State {
throw new Error('implement')
}
set(newState: State) {
throw new Error('implement')
}
apply(fn: (v: State) => State) {
throw new Error('implement')
}
assign(newState: State) {
throw new Error('implement')
}
/* eslint-enable no-unused-vars */
}