Skip to content

Commit

Permalink
build
Browse files Browse the repository at this point in the history
  • Loading branch information
phenax committed Oct 27, 2018
1 parent 2091b13 commit 4a41b60
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 47 deletions.
53 changes: 33 additions & 20 deletions build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,45 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.fromClassPrototype = exports.createPipes = void 0;
Object.defineProperty(exports, "compose", {
enumerable: true,
get: function get() {
return _utils.compose;
}
});
exports.fromClassPrototype = exports.createPipes = exports.createPipe = void 0;

var _utils = require("./utils");

// type Accessors = Object Function
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

// type Accessor = (a) -> Object ((a) -> b) -> b
// type Class = Function
// createPipes :: [String] -> Accessors
var createPipes = function createPipes(methodNames) {
return (0, _utils.fromPairs)(methodNames.filter(Boolean).map(function (method) {
return [method, function () {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}

return function (obj) {
return obj[method].apply(obj, args);
};
}];
}));
}; // fromClassPrototype :: Class -> Accessors
// createPipe :: String -> Accessor
var createPipe = function createPipe(method) {
return function () {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}

return function (obj) {
return obj[method].apply(obj, args);
};
};
}; // This is beautiful. My library in action.

exports.createPipes = createPipes;

var fromClassPrototype = function fromClassPrototype(Class) {
return createPipes((0, _utils.getMethods)(Class));
};
exports.createPipe = createPipe;
var map = createPipe('map');
var filter = createPipe('filter');
var reduce = createPipe('reduce'); // createPipes :: [String] -> Object Accessor

var createPipes = (0, _utils.compose)(reduce(function (acc, method) {
return _objectSpread({}, acc, _defineProperty({}, method, createPipe(method)));
}, {}), filter(Boolean)); // fromClassPrototype :: Class -> Accessors

exports.createPipes = createPipes;
var fromClassPrototype = (0, _utils.compose)(createPipes, _utils.getMethods);
exports.fromClassPrototype = fromClassPrototype;
29 changes: 2 additions & 27 deletions build/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,7 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getMethods = exports.fromPairs = exports.compose = void 0;

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }

function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
exports.getMethods = exports.compose = void 0;

// compose :: (...Function) -> Function
var compose = function compose() {
Expand All @@ -28,23 +16,10 @@ var compose = function compose() {
return a(b.apply(void 0, arguments));
};
});
}; // fromPairs :: [[String, b]] -> Object b


exports.compose = compose;

var fromPairs = function fromPairs(pairs) {
return pairs.reduce(function (acc, _ref) {
var _ref2 = _slicedToArray(_ref, 2),
k = _ref2[0],
v = _ref2[1];

return _objectSpread({}, acc, _defineProperty({}, k, v));
}, {});
}; // getMethods :: Class -> [String]


exports.fromPairs = fromPairs;
exports.compose = compose;

var getMethods = function getMethods(Class) {
return Object.getOwnPropertyNames((Class || {}).prototype || {}).filter(function (key) {
Expand Down

0 comments on commit 4a41b60

Please sign in to comment.