extract notify-listeners and listen to functions
This commit is contained in:
parent
26dfaeb152
commit
8679518ca3
@ -17,27 +17,31 @@
|
|||||||
(.. cache-dir "/cookies.db")
|
(.. cache-dir "/cookies.db")
|
||||||
WebKit2.CookiePersistentStorage.SQLITE))
|
WebKit2.CookiePersistentStorage.SQLITE))
|
||||||
|
|
||||||
|
(fn notify-listeners [listeners name value]
|
||||||
|
(let [funs (. listeners name)]
|
||||||
|
(when funs
|
||||||
|
(each [_ f (ipairs funs)]
|
||||||
|
(f value)))))
|
||||||
|
|
||||||
|
(fn add-listener [listeners event-name fun]
|
||||||
|
(let [funs (or (. listeners event-name) [])]
|
||||||
|
(table.insert funs fun)
|
||||||
|
(tset listeners event-name funs)))
|
||||||
|
|
||||||
(local
|
(local
|
||||||
Webview
|
Webview
|
||||||
{
|
{
|
||||||
:new
|
:new
|
||||||
#(let [listeners {}
|
#(let [listeners {}
|
||||||
notify-listeners (fn [self pspec]
|
|
||||||
(let [n pspec.name
|
|
||||||
funs (. listeners n)]
|
|
||||||
(when funs
|
|
||||||
(each [_ f (ipairs funs)]
|
|
||||||
(f (. self n))))))
|
|
||||||
widget (WebKit2.WebView {
|
widget (WebKit2.WebView {
|
||||||
:on_notify
|
:on_notify
|
||||||
#(notify-listeners $1 $2)
|
(fn [self pspec]
|
||||||
|
(when (not (= pspec.name :parent))
|
||||||
|
(notify-listeners listeners pspec.name (. self pspec.name))))
|
||||||
})]
|
})]
|
||||||
;;(load-adblocks webview.user_content_manager content-filter-store)
|
;;(load-adblocks webview.user_content_manager content-filter-store)
|
||||||
{
|
{
|
||||||
:listen (fn [self event-name fun]
|
:listen #(add-listener listeners $2 $3)
|
||||||
(let [funs (or (. listeners event-name) [])]
|
|
||||||
(table.insert funs fun)
|
|
||||||
(tset listeners event-name funs)))
|
|
||||||
:visit (fn [self url]
|
:visit (fn [self url]
|
||||||
(widget:load_uri url))
|
(widget:load_uri url))
|
||||||
:stop-loading #(widget:stop_loading)
|
:stop-loading #(widget:stop_loading)
|
||||||
|
Loading…
Reference in New Issue
Block a user