Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function connect(options = {}) {
const id = generateId(options.instanceId);
const opts = {
...options,
instanceId: id,
name: options.name || id,
actionCreators: JSON.stringify(getActionsArray(options.actionCreators || {})),
};
start();
return {
init(state, action) {
send(action || {}, state, 'INIT', opts);
},
subscribe(listener) {
if (!listener) return undefined;
if (!listeners[id]) listeners[id] = [];
listeners[id].push(listener);
return function unsubscribe() {
const index = listeners[id].indexOf(listener);
listeners[id].splice(index, 1);
};
},
if (options.actionCreators) this.actionCreators = () => getActionsArray(options.actionCreators);
this.stateSanitizer = options.stateSanitizer;
actionCreators: actionCreators && (() => getActionsArray(actionCreators)),
stateSanitizer,