-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnotifier.lua
75 lines (49 loc) · 1.33 KB
/
notifier.lua
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
#! /usr/bin/env lua
--
-- notifier.lua
-- Copyright (C) 2021 Shewer Lu <[email protected]>
--
-- Distributed under terms of the MIT license.
--
-- for librime-lua notifier
--
require 'tools/object'
Notifier=Class("Notifier")
function Notifier:_initialize(env)
self._env=env
self._list=metatable()
return self
end
function Notifier:_connect(name,func)
local connection= self._env.engine.context[name]:connect(func)
self._list:insert(connection)
return connection
end
function Notifier:disconnect()
for i,connection in next , self._list do
connection:disconnect()
self._list[i] = nil
end
end
function Notifier:commit(func) -- func(ctx)
return self:_connect("commit_notifier",func)
end
function Notifier:select(func) -- func(ctx)
return self:_connect("select_notifier",func)
end
function Notifier:update(func) -- func(ctx)
return self:_connect("update_notifier",func)
end
function Notifier:delete(func) -- func(ctx)
return self:_connect("delete_notifier",func)
end
function Notifier:option(func) -- func(ctx,name)
return self:_connect("option_update_notifier",func)
end
function Notifier:property(func) -- func(ctx,name)
return self:_connect("property_update_notifier",func)
end
function Notifier:unhandled_key(func) -- func(ctx)
return self:_connect("unhandled_key_notifier",func)
end
return Notifier