History

js: use new hooks API (match f60826c3)

Avi Halachmi (:avih) committed 8 years ago

Commit ec625261 parent 84aa9e72 files · +50 −10Browse files

Showing the changes to player/javascript (1 of 2 files). Show all

Unified · Split

player/javascript/defaults.js+8−10
@@ -123,22 +123,19 @@ function dispatch_message(ev) { · 122 unmodified lines
123123 }
124124
125125 // ----- hooks -----
126−var next_hid = 1,
127− hooks = new_cache(); // items of id: fn
126+var hooks = []; // array of callbacks, id is index+1
128127
129−function hook_run(id, cont) {
130− var cb = hooks[id];
128+function run_hook(ev) {
129+ var cb = ev.id > 0 && hooks[ev.id - 1];
131130 if (cb)
132131 cb();
133− mp.commandv("hook-ack", cont);
132+ mp._hook_continue(ev.hook_id);
134133 }
135134
136135 mp.add_hook = function add_hook(name, pri, fn) {
137− if (next_hid == 1) // doesn't really matter if we do it once or always
138− mp.register_script_message("hook_run", hook_run);
139− var id = next_hid++;
140− hooks[id] = fn;
141− return mp.commandv("hook-add", name, id, pri);
136+ hooks.push(fn);
137+ // 50 (scripting docs default priority) maps to 0 (default in C API docs)
138+ return mp._hook_add(name, pri - 50, hooks.length);
142139 }
143140
144141 /**********************************************************************
@@ -559,6 +556,7 @@ mp.keep_running = true; · 414 unmodified lines
559556 g.exit = function() { mp.keep_running = false }; // user-facing too
560557 mp.register_event("shutdown", g.exit);
561558 mp.register_event("property-change", notify_observer);
559+mp.register_event("hook", run_hook);
562560 mp.register_event("client-message", dispatch_message);
563561 mp.register_script_message("key-binding", dispatch_key_binding);
564562

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t