Comparing version 1.1.0 to 1.1.1
340
dist/base.js
@@ -24,48 +24,108 @@ "use strict"; | ||
var _build = require("./build"); | ||
// Helpers | ||
function emitBase(_ref) { | ||
var emitTypes = _ref.emitTypes, | ||
payload = _ref.payload, | ||
prep = _ref.prep, | ||
state = _ref.state, | ||
sync = _ref.sync; | ||
function emitBase(_x) { | ||
return _emitBase.apply(this, arguments); | ||
} | ||
if (sync) { | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
function _emitBase() { | ||
_emitBase = (0, _asyncToGenerator2.default)( | ||
/*#__PURE__*/ | ||
_regenerator.default.mark(function _callee(_ref) { | ||
var payload, prep, state, sync, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, type; | ||
try { | ||
for (var _iterator = emitTypes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var type = _step.value; | ||
emitType({ | ||
payload: payload, | ||
prep: prep, | ||
state: state, | ||
sync: sync, | ||
type: type | ||
}); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return != null) { | ||
_iterator.return(); | ||
return _regenerator.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
payload = _ref.payload, prep = _ref.prep, state = _ref.state, sync = _ref.sync; | ||
if (!sync) { | ||
_context.next = 30; | ||
break; | ||
} | ||
_iteratorNormalCompletion2 = true; | ||
_didIteratorError2 = false; | ||
_iteratorError2 = undefined; | ||
_context.prev = 5; | ||
_iterator2 = _build.syncEmitTypes[Symbol.iterator](); | ||
case 7: | ||
if (_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done) { | ||
_context.next = 14; | ||
break; | ||
} | ||
type = _step2.value; | ||
_context.next = 11; | ||
return emitType({ | ||
payload: payload, | ||
prep: prep, | ||
state: state, | ||
sync: sync, | ||
type: type | ||
}); | ||
case 11: | ||
_iteratorNormalCompletion2 = true; | ||
_context.next = 7; | ||
break; | ||
case 14: | ||
_context.next = 20; | ||
break; | ||
case 16: | ||
_context.prev = 16; | ||
_context.t0 = _context["catch"](5); | ||
_didIteratorError2 = true; | ||
_iteratorError2 = _context.t0; | ||
case 20: | ||
_context.prev = 20; | ||
_context.prev = 21; | ||
if (!_iteratorNormalCompletion2 && _iterator2.return != null) { | ||
_iterator2.return(); | ||
} | ||
case 23: | ||
_context.prev = 23; | ||
if (!_didIteratorError2) { | ||
_context.next = 26; | ||
break; | ||
} | ||
throw _iteratorError2; | ||
case 26: | ||
return _context.finish(23); | ||
case 27: | ||
return _context.finish(20); | ||
case 28: | ||
_context.next = 32; | ||
break; | ||
case 30: | ||
_context.next = 32; | ||
return Promise.all(_build.asyncEmitTypes.map(emitTypesMap.bind({ | ||
payload: payload, | ||
prep: prep, | ||
state: state, | ||
sync: sync | ||
}))); | ||
case 32: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
} else { | ||
return Promise.all(emitTypes.map(emitTypesMap.bind({ | ||
payload: payload, | ||
prep: prep, | ||
state: state, | ||
sync: sync | ||
}))); | ||
} | ||
}, _callee, this, [[5, 16, 20, 28], [21,, 23, 27]]); | ||
})); | ||
return _emitBase.apply(this, arguments); | ||
} | ||
@@ -87,52 +147,112 @@ | ||
function emitType(_ref2) { | ||
var payload = _ref2.payload, | ||
prep = _ref2.prep, | ||
state = _ref2.state, | ||
sync = _ref2.sync, | ||
type = _ref2.type; | ||
var events = state.events; | ||
var map = events.maps[type]; | ||
var set = events.sets[type]; | ||
var keys = (0, _keys.buildKeys)({ | ||
prep: prep, | ||
state: state, | ||
type: type | ||
}); | ||
function emitType(_x2) { | ||
return _emitType.apply(this, arguments); | ||
} | ||
if (sync) { | ||
var _iteratorNormalCompletion2 = true; | ||
var _didIteratorError2 = false; | ||
var _iteratorError2 = undefined; | ||
function _emitType() { | ||
_emitType = (0, _asyncToGenerator2.default)( | ||
/*#__PURE__*/ | ||
_regenerator.default.mark(function _callee2(_ref2) { | ||
var payload, prep, state, sync, type, events, map, set, keys, _iteratorNormalCompletion3, _didIteratorError3, _iteratorError3, _iterator3, _step3, key; | ||
try { | ||
for (var _iterator2 = keys[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var key = _step2.value; | ||
(0, _emitter.emitSync)(map, key, payload); | ||
set.add(key); | ||
} | ||
} catch (err) { | ||
_didIteratorError2 = true; | ||
_iteratorError2 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion2 && _iterator2.return != null) { | ||
_iterator2.return(); | ||
return _regenerator.default.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
payload = _ref2.payload, prep = _ref2.prep, state = _ref2.state, sync = _ref2.sync, type = _ref2.type; | ||
events = state.events; | ||
map = events.maps[type]; | ||
set = events.sets[type]; | ||
keys = (0, _keys.buildKeys)({ | ||
prep: prep, | ||
state: state, | ||
type: type | ||
}); | ||
if (!sync) { | ||
_context2.next = 35; | ||
break; | ||
} | ||
_iteratorNormalCompletion3 = true; | ||
_didIteratorError3 = false; | ||
_iteratorError3 = undefined; | ||
_context2.prev = 9; | ||
_iterator3 = keys[Symbol.iterator](); | ||
case 11: | ||
if (_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done) { | ||
_context2.next = 19; | ||
break; | ||
} | ||
key = _step3.value; | ||
_context2.next = 15; | ||
return (0, _emitter.emitSerial)(map, key, payload); | ||
case 15: | ||
set.add(key); | ||
case 16: | ||
_iteratorNormalCompletion3 = true; | ||
_context2.next = 11; | ||
break; | ||
case 19: | ||
_context2.next = 25; | ||
break; | ||
case 21: | ||
_context2.prev = 21; | ||
_context2.t0 = _context2["catch"](9); | ||
_didIteratorError3 = true; | ||
_iteratorError3 = _context2.t0; | ||
case 25: | ||
_context2.prev = 25; | ||
_context2.prev = 26; | ||
if (!_iteratorNormalCompletion3 && _iterator3.return != null) { | ||
_iterator3.return(); | ||
} | ||
case 28: | ||
_context2.prev = 28; | ||
if (!_didIteratorError3) { | ||
_context2.next = 31; | ||
break; | ||
} | ||
throw _iteratorError3; | ||
case 31: | ||
return _context2.finish(28); | ||
case 32: | ||
return _context2.finish(25); | ||
case 33: | ||
_context2.next = 37; | ||
break; | ||
case 35: | ||
_context2.next = 37; | ||
return Promise.all(keys.map(emitMap, { | ||
map: map, | ||
payload: payload, | ||
set: set | ||
})); | ||
case 37: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} finally { | ||
if (_didIteratorError2) { | ||
throw _iteratorError2; | ||
} | ||
} | ||
} | ||
} else { | ||
return Promise.all(keys.map(emitMap, { | ||
map: map, | ||
payload: payload, | ||
set: set | ||
})); | ||
} | ||
}, _callee2, this, [[9, 21, 25, 33], [26,, 28, 32]]); | ||
})); | ||
return _emitType.apply(this, arguments); | ||
} | ||
function emitMap(_x) { | ||
function emitMap(_x3) { | ||
return _emitMap.apply(this, arguments); | ||
@@ -144,10 +264,10 @@ } | ||
/*#__PURE__*/ | ||
_regenerator.default.mark(function _callee(key) { | ||
_regenerator.default.mark(function _callee3(key) { | ||
var map, payload, set; | ||
return _regenerator.default.wrap(function _callee$(_context) { | ||
return _regenerator.default.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
map = this.map, payload = this.payload, set = this.set; | ||
_context.next = 3; | ||
_context3.next = 3; | ||
return (0, _emitter.emit)(map, key, payload); | ||
@@ -160,6 +280,6 @@ | ||
case "end": | ||
return _context.stop(); | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
}, _callee3, this); | ||
})); | ||
@@ -211,22 +331,22 @@ return _emitMap.apply(this, arguments); | ||
var offs = this.offs; | ||
var _iteratorNormalCompletion3 = true; | ||
var _didIteratorError3 = false; | ||
var _iteratorError3 = undefined; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator3 = offs[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { | ||
var off = _step3.value; | ||
for (var _iterator = offs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var off = _step.value; | ||
off(); | ||
} | ||
} catch (err) { | ||
_didIteratorError3 = true; | ||
_iteratorError3 = err; | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion3 && _iterator3.return != null) { | ||
_iterator3.return(); | ||
if (!_iteratorNormalCompletion && _iterator.return != null) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError3) { | ||
throw _iteratorError3; | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
@@ -273,3 +393,3 @@ } | ||
function onceMapFn(_x2) { | ||
function onceMapFn(_x4) { | ||
return _onceMapFn.apply(this, arguments); | ||
@@ -281,7 +401,7 @@ } | ||
/*#__PURE__*/ | ||
_regenerator.default.mark(function _callee2(opts) { | ||
_regenerator.default.mark(function _callee4(opts) { | ||
var fn, state, payload; | ||
return _regenerator.default.wrap(function _callee2$(_context2) { | ||
return _regenerator.default.wrap(function _callee4$(_context4) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
switch (_context4.prev = _context4.next) { | ||
case 0: | ||
@@ -293,14 +413,14 @@ fn = this.fn, state = this.state; | ||
}); | ||
_context2.next = 4; | ||
_context4.next = 4; | ||
return fn(payload); | ||
case 4: | ||
return _context2.abrupt("return", payload); | ||
return _context4.abrupt("return", payload); | ||
case 5: | ||
case "end": | ||
return _context2.stop(); | ||
return _context4.stop(); | ||
} | ||
} | ||
}, _callee2, this); | ||
}, _callee4, this); | ||
})); | ||
@@ -307,0 +427,0 @@ return _onceMapFn.apply(this, arguments); |
@@ -9,3 +9,2 @@ "use strict"; | ||
exports.emit = emit; | ||
exports.emitSync = emitSync; | ||
exports.on = on; | ||
@@ -15,3 +14,3 @@ exports.onEmitted = onEmitted; | ||
exports.onceEmitted = onceEmitted; | ||
exports.emitTypes = void 0; | ||
exports.emitTypes = exports.syncEmitTypes = exports.asyncEmitTypes = void 0; | ||
@@ -31,3 +30,7 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); | ||
// Constants | ||
var emitTypes = ["any", "on"]; // Helpers | ||
var asyncEmitTypes = ["any", "on"]; | ||
exports.asyncEmitTypes = asyncEmitTypes; | ||
var syncEmitTypes = ["anySync", "onSync"]; | ||
exports.syncEmitTypes = syncEmitTypes; | ||
var emitTypes = asyncEmitTypes.concat(syncEmitTypes); // Helpers | ||
@@ -68,8 +71,12 @@ exports.emitTypes = emitTypes; | ||
_context.next = 5; | ||
return (0, _base.emitBase)({ | ||
emitTypes: emitTypes, | ||
return Promise.all([(0, _base.emitBase)({ | ||
payload: payload, | ||
prep: "before", | ||
state: state | ||
}); | ||
}), (0, _base.emitBase)({ | ||
payload: payload, | ||
prep: "before", | ||
state: state, | ||
sync: true | ||
})]); | ||
@@ -82,11 +89,14 @@ case 5: | ||
return _context.abrupt("return", payload); | ||
return _context.abrupt("return", payload.event.signal.returnValue); | ||
case 7: | ||
_context.next = 9; | ||
return (0, _base.emitBase)({ | ||
emitTypes: emitTypes, | ||
return Promise.all([(0, _base.emitBase)({ | ||
payload: payload, | ||
state: state | ||
}); | ||
}), (0, _base.emitBase)({ | ||
payload: payload, | ||
state: state, | ||
sync: true | ||
})]); | ||
@@ -99,12 +109,16 @@ case 9: | ||
return _context.abrupt("return", payload); | ||
return _context.abrupt("return", payload.event.signal.returnValue); | ||
case 11: | ||
_context.next = 13; | ||
return (0, _base.emitBase)({ | ||
emitTypes: emitTypes, | ||
return Promise.all([(0, _base.emitBase)({ | ||
payload: payload, | ||
prep: "after", | ||
state: state | ||
}); | ||
}), (0, _base.emitBase)({ | ||
payload: payload, | ||
prep: "after", | ||
state: state, | ||
sync: true | ||
})]); | ||
@@ -124,3 +138,3 @@ case 13: | ||
function emitSync() { | ||
function on() { | ||
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
@@ -134,49 +148,2 @@ args[_key2] = arguments[_key2]; | ||
}); | ||
var payload = (0, _payload.buildPayload)({ | ||
emit: true, | ||
state: state | ||
}); | ||
(0, _base.emitBase)({ | ||
emitTypes: emitTypes, | ||
payload: payload, | ||
prep: "before", | ||
state: state, | ||
sync: true | ||
}); | ||
if (payload.event.signal.cancel) { | ||
return payload; | ||
} | ||
(0, _base.emitBase)({ | ||
emitTypes: emitTypes, | ||
payload: payload, | ||
state: state, | ||
sync: true | ||
}); | ||
if (payload.event.signal.cancel) { | ||
return payload; | ||
} | ||
(0, _base.emitBase)({ | ||
emitTypes: emitTypes, | ||
payload: payload, | ||
prep: "after", | ||
state: state, | ||
sync: true | ||
}); | ||
return payload.event.signal.returnValue; | ||
} | ||
function on() { | ||
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { | ||
args[_key3] = arguments[_key3]; | ||
} | ||
var type = nameToType(this.name); | ||
var state = (0, _args3.initState)({ | ||
args: args, | ||
options: this | ||
}); | ||
var multiOutput = (0, _multi.multi)({ | ||
@@ -186,2 +153,3 @@ fn: on, | ||
}); | ||
var type = getType(state); | ||
@@ -199,7 +167,6 @@ if (multiOutput) { | ||
function onEmitted() { | ||
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { | ||
args[_key4] = arguments[_key4]; | ||
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { | ||
args[_key3] = arguments[_key3]; | ||
} | ||
var type = nameToType(this.name); | ||
var state = (0, _args3.initState)({ | ||
@@ -213,2 +180,3 @@ args: args, | ||
}); | ||
var type = getType(state); | ||
@@ -237,7 +205,6 @@ if (multiOutput) { | ||
function once() { | ||
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) { | ||
args[_key5] = arguments[_key5]; | ||
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { | ||
args[_key4] = arguments[_key4]; | ||
} | ||
var type = nameToType(this.name); | ||
var state = (0, _args3.initState)({ | ||
@@ -251,2 +218,3 @@ args: args, | ||
}); | ||
var type = getType(state); | ||
@@ -264,7 +232,6 @@ if (multiOutput) { | ||
function onceEmitted() { | ||
for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) { | ||
args[_key6] = arguments[_key6]; | ||
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) { | ||
args[_key5] = arguments[_key5]; | ||
} | ||
var type = nameToType(this.name); | ||
var state = (0, _args3.initState)({ | ||
@@ -278,2 +245,3 @@ args: args, | ||
}); | ||
var type = getType(state); | ||
@@ -334,5 +302,7 @@ if (multiOutput) { | ||
function nameToType(name) { | ||
return name.indexOf("Any") > -1 ? "any" : "on"; | ||
function getType(_ref2) { | ||
var name = _ref2.name, | ||
sync = _ref2.sync; | ||
return (name.indexOf("Any") > -1 ? "any" : "on") + (sync ? "Sync" : ""); | ||
} | ||
//# sourceMappingURL=build.js.map |
@@ -27,3 +27,2 @@ "use strict"; | ||
emit: _build.emit.bind(opts), | ||
emitSync: _build.emitSync.bind(opts), | ||
on: _build.on.bind((0, _objectSpread2.default)({}, opts, { | ||
@@ -53,2 +52,5 @@ name: "on" | ||
})), | ||
sync: contextComposer.bind((0, _objectSpread2.default)({}, opts, { | ||
sync: true | ||
})), | ||
withOp: function withOp(op) { | ||
@@ -55,0 +57,0 @@ (0, _op.opBase)({ |
@@ -38,5 +38,31 @@ "use strict"; | ||
state = this.state; | ||
var listener = state.args[0][props]; | ||
if (Array.isArray(listener)) { | ||
return listener.map(function (listenFn) { | ||
return buildSubscriber({ | ||
fn: fn, | ||
listener: listenFn, | ||
props: props, | ||
state: state | ||
}); | ||
}); | ||
} else { | ||
return buildSubscriber({ | ||
fn: fn, | ||
listener: listener, | ||
props: props, | ||
state: state | ||
}); | ||
} | ||
} | ||
function buildSubscriber(_ref2) { | ||
var fn = _ref2.fn, | ||
listener = _ref2.listener, | ||
props = _ref2.props, | ||
state = _ref2.state; | ||
return fn.call((0, _objectSpread2.default)({}, state, { | ||
args: undefined, | ||
fn: state.args[0][props], | ||
fn: listener, | ||
props: props | ||
@@ -55,3 +81,30 @@ })); | ||
var off = _step.value; | ||
off(); | ||
if (Array.isArray(off)) { | ||
var _iteratorNormalCompletion2 = true; | ||
var _didIteratorError2 = false; | ||
var _iteratorError2 = undefined; | ||
try { | ||
for (var _iterator2 = off[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var fn = _step2.value; | ||
fn(); | ||
} | ||
} catch (err) { | ||
_didIteratorError2 = true; | ||
_iteratorError2 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion2 && _iterator2.return != null) { | ||
_iterator2.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError2) { | ||
throw _iteratorError2; | ||
} | ||
} | ||
} | ||
} else { | ||
off(); | ||
} | ||
} | ||
@@ -58,0 +111,0 @@ } catch (err) { |
// Helpers | ||
import { buildKeys } from "./keys" | ||
import { buildPayload } from "./payload" | ||
import { emit, emitSync, on, once } from "./emitter" | ||
import { emit, emitSerial, on, once } from "./emitter" | ||
import { asyncEmitTypes, syncEmitTypes } from "./build" | ||
export function emitBase({ | ||
emitTypes, | ||
export async function emitBase({ | ||
payload, | ||
@@ -14,8 +14,8 @@ prep, | ||
if (sync) { | ||
for (const type of emitTypes) { | ||
emitType({ payload, prep, state, sync, type }) | ||
for (const type of syncEmitTypes) { | ||
await emitType({ payload, prep, state, sync, type }) | ||
} | ||
} else { | ||
return Promise.all( | ||
emitTypes.map( | ||
await Promise.all( | ||
asyncEmitTypes.map( | ||
emitTypesMap.bind({ payload, prep, state, sync }) | ||
@@ -32,3 +32,3 @@ ) | ||
export function emitType({ | ||
export async function emitType({ | ||
payload, | ||
@@ -47,7 +47,7 @@ prep, | ||
for (const key of keys) { | ||
emitSync(map, key, payload) | ||
await emitSerial(map, key, payload) | ||
set.add(key) | ||
} | ||
} else { | ||
return Promise.all( | ||
await Promise.all( | ||
keys.map(emitMap, { map, payload, set }) | ||
@@ -54,0 +54,0 @@ ) |
@@ -12,3 +12,7 @@ import { initState } from "./args" | ||
// Constants | ||
export const emitTypes = ["any", "on"] | ||
export const asyncEmitTypes = ["any", "on"] | ||
export const syncEmitTypes = ["anySync", "onSync"] | ||
export const emitTypes = asyncEmitTypes.concat( | ||
syncEmitTypes | ||
) | ||
@@ -20,25 +24,29 @@ // Helpers | ||
await emitBase({ | ||
emitTypes, | ||
payload, | ||
prep: "before", | ||
state, | ||
}) | ||
await Promise.all([ | ||
emitBase({ payload, prep: "before", state }), | ||
emitBase({ | ||
payload, | ||
prep: "before", | ||
state, | ||
sync: true, | ||
}), | ||
]) | ||
if (payload.event.signal.cancel) { | ||
return payload | ||
return payload.event.signal.returnValue | ||
} | ||
await emitBase({ emitTypes, payload, state }) | ||
await Promise.all([ | ||
emitBase({ payload, state }), | ||
emitBase({ payload, state, sync: true }), | ||
]) | ||
if (payload.event.signal.cancel) { | ||
return payload | ||
return payload.event.signal.returnValue | ||
} | ||
await emitBase({ | ||
emitTypes, | ||
payload, | ||
prep: "after", | ||
state, | ||
}) | ||
await Promise.all([ | ||
emitBase({ payload, prep: "after", state }), | ||
emitBase({ payload, prep: "after", state, sync: true }), | ||
]) | ||
@@ -48,39 +56,6 @@ return payload.event.signal.returnValue | ||
export function emitSync(...args) { | ||
const state = initState({ args, options: this }) | ||
const payload = buildPayload({ emit: true, state }) | ||
emitBase({ | ||
emitTypes, | ||
payload, | ||
prep: "before", | ||
state, | ||
sync: true, | ||
}) | ||
if (payload.event.signal.cancel) { | ||
return payload | ||
} | ||
emitBase({ emitTypes, payload, state, sync: true }) | ||
if (payload.event.signal.cancel) { | ||
return payload | ||
} | ||
emitBase({ | ||
emitTypes, | ||
payload, | ||
prep: "after", | ||
state, | ||
sync: true, | ||
}) | ||
return payload.event.signal.returnValue | ||
} | ||
export function on(...args) { | ||
const type = nameToType(this.name) | ||
const state = initState({ args, options: this }) | ||
const multiOutput = multi({ fn: on, state }) | ||
const type = getType(state) | ||
@@ -95,5 +70,5 @@ if (multiOutput) { | ||
export function onEmitted(...args) { | ||
const type = nameToType(this.name) | ||
const state = initState({ args, options: this }) | ||
const multiOutput = multi({ fn: onEmitted, state }) | ||
const type = getType(state) | ||
@@ -114,5 +89,5 @@ if (multiOutput) { | ||
export function once(...args) { | ||
const type = nameToType(this.name) | ||
const state = initState({ args, options: this }) | ||
const multiOutput = multi({ fn: once, state }) | ||
const type = getType(state) | ||
@@ -127,5 +102,5 @@ if (multiOutput) { | ||
export function onceEmitted(...args) { | ||
const type = nameToType(this.name) | ||
const state = initState({ args, options: this }) | ||
const multiOutput = multi({ fn: onceEmitted, state }) | ||
const type = getType(state) | ||
@@ -151,4 +126,7 @@ if (multiOutput) { | ||
function nameToType(name) { | ||
return name.indexOf("Any") > -1 ? "any" : "on" | ||
function getType({ name, sync }) { | ||
return ( | ||
(name.indexOf("Any") > -1 ? "any" : "on") + | ||
(sync ? "Sync" : "") | ||
) | ||
} |
import { opBase } from "./op" | ||
import { | ||
emit, | ||
emitSync, | ||
onEmitted, | ||
@@ -24,4 +23,2 @@ on, | ||
emitSync: emitSync.bind(opts), | ||
on: on.bind({ ...opts, name: "on" }), | ||
@@ -55,2 +52,7 @@ | ||
sync: contextComposer.bind({ | ||
...opts, | ||
sync: true, | ||
}), | ||
withOp: op => { | ||
@@ -57,0 +59,0 @@ opBase({ op, options: opts }) |
@@ -20,7 +20,23 @@ import { isObject } from "./util" | ||
const { fn, state } = this | ||
const listener = state.args[0][props] | ||
if (Array.isArray(listener)) { | ||
return listener.map(listenFn => | ||
buildSubscriber({ | ||
fn, | ||
listener: listenFn, | ||
props, | ||
state, | ||
}) | ||
) | ||
} else { | ||
return buildSubscriber({ fn, listener, props, state }) | ||
} | ||
} | ||
function buildSubscriber({ fn, listener, props, state }) { | ||
return fn.call({ | ||
...state, | ||
args: undefined, | ||
fn: state.args[0][props], | ||
fn: listener, | ||
props, | ||
@@ -33,4 +49,10 @@ }) | ||
for (const off of offs) { | ||
off() | ||
if (Array.isArray(off)) { | ||
for (const fn of off) { | ||
fn() | ||
} | ||
} else { | ||
off() | ||
} | ||
} | ||
} |
@@ -15,3 +15,3 @@ { | ||
], | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Build beautiful and extensible eventing APIs", | ||
@@ -18,0 +18,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
117628
2188