aboutsummaryrefslogtreecommitdiffstats
path: root/src/client/JsApi.hx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/JsApi.hx')
-rw-r--r--src/client/JsApi.hx43
1 files changed, 19 insertions, 24 deletions
diff --git a/src/client/JsApi.hx b/src/client/JsApi.hx
index abf9a6a..defcc4d 100644
--- a/src/client/JsApi.hx
+++ b/src/client/JsApi.hx
@@ -16,7 +16,7 @@ class JsApi {
static final subtitleFormats = [];
static final videoChange:Array<VideoChangeFunc> = [];
static final videoRemove:Array<VideoChangeFunc> = [];
- static final onceListeners:Array<{type:WsEventType, func:OnceEventFunc}> = [];
+ static final onceListeners:Array<{type:WsEventType, callback:OnceEventFunc}> = [];
public static function init(main:Main, player:Player):Void {
JsApi.main = main;
@@ -147,52 +147,47 @@ class JsApi {
* `});`
*/
@:expose
- public static function once(type:WsEventType, func:OnceEventFunc):Void {
- onceListeners.push({type: type, func: func});
+ public static function once(type:WsEventType, callback:OnceEventFunc):Void {
+ onceListeners.unshift({type: type, callback: callback});
}
public static function fireOnceEvent(event:WsEvent):Void {
- var i = 0;
- while (i < onceListeners.length) {
- final listener = onceListeners[i];
- if (listener.type == event.type) {
- listener.func(event);
- onceListeners.remove(listener);
- continue;
- }
- i++;
+ for (listener in onceListeners.reversed()) {
+ if (listener.type != event.type) continue;
+ listener.callback(event);
+ onceListeners.remove(listener);
}
}
@:expose
- static function notifyOnVideoChange(func:VideoChangeFunc):Void {
- videoChange.push(func);
+ static function notifyOnVideoChange(callback:VideoChangeFunc):Void {
+ videoChange.push(callback);
}
@:expose
- static function removeFromVideoChange(func:VideoChangeFunc):Void {
- videoChange.remove(func);
+ static function removeFromVideoChange(callback:VideoChangeFunc):Void {
+ videoChange.remove(callback);
}
public static function fireVideoChangeEvents(item:VideoItem):Void {
- for (func in videoChange) {
- func(item);
+ for (callback in videoChange) {
+ callback(item);
}
}
@:expose
- static function notifyOnVideoRemove(func:VideoChangeFunc):Void {
- videoRemove.push(func);
+ static function notifyOnVideoRemove(callback:VideoChangeFunc):Void {
+ videoRemove.push(callback);
}
@:expose
- static function removeFromVideoRemove(func:VideoChangeFunc):Void {
- videoRemove.remove(func);
+ static function removeFromVideoRemove(callback:VideoChangeFunc):Void {
+ videoRemove.remove(callback);
}
public static function fireVideoRemoveEvents(item:VideoItem):Void {
- for (func in videoRemove) {
- func(item);
+ for (callback in videoRemove) {
+ callback(item);
}
}
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage