@@ -175,25 +175,31 @@ Display elements of `v` inside notification boxes that can be closed with a clos
175
175
The elements are laid out according to `layout`.
176
176
`observe` on this widget returns the observable of the list of elements that have not bein deleted.
177
177
"""
178
- function notifications (:: WidgetTheme , v= []; container = div, wrap = identity,
179
- layout = (v... )-> container ((wrap (el) for el in v). .. ), className = " " )
180
-
178
+ function notifications (:: WidgetTheme , v= []; container = node (:div ),
179
+ wrap = identity,
180
+ layout = (v... )-> container ((wrap (el) for el in v). .. ),
181
+ className = " " )
182
+ scope = Scope ()
181
183
output = Observable {Any} (v)
184
+ to_delete = Observable (scope, " to_delete" , 0 )
185
+ on (to_delete) do ind
186
+ v = output[]
187
+ deleteat! (v, ind)
188
+ output[] = v
189
+ end
182
190
className = mergeclasses (className, " notification" )
183
191
list = map (output) do t
184
192
function create_item (ind, el)
185
- btn = button (className = " delete" )
186
- on (observe (btn)) do x
187
- deleteat! (t, ind)
188
- output[] = output[]
189
- end
190
- div (btn, className = className, el)
193
+ btn = node (:button , className = " delete" , events = Dict (" click" =>
194
+ @js event -> $ to_delete[] = $ ind))
195
+ node (:div , btn, el, className = className)
191
196
end
192
197
[create_item (ind, el) for (ind, el) in enumerate (t)]
193
198
end
194
- scope = Scope ()
195
- slap_design! (scope)
199
+
196
200
scope. dom = map (v -> layout (v... ), list)
201
+ slap_design! (scope)
202
+
197
203
Widget {:notifications} ([:list => list]; output = output, scope = scope,
198
204
layout = _ -> node (:div , scope, className= " interact-widget" ))
199
205
end
0 commit comments