raid-addons
Version:
Add-ons functions for use with Raid
39 lines (32 loc) • 994 B
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createAdaptor = void 0;
var identity = function identity(_) {
return _;
};
var createAdaptor = function createAdaptor(cb) {
return function adaptor(signal) {
var internalState = {};
signal.observe(function (state) {
internalState = state;
});
return function connect(selector, fn) {
if (fn && !selector) {
throw new Error('No state selector for connected function');
} // selector is optional, if it is omitted then assume the first
// argument is the component function
var select = fn ? selector : identity;
var func = fn || selector; // return props => {
// let state = select(internalState)
// return func(state, props)
// }
// return cb(select, internalState, func)
return cb(select, function () {
return internalState;
}, func);
};
};
};
exports.createAdaptor = createAdaptor;
;