@@ -2,7 +2,7 @@ local M = {}
2
2
3
3
local global_handlers = {}
4
4
5
- local Event = {
5
+ M . Event = {
6
6
Ready = " Ready" ,
7
7
NodeRenamed = " NodeRenamed" ,
8
8
TreeOpen = " TreeOpen" ,
@@ -18,7 +18,7 @@ local function get_handlers(event_name)
18
18
return global_handlers [event_name ] or {}
19
19
end
20
20
21
- local function register_handler (event_name , handler )
21
+ function M . subscribe (event_name , handler )
22
22
local handlers = get_handlers (event_name )
23
23
table.insert (handlers , handler )
24
24
global_handlers [event_name ] = handlers
@@ -35,107 +35,107 @@ end
35
35
36
36
-- @private
37
37
function M ._dispatch_ready ()
38
- dispatch (Event .Ready )
38
+ dispatch (M . Event .Ready )
39
39
end
40
40
41
41
-- @private
42
42
function M ._dispatch_node_renamed (old_name , new_name )
43
- dispatch (Event .NodeRenamed , { old_name = old_name , new_name = new_name })
43
+ dispatch (M . Event .NodeRenamed , { old_name = old_name , new_name = new_name })
44
44
end
45
45
46
46
-- @private
47
47
function M ._dispatch_file_removed (fname )
48
- dispatch (Event .FileRemoved , { fname = fname })
48
+ dispatch (M . Event .FileRemoved , { fname = fname })
49
49
end
50
50
51
51
-- @private
52
52
function M ._dispatch_file_created (fname )
53
- dispatch (Event .FileCreated , { fname = fname })
53
+ dispatch (M . Event .FileCreated , { fname = fname })
54
54
end
55
55
56
56
-- @private
57
57
function M ._dispatch_folder_created (folder_name )
58
- dispatch (Event .FolderCreated , { folder_name = folder_name })
58
+ dispatch (M . Event .FolderCreated , { folder_name = folder_name })
59
59
end
60
60
61
61
-- @private
62
62
function M ._dispatch_folder_removed (folder_name )
63
- dispatch (Event .FolderRemoved , { folder_name = folder_name })
63
+ dispatch (M . Event .FolderRemoved , { folder_name = folder_name })
64
64
end
65
65
66
66
-- @private
67
67
function M ._dispatch_on_tree_open ()
68
- dispatch (Event .TreeOpen , nil )
68
+ dispatch (M . Event .TreeOpen , nil )
69
69
end
70
70
71
71
-- @private
72
72
function M ._dispatch_on_tree_close ()
73
- dispatch (Event .TreeClose , nil )
73
+ dispatch (M . Event .TreeClose , nil )
74
74
end
75
75
76
76
-- @private
77
77
function M ._dispatch_on_tree_resize (size )
78
- dispatch (Event .Resize , size )
78
+ dispatch (M . Event .Resize , size )
79
79
end
80
80
81
81
-- Registers a handler for the Ready event.
82
82
-- @param handler (function) Handler with the signature `function()`
83
83
function M .on_nvim_tree_ready (handler )
84
- register_handler ( Event .Ready , handler )
84
+ M . subscribe ( M . Event .Ready , handler )
85
85
end
86
86
87
87
-- Registers a handler for the NodeRenamed event.
88
88
-- @param handler (function) Handler with the signature function(payload), where payload is a table containing:
89
89
-- - old_name (string) Absolute path to the old node location.
90
90
-- - new_name (string) Absolute path to the new node location.
91
91
function M .on_node_renamed (handler )
92
- register_handler ( Event .NodeRenamed , handler )
92
+ M . subscribe ( M . Event .NodeRenamed , handler )
93
93
end
94
94
95
95
-- Registers a handler for the FileCreated event.
96
96
-- @param handler (function) Handler with the signature function(payload), where payload is a table containing:
97
97
-- - fname (string) Absolute path to the created file.
98
98
function M .on_file_created (handler )
99
- register_handler ( Event .FileCreated , handler )
99
+ M . subscribe ( M . Event .FileCreated , handler )
100
100
end
101
101
102
102
-- Registers a handler for the FileRemoved event.
103
103
-- @param handler (function) Handler with the signature function(payload), where payload is a table containing:
104
104
-- - fname (string) Absolute path to the removed file.
105
105
function M .on_file_removed (handler )
106
- register_handler ( Event .FileRemoved , handler )
106
+ M . subscribe ( M . Event .FileRemoved , handler )
107
107
end
108
108
109
109
-- Registers a handler for the FolderCreated event.
110
110
-- @param handler (function) Handler with the signature function(payload), where payload is a table containing:
111
111
-- - folder_name (string) Absolute path to the created folder.
112
112
function M .on_folder_created (handler )
113
- register_handler ( Event .FolderCreated , handler )
113
+ M . subscribe ( M . Event .FolderCreated , handler )
114
114
end
115
115
116
116
-- Registers a handler for the FolderRemoved event.
117
117
-- @param handler (function) Handler with the signature function(payload), where payload is a table containing:
118
118
-- - folder_name (string) Absolute path to the removed folder.
119
119
function M .on_folder_removed (handler )
120
- register_handler ( Event .FolderRemoved , handler )
120
+ M . subscribe ( M . Event .FolderRemoved , handler )
121
121
end
122
122
123
123
-- Registers a handler for the TreeOpen event.
124
124
-- @param handler (function) Handler with the signature function(payload)
125
125
function M .on_tree_open (handler )
126
- register_handler ( Event .TreeOpen , handler )
126
+ M . subscribe ( M . Event .TreeOpen , handler )
127
127
end
128
128
129
129
-- Registers a handler for the TreeClose event.
130
130
-- @param handler (function) Handler with the signature function(payload)
131
131
function M .on_tree_close (handler )
132
- register_handler ( Event .TreeClose , handler )
132
+ M . subscribe ( M . Event .TreeClose , handler )
133
133
end
134
134
135
135
-- Registers a handler for the Resize event.
136
136
-- @param handler (function) Handler with the signature function(size)
137
137
function M .on_tree_resize (handler )
138
- register_handler ( Event .Resize , handler )
138
+ M . subscribe ( M . Event .Resize , handler )
139
139
end
140
140
141
141
return M
0 commit comments