Index: ext/common.js |
=================================================================== |
--- a/ext/common.js |
+++ b/ext/common.js |
@@ -74,4 +74,42 @@ |
window.removeEventListener("message", listener._extWrapper, false); |
} |
}; |
+ |
+ class Port |
saroyanm
2018/03/12 13:08:28
I like that we have started to use javascript clas
a.giammarchi
2018/03/12 13:17:31
FWIW, when needed, I prefer classes too and I thin
Thomas Greiner
2018/03/13 18:24:45
Yes, this is just a mock. We're still supporting O
a.giammarchi
2018/03/14 07:51:03
AFAIK Opera 36 already supports Classes, but it's
|
+ { |
+ constructor(name) |
+ { |
+ this._name = name; |
+ } |
+ |
+ get name() |
+ { |
+ return this._name; |
+ } |
+ |
+ get onDisconnect() |
+ { |
+ return { |
+ addListener() {} |
+ }; |
+ } |
+ |
+ get onMessage() |
+ { |
+ let name = this._name; |
+ return { |
+ addListener(listener) |
+ { |
+ window.addEventListener("message", (event) => |
+ { |
+ if (event.data.type != "port" || event.data.name != name) |
+ return; |
+ |
+ listener(event.data.payload); |
+ }); |
+ } |
+ }; |
+ } |
+ } |
+ window.ext._Port = Port; |
}()); |