-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
39 lines (33 loc) · 992 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var mixins = module.exports = function () {};
mixins.focusingInput = require('./mixins/focusingInput');
mixins.forceUpdateOn = require('./mixins/forceUpdateOn');
mixins.swapProps = require('./mixins/swapProps');
mixins.after = function (afterFn) {
return function (fn) {
return function () {
fn.apply(this, arguments);
afterFn.apply(this, arguments);
};
};
};
mixins.before = function (beforeFn) {
return function (fn) {
return function () {
beforeFn.apply(this, arguments);
fn.apply(this, arguments);
};
};
};
mixins.inOrder = joiner(mixins.before);
mixins.inReverseOrder = joiner(mixins.after);
function joiner (combiner) {
return function (mixins) {
return mixins.reduce(function (joinedMixins, mixin) {
Object.keys(mixin).forEach(function (key) {
var prevFn = (joinedMixins[key] || function () {});
joinedMixins[key] = combiner(prevFn)(mixin[key]);
});
return joinedMixins;
}, {});
};
}