Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private _observeEvent = (eventType: string | string[], stage: ObservationStage = ObservationStage.committed): Rx.Observable> => {
return Rx.Observable.create((obs: Rx.Observer) => {
const events = typeof eventType === 'string' ? [eventType] : eventType;
const espEventStreamSubscription = this._router
.getAllEventsObservable(events, stage)
.filter(eventEnvelope => eventEnvelope.modelId === this._modelId)
.subscribe(
(eventEnvelope: EventEnvelope>) => {
logger.verbose(`Passing event [${eventEnvelope.eventType}] at stage [${eventEnvelope.observationStage}] for model [${eventEnvelope.modelId}] to eventStream.`);
let inputEvent: InputEvent = this._mapEventEnvelopToInputEvent(eventEnvelope);
// Pass the event off to our polimer observable stream.
// In theory, these streams must never error.
// They need to bake in their own exception handling.
// We wrap in a try catch just to stop any exception bubbling to the router
try {
obs.onNext(inputEvent);
} catch (err) {
(eventName: string | string[], stage: string = ObservationStage.committed): Rx.Observable> => {
return Rx.Observable.create(obs => {
const events = typeof eventName === 'string'
? new Set(eventName)
: new Set(eventName);
const stream = router.getAllEventsObservable()
.filter(envelope => envelope.observationStage === stage)
.filter(envelope => events.has(envelope.eventType))
.map>(payload => ({
...payload,
store
}));
return stream.subscribe(
payload => {
logger.debug('Received esp-js payload. Passing the payload onto the polimer observables.', payload);
export function eventTransformFor(eventType: string, observationStage = ObservationStage.committed) {
return function (target, name, descriptor) {
Guard.stringIsNotEmpty(eventType, 'eventType passed to an observeStoreEvent decorator must not be \'\'');
let metadata: EspMetadata = EspDecoratorUtil.getOrCreateMetaData(target.constructor);
metadata.addEvent(
name,
eventType,
DecoratorTypes.custom,
observationStage,
null
);
return descriptor;
};
}