Skip to content

Commit

Permalink
Make the stampit infectable.
Browse files Browse the repository at this point in the history
  • Loading branch information
koresar committed Sep 19, 2016
1 parent 6737b9c commit f93476e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
10 changes: 4 additions & 6 deletions src/stampit.js
Expand Up @@ -110,11 +110,7 @@ const baseStampit = compose({
return this(...args);
},

compose(...args) {
args = args.filter(isComposable)
.map(arg => isStamp(arg) ? arg : standardiseDescriptor(arg));
return compose.apply(this || baseStampit, args);
}
compose: stampit
}, allUtilities)
});

Expand All @@ -123,7 +119,9 @@ const baseStampit = compose({
* @return {Stamp}
*/
function stampit(...args) {
return baseStampit.compose(...args);
args = args.filter(isComposable)
.map(arg => isStamp(arg) ? arg : standardiseDescriptor(arg));
return compose.apply(this || baseStampit, args);
}

export default assign(stampit,
Expand Down
2 changes: 1 addition & 1 deletion test/import.js
Expand Up @@ -7,7 +7,7 @@ test('import is the same as require', (t) => {
const stampit2 = require('../dist/stampit');

t.equal(stampit1, stampit2,
'Should export same object for both ES and CommonJS');
'Should export same object for both ES6 and CommonJS');

t.end();
});
29 changes: 29 additions & 0 deletions test/infected-statics.js
Expand Up @@ -73,3 +73,32 @@ test('stampit().staticPropertyDescriptors static method', (t) => {

t.end();
});

test('stampit() can be infected', t => {
let counter = 0;
const infectedStampit = function (...args) {
counter++;
args.push({
staticProperties: {
compose: infectedStampit
}
});

return stampit.apply(this, args);
};

const stamp = infectedStampit({props: {a: 1}}) // 1
.compose({deepProps: {b: 2}}) // 2
.methods({c: 3}) // 3
.compose( // 4
infectedStampit({conf: {d: 4}}) // 5
);

t.equal(counter, 5, 'should call infected compose 5 times');
t.equal(stamp.compose.properties.a, 1, 'should compose properties');
t.equal(stamp.compose.deepProperties.b, 2, 'should compose deepProperties');
t.equal(stamp.compose.methods.c, 3, 'should compose methods');
t.equal(stamp.compose.configuration.d, 4, 'should compose configuration');

t.end();
});

0 comments on commit f93476e

Please sign in to comment.