@effection/events
Advanced tools
Comparing version 2.0.0-preview.3-c6bfc68 to 2.0.0-preview.3-f6f5f84
@@ -29,3 +29,3 @@ 'use strict'; | ||
function once(source, eventName) { | ||
function onceEmit(source, eventName) { | ||
return function (task) { | ||
@@ -48,4 +48,12 @@ return function (resolve) { | ||
} | ||
function once(source, eventName) { | ||
return function* () { | ||
var _yield$onceEmit = yield onceEmit(source, eventName), | ||
event = _yield$onceEmit[0]; | ||
function on(source, name) { | ||
return event; | ||
}; | ||
} | ||
function onEmit(source, name) { | ||
return subscription.createStream(function (publish) { | ||
@@ -70,2 +78,8 @@ return function* () { | ||
} | ||
function on(source, name) { | ||
return onEmit(source, name).map(function (_ref) { | ||
var event = _ref[0]; | ||
return event; | ||
}); | ||
} | ||
@@ -82,4 +96,6 @@ function throwOnErrorEvent(task, source) { | ||
exports.on = on; | ||
exports.onEmit = onEmit; | ||
exports.once = once; | ||
exports.onceEmit = onceEmit; | ||
exports.throwOnErrorEvent = throwOnErrorEvent; | ||
//# sourceMappingURL=events.cjs.development.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";var n=require("@effection/subscription");function r(n){return"function"==typeof n.addEventListener}function t(n,t,e){r(n)?n.addEventListener(t,e):n.on(t,e)}function e(n,t,e){r(n)?n.removeEventListener(t,e):n.off(t,e)}function o(n,r){return function(o){return function(i){var u=function(){for(var n=arguments.length,r=new Array(n),t=0;t<n;t++)r[t]=arguments[t];i(r)};o.ensure((function(){e(n,r,u)})),t(n,r,u)}}}exports.on=function(r,o){return n.createStream((function(n){return function*(){var i=function(){for(var r=arguments.length,t=new Array(r),e=0;e<r;e++)t[e]=arguments[e];return n(t)};try{t(r,o,i),yield}finally{e(r,o,i)}}}))},exports.once=o,exports.throwOnErrorEvent=function(n,r){return n.spawn((function*(){throw(yield o(r,"error"))[0]}))}; | ||
"use strict";var n=require("@effection/subscription");function r(n){return"function"==typeof n.addEventListener}function t(n,t,e){r(n)?n.addEventListener(t,e):n.on(t,e)}function e(n,t,e){r(n)?n.removeEventListener(t,e):n.off(t,e)}function o(n,r){return function(o){return function(u){var i=function(){for(var n=arguments.length,r=new Array(n),t=0;t<n;t++)r[t]=arguments[t];u(r)};o.ensure((function(){e(n,r,i)})),t(n,r,i)}}}function u(n,r){return function*(){return(yield o(n,r))[0]}}function i(r,o){return n.createStream((function(n){return function*(){var u=function(){for(var r=arguments.length,t=new Array(r),e=0;e<r;e++)t[e]=arguments[e];return n(t)};try{t(r,o,u),yield}finally{e(r,o,u)}}}))}exports.on=function(n,r){return i(n,r).map((function(n){return n[0]}))},exports.onEmit=i,exports.once=u,exports.onceEmit=o,exports.throwOnErrorEvent=function(n,r){return n.spawn((function*(){throw(yield u(r,"error"))[0]}))}; | ||
//# sourceMappingURL=events.cjs.production.min.js.map |
@@ -27,3 +27,3 @@ import { createStream } from '@effection/subscription'; | ||
function once(source, eventName) { | ||
function onceEmit(source, eventName) { | ||
return function (task) { | ||
@@ -46,4 +46,12 @@ return function (resolve) { | ||
} | ||
function once(source, eventName) { | ||
return function* () { | ||
var _yield$onceEmit = yield onceEmit(source, eventName), | ||
event = _yield$onceEmit[0]; | ||
function on(source, name) { | ||
return event; | ||
}; | ||
} | ||
function onEmit(source, name) { | ||
return createStream(function (publish) { | ||
@@ -68,2 +76,8 @@ return function* () { | ||
} | ||
function on(source, name) { | ||
return onEmit(source, name).map(function (_ref) { | ||
var event = _ref[0]; | ||
return event; | ||
}); | ||
} | ||
@@ -79,3 +93,3 @@ function throwOnErrorEvent(task, source) { | ||
export { on, once, throwOnErrorEvent }; | ||
export { on, onEmit, once, onceEmit, throwOnErrorEvent }; | ||
//# sourceMappingURL=events.esm.js.map |
@@ -1,4 +0,4 @@ | ||
export { once } from './once'; | ||
export { on } from './on'; | ||
export { once, onceEmit } from './once'; | ||
export { on, onEmit } from './on'; | ||
export { throwOnErrorEvent } from './throw-on-error-event'; | ||
export { EventSource } from './event-source'; |
import { Stream } from '@effection/subscription'; | ||
import { EventSource } from './event-source'; | ||
export declare function on<T extends Array<unknown> = unknown[]>(source: EventSource, name: string): Stream<T, void>; | ||
export declare function onEmit<T extends Array<unknown> = unknown[]>(source: EventSource, name: string): Stream<T, void>; | ||
export declare function on<T = unknown>(source: EventSource, name: string): Stream<T, void>; |
@@ -7,2 +7,3 @@ import { Operation } from '@effection/core'; | ||
*/ | ||
export declare function once<TArgs extends unknown[] = unknown[]>(source: EventSource, eventName: string): Operation<TArgs>; | ||
export declare function onceEmit<TArgs extends unknown[] = unknown[]>(source: EventSource, eventName: string): Operation<TArgs>; | ||
export declare function once<T = unknown>(source: EventSource, eventName: string): Operation<T>; |
{ | ||
"name": "@effection/events", | ||
"version": "2.0.0-preview.3-c6bfc68", | ||
"version": "2.0.0-preview.3-f6f5f84", | ||
"description": "Helpers for listening to events with effection", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -1,4 +0,4 @@ | ||
export { once } from './once'; | ||
export { on } from './on'; | ||
export { once, onceEmit } from './once'; | ||
export { on, onEmit } from './on'; | ||
export { throwOnErrorEvent } from './throw-on-error-event'; | ||
export { EventSource } from './event-source'; |
@@ -5,3 +5,3 @@ import { createStream, Stream } from '@effection/subscription'; | ||
export function on<T extends Array<unknown> = unknown[]>(source: EventSource, name: string): Stream<T, void> { | ||
export function onEmit<T extends Array<unknown> = unknown[]>(source: EventSource, name: string): Stream<T, void> { | ||
return createStream((publish) => function*() { | ||
@@ -17,1 +17,6 @@ let listener = (...args: T) => publish(args); | ||
} | ||
export function on<T = unknown>(source: EventSource, name: string): Stream<T, void> { | ||
return onEmit<[T]>(source, name).map(([event]) => event) | ||
} |
@@ -8,3 +8,3 @@ import { Operation } from '@effection/core'; | ||
*/ | ||
export function once<TArgs extends unknown[] = unknown[]>(source: EventSource, eventName: string): Operation<TArgs> { | ||
export function onceEmit<TArgs extends unknown[] = unknown[]>(source: EventSource, eventName: string): Operation<TArgs> { | ||
return (task) => (resolve) => { | ||
@@ -18,1 +18,8 @@ let listener = (...args: unknown[]) => { resolve(args as TArgs) }; | ||
} | ||
export function once<T = unknown>(source: EventSource, eventName: string): Operation<T> { | ||
return function*() { | ||
let [event]: [T] = yield onceEmit<[T]>(source, eventName); | ||
return event; | ||
} | ||
} |
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
30279
274