-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdeferAggregator.coffee
50 lines (40 loc) · 1.18 KB
/
deferAggregator.coffee
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
define [
'cord!errors'
'cord!utils/Future'
'asap/raw'
'underscore'
], (errors, Future, asap, _) ->
class DeferAggregator
defers: {}
setWidgetParams: (widget, params) ->
id = widget.ctx.id
if @defers[id]?
df = @defers[id]
_.extend(df.params, params)
for key, value of params
if value == ':deferred'
if not df.deferredParams[key]?
df.promise.fork()
df.deferredParams[key] = true
else if df.deferredParams[key]?
df.promise.resolve()
df.deferredParams[key] = null
else
df =
params: params
promise: (new Future('deferAgregator')).fork()
deferredParams: {}
@defers[id] = df
for key, value of params
if value == ':deferred'
df.deferredParams[key] = true
df.promise.fork()
asap ->
df.promise.resolve()
df.promise.then =>
widget.setParamsSafe(df.params).catchIf (err) ->
err instanceof errors.WidgetParamsRace
.failAloud(widget.debug('DeferAggregator'))
delete @defers[id]
return
new DeferAggregator