-
Notifications
You must be signed in to change notification settings - Fork 21
/
core.cljs
106 lines (80 loc) · 3.48 KB
/
core.cljs
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
(ns citrus.core
(:require [citrus.reconciler :as r]
[citrus.cursor :as c]))
(defn reconciler
"Creates an instance of Reconciler
(citrus/reconciler {:state (atom {})
:controllers {:counter counter/control}
:effect-handlers {:http effects/http}
:batched-updates {:schedule-fn f :release-fn f'}
:chunked-updates f})
Arguments
config - a map of
state - app state atom
controllers - a hash of state controllers
effect-handlers - a hash of effects handlers
batched-updates - a hash of two functions used to batch reconciler updates, defaults to
`{:schedule-fn js/requestAnimationFrame :release-fn js/cancelAnimationFrame}`
chunked-updates - a function used to divide reconciler update into chunks, doesn't used by default
Returned value supports deref, watches and metadata.
The only supported option is `:meta`"
[{:keys [state controllers effect-handlers co-effects batched-updates chunked-updates]} & {:as options}]
(r/Reconciler.
controllers
effect-handlers
co-effects
state
(volatile! [])
(volatile! nil)
(or batched-updates {:schedule-fn js/requestAnimationFrame :release-fn js/cancelAnimationFrame})
chunked-updates
(:meta options)))
(defn dispatch!
"Invoke an event on particular controller asynchronously
(citrus/dispatch! reconciler :users :load \"id\")
Arguments
reconciler - an instance of Reconciler
controller - name of a controller
event - a dispatch value of a method defined in the controller
args - arguments to be passed into the controller"
[reconciler controller event & args]
(r/dispatch! reconciler controller event args))
(defn dispatch-sync!
"Invoke an event on particular controller synchronously
(citrus/dispatch! reconciler :users :load \"id\")
Arguments
reconciler - an instance of Reconciler
controller - name of a controller
event - a dispatch value of a method defined in the controller
args - arguments to be passed into the controller"
[reconciler controller event & args]
(r/dispatch-sync! reconciler controller event args))
(defn broadcast!
"Invoke an event on all controllers asynchronously
(citrus/broadcast! reconciler :init)
Arguments
reconciler - an instance of Reconciler
event - a dispatch value of a method defined in the controller
args - arguments to be passed into the controller"
[reconciler event & args]
(r/broadcast! reconciler event args))
(defn broadcast-sync!
"Invoke an event on all controllers synchronously
(citrus/broadcast! reconciler :init)
Arguments
reconciler - an instance of Reconciler
event - a dispatch value of a method defined in the controller
args - arguments to be passed into the controller"
[reconciler event & args]
(r/broadcast-sync! reconciler event args))
(defn subscription
"Create a subscription to state updates
(citrus/subscription reconciler [:users 0] (juxt [:fname :lname]))
Arguments
reconciler - an instance of Reconciler
path - a vector which describes a path into reconciler's atom value
reducer - an aggregate function which computes a materialized view of data behind the path"
([reconciler path]
(subscription reconciler path identity))
([reconciler path reducer]
(c/reduce-cursor-in reconciler path reducer)))