1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | var __read = (this && this.__read) || function (o, n) {
|
15 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
16 | if (!m) return o;
|
17 | var i = m.call(o), r, ar = [], e;
|
18 | try {
|
19 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
20 | }
|
21 | catch (error) { e = { error: error }; }
|
22 | finally {
|
23 | try {
|
24 | if (r && !r.done && (m = i["return"])) m.call(i);
|
25 | }
|
26 | finally { if (e) throw e.error; }
|
27 | }
|
28 | return ar;
|
29 | };
|
30 | var __spread = (this && this.__spread) || function () {
|
31 | for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
32 | return ar;
|
33 | };
|
34 | Object.defineProperty(exports, "__esModule", { value: true });
|
35 | var lists = [];
|
36 | var MethodEmbed = (function () {
|
37 | function MethodEmbed(context, methodName) {
|
38 | this.context = context;
|
39 | this.methodName = methodName;
|
40 | this._originalMethod = context[methodName].bind(context);
|
41 | }
|
42 | MethodEmbed.add = function (context, methodName, methodOverride) {
|
43 | getInstance(context, methodName).set(methodOverride);
|
44 | };
|
45 | MethodEmbed.remove = function (context, methodName) {
|
46 | getInstance(context, methodName).remove();
|
47 | };
|
48 | MethodEmbed.prototype.set = function (methodOverride) {
|
49 | var _this = this;
|
50 | this.context[this.methodName] = function () {
|
51 | var args = [];
|
52 | for (var _i = 0; _i < arguments.length; _i++) {
|
53 | args[_i] = arguments[_i];
|
54 | }
|
55 | return methodOverride(_this._originalMethod.apply(_this, __spread(args)));
|
56 | };
|
57 | };
|
58 | MethodEmbed.prototype.remove = function () {
|
59 | this.context[this.methodName] = this._originalMethod;
|
60 | };
|
61 | return MethodEmbed;
|
62 | }());
|
63 | exports.MethodEmbed = MethodEmbed;
|
64 | function getInstance(context, methodName) {
|
65 | var instance = lists.filter(function (h) { return h.context === context && h.methodName === methodName; })[0];
|
66 | if (!instance) {
|
67 | instance = new MethodEmbed(context, methodName);
|
68 | lists.push(instance);
|
69 | }
|
70 | return instance;
|
71 | }
|
72 |
|
73 |
|
74 |
|
75 | exports.default = MethodEmbed;
|
76 |
|
\ | No newline at end of file |