1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var isFunction = require("lodash/isFunction");
|
4 | var factory_1 = require("./factory");
|
5 | var bind_1 = require("./bind");
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | function BindAll(methods) {
|
30 | if (methods === void 0) { methods = []; }
|
31 | return function (target) {
|
32 | bindAllMethods(target, methods);
|
33 | };
|
34 | }
|
35 | exports.BindAll = BindAll;
|
36 | exports.bindAll = BindAll;
|
37 | function bindAllMethods(target, methods) {
|
38 | if (methods === void 0) { methods = []; }
|
39 | var targetProto = target.prototype;
|
40 | var proto = target.prototype;
|
41 | var boundKeys = [];
|
42 | while (proto && proto !== Object.prototype) {
|
43 | for (var _i = 0, _a = Object.getOwnPropertyNames(proto); _i < _a.length; _i++) {
|
44 | var key = _a[_i];
|
45 | var include = methods.length ? methods.indexOf(key) !== -1 : true;
|
46 | var descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
47 | if (include && key !== 'constructor') {
|
48 |
|
49 |
|
50 | if (descriptor.get) {
|
51 | var chainData = factory_1.InstanceChainMap.get([proto, key]);
|
52 | if (!chainData || !chainData.isMethod) {
|
53 | continue;
|
54 | }
|
55 | }
|
56 | if (isFunction(proto[key]) && boundKeys.indexOf(key) === -1) {
|
57 | Object.defineProperty(targetProto, key, bind_1.Bind(proto, key, descriptor));
|
58 | boundKeys.push(key);
|
59 | }
|
60 | }
|
61 | }
|
62 | proto = Object.getPrototypeOf(proto);
|
63 | }
|
64 | }
|
65 | exports.default = BindAll;
|
66 |
|
\ | No newline at end of file |