1 |
|
2 |
|
3 | import { __read, __spread } from "tslib";
|
4 | var lists = [];
|
5 | var MethodEmbed = (function () {
|
6 | function MethodEmbed(context, methodName) {
|
7 | this.context = context;
|
8 | this.methodName = methodName;
|
9 | this._originalMethod = context[methodName].bind(context);
|
10 | }
|
11 | MethodEmbed.add = function (context, methodName, methodOverride) {
|
12 | getInstance(context, methodName).set(methodOverride);
|
13 | };
|
14 | MethodEmbed.remove = function (context, methodName) {
|
15 | getInstance(context, methodName).remove();
|
16 | };
|
17 | MethodEmbed.prototype.set = function (methodOverride) {
|
18 | var _this = this;
|
19 | this.context[this.methodName] = function () {
|
20 | var args = [];
|
21 | for (var _i = 0; _i < arguments.length; _i++) {
|
22 | args[_i] = arguments[_i];
|
23 | }
|
24 | return methodOverride(_this._originalMethod.apply(_this, __spread(args)));
|
25 | };
|
26 | };
|
27 | MethodEmbed.prototype.remove = function () {
|
28 | this.context[this.methodName] = this._originalMethod;
|
29 | };
|
30 | return MethodEmbed;
|
31 | }());
|
32 | export { MethodEmbed };
|
33 | function getInstance(context, methodName) {
|
34 | var instance = lists.filter(function (h) { return h.context === context && h.methodName === methodName; })[0];
|
35 | if (!instance) {
|
36 | instance = new MethodEmbed(context, methodName);
|
37 | lists.push(instance);
|
38 | }
|
39 | return instance;
|
40 | }
|
41 |
|
\ | No newline at end of file |