Comparing version 1.0.3 to 1.1.0
43
index.js
var objectAssign = require('object-assign') | ||
var R = require('ramda') | ||
module.exports = { | ||
/** | ||
* factorIn | ||
* Take optional actions and return a Factory function | ||
* that calls said actions | ||
* @param {Object} actions | ||
* @return {Function} | ||
*/ | ||
factorIn: function (actions) { | ||
if (typeof (actions) !== 'object') return null | ||
actions = actions || {} | ||
return function (f) { | ||
return f ? f(actions) : null | ||
} | ||
}, | ||
/** | ||
* factory | ||
* Return a function that applies it's `actions` to any optional `args` | ||
* and returns an object. | ||
* @param {Object} args | ||
* @return {Function} | ||
*/ | ||
factory: function (args) { | ||
args = args || null | ||
return function (actions) { | ||
actions = actions || {} | ||
return objectAssign({}, actions, args) | ||
} | ||
function FactorIn (actions) { | ||
if (typeof (actions) !== 'object') return null | ||
return function (args) { | ||
return objectAssign( | ||
{}, | ||
actions, | ||
args | ||
) | ||
} | ||
} | ||
module.exports = R.curry(FactorIn) |
{ | ||
"name": "factor-in", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "Generate unique factory functions that return objects with inherited object data", | ||
@@ -15,3 +15,4 @@ "main": "index.js", | ||
"dependencies": { | ||
"object-assign": "^4.0.1" | ||
"object-assign": "^4.0.1", | ||
"ramda": "^0.17.1" | ||
}, | ||
@@ -18,0 +19,0 @@ "devDependencies": { |
@@ -20,7 +20,7 @@ # factor-in | ||
```js | ||
import { factorIn as FI, factory as F } from 'factor-in' | ||
import factorIn from 'factor-in' | ||
// Create our base factory function with object data we expect all | ||
// Create our base object data we expect all | ||
// factory functions to inherit from. | ||
const FactorIn = FI ({ | ||
const f = factorIn ({ | ||
foo () {}, | ||
@@ -30,10 +30,3 @@ bar () {} | ||
// Create a new factory function with unique object data | ||
const UniqueFactory = F ({ | ||
baz: 'Baz', | ||
qux: 'Qux' | ||
}) | ||
// To create our custom object we`factor-in` our `UniqueFactory` function. | ||
const myCustomObject = FactorIn(UniqueFactory) | ||
var obj = f ({ baz: 'Baz', qux: 'Qux' }) | ||
//=> {foo: foo(), bar: bar(), baz: 'Baz', qux: 'Qux'} | ||
@@ -40,0 +33,0 @@ ``` |
3790
2
13
45
+ Addedramda@^0.17.1
+ Addedramda@0.17.1(transitive)