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