UNPKG

js-abstract-synchronizer

Version:
52 lines (40 loc) 1.75 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _lodash = require('lodash'); var _lodash2 = _interopRequireDefault(_lodash); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } var addArrayMethods = function addArrayMethods(_ref) { var getTargetInnerObject = _ref.getTargetInnerObject, target = _ref.target; target.get = function get(index) { return getTargetInnerObject()[index]; }; target.set = function set(index, value) { getTargetInnerObject()[index] = value; }; target.size = function size() { return getTargetInnerObject().length; }; }; exports.default = function (_ref2) { var getTargetInnerObject = _ref2.getTargetInnerObject, prototype = _ref2.prototype, target = _ref2.target; var allMethodsNames = _lodash2.default.difference(_lodash2.default.filter(Object.getOwnPropertyNames(prototype), function (property) { return typeof prototype[property] === 'function'; }), [].concat(_toConsumableArray(Object.getOwnPropertyNames(Object.prototype)), ['constructor'])); allMethodsNames.forEach(function (methodName) { target[methodName] = function () { for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return prototype[methodName].apply(getTargetInnerObject(), args); }; }); if (Array.isArray(prototype)) { addArrayMethods({ getTargetInnerObject: getTargetInnerObject, target: target }); } };