it('should not fail when types are symbols', () => { const actions = new Subject(); const cache1 = []; const cache2 = []; const LULZ_TYPE = Symbol(); const HAHA_TYPE = Symbol(); const LARF_TYPE = Symbol(); actions.pipe(ofType(LULZ_TYPE, LARF_TYPE)).subscribe(x => cache1.push(x)); actions.pipe(ofType(HAHA_TYPE)).subscribe(x => cache2.push(x)); actions.next({ type: LULZ_TYPE, i: 0 }); expect(cache1).to.deep.equal([{ type: LULZ_TYPE, i: 0 }]); expect(cache2).to.deep.equal([]); actions.next({ type: LARF_TYPE, i: 1 }); expect(cache1).to.deep.equal([{ type: LULZ_TYPE, i: 0 }, { type: LARF_TYPE, i: 1 }]); expect(cache2).to.deep.equal([]); actions.next({ type: HAHA_TYPE, i: 0 }); expect(cache1).to.deep.equal([{ type: LULZ_TYPE, i: 0 }, { type: LARF_TYPE, i: 1 }]); expect(cache2).to.deep.equal([{ type: HAHA_TYPE, i: 0 }]); });
switchMap(() => { const frameReady = new Subject(); const consoleProxy = new Subject(); const frameTests = createTestFramer( document, state$, frameReady, consoleProxy ); const challengeResults = frameReady.pipe( pluck('checkChallengePayload'), map(checkChallengePayload => ({ checkChallengePayload, tests: challengeTestsSelector(state$.value) })), switchMap(({ checkChallengePayload, tests }) => { const postTests = of( updateConsole('// tests completed'), logsToConsole('// console output'), checkChallenge(checkChallengePayload) ).pipe(delay(250)); return runTestsInTestFrame(document, tests).pipe( switchMap(tests => { return from(tests).pipe( map(({ message }) => message), filter(overEvery(isString, Boolean)), map(updateConsole), concat(of(updateTests(tests))) ); }), concat(postTests) ); }) ); const buildAndFrameChallenge = action$.pipe( ofType(types.executeChallenge), debounceTime(executeDebounceTimeout), filter(() => isJSEnabledSelector(state$.value)), switchMap(() => { const state = state$.value; const { challengeType } = challengeMetaSelector(state); const build = challengeType === backend ? buildBackendChallenge : buildFromFiles; return build(state).pipe( tap(frameTests), ignoreElements(), startWith(initLogs()), startWith(initConsole('// running tests')), catchError(err => { console.error(err); return of(disableJSOnError(err)); }) ); }) ); const proxyConsole = consoleProxy.pipe(map(updateLogs)); return merge(buildAndFrameChallenge, challengeResults, proxyConsole); })
postMessage(data) { const tid = this._makeTaskID(); this._tasks.push({tid, data}); if (this.__dbg) console.log(`Pool: [name=${this._name}, tid=${tid}, queue=${this._tasks.length}]`); this._run(); return race( this.messages$.pipe(filter((e) => e.tid === tid), take(1), pluck('m', 'data')), this.errors$.pipe(filter((e) => e.tid === tid), take(1), map((e) => { throw e.e; })) ).pipe(take(1)).toPromise(); }
it('should handle actionCreators which define a toString method', () => { // This helps when using the popular `redux-actions` npm package. const actions = new Subject(); const cache1 = []; const cache2 = []; const LULZ_TYPE = 'LULZ'; const HAHA_TYPE = 'HAHA'; const LARF_TYPE = Symbol(); const createActionCreator = type => { const actionCreator = payload => ({ type, payload }); actionCreator.toString = () => type; return actionCreator; }; const lulz = createActionCreator(LULZ_TYPE); const haha = createActionCreator(HAHA_TYPE); const larf = createActionCreator(LARF_TYPE); // Sanity check. expect(String(lulz)).to.deep.equal(LULZ_TYPE); expect(lulz(0)).to.deep.equal({ type: LULZ_TYPE, payload: 0 }); actions.pipe(ofType(lulz, larf)).subscribe(x => cache1.push(x)); actions.pipe(ofType(haha)).subscribe(x => cache2.push(x)); actions.next(lulz(0)); expect(cache1).to.deep.equal([lulz(0)]); expect(cache2).to.deep.equal([]); actions.next(larf(1)); expect(cache1).to.deep.equal([lulz(0), larf(1)]); expect(cache2).to.deep.equal([]); actions.next(haha(0)); expect(cache1).to.deep.equal([lulz(0), larf(1)]); expect(cache2).to.deep.equal([haha(0)]); });
it('should filter by action type', () => { let actions = new Subject(); let lulz = []; let haha = []; actions.pipe(ofType('LULZ')).subscribe(x => lulz.push(x)); actions.pipe(ofType('HAHA')).subscribe(x => haha.push(x)); actions.next({ type: 'LULZ', i: 0 }); expect(lulz).to.deep.equal([{ type: 'LULZ', i: 0 }]); expect(haha).to.deep.equal([]); actions.next({ type: 'LULZ', i: 1 }); expect(lulz).to.deep.equal([{ type: 'LULZ', i: 0 }, { type: 'LULZ', i: 1 }]); expect(haha).to.deep.equal([]); actions.next({ type: 'HAHA', i: 0 }); expect(lulz).to.deep.equal([{ type: 'LULZ', i: 0 }, { type: 'LULZ', i: 1 }]); expect(haha).to.deep.equal([{ type: 'HAHA', i: 0 }]); });
return this._platform.isBrowser ? Observable.create(observer => { if (!this._globalSubscription) { this._addGlobalListener(); } // In the case of a 0ms delay, use an observable without auditTime // since it does add a perceptible delay in processing overhead. const /** @type {?} */ subscription = auditTimeInMs > 0 ? this._scrolled.pipe(auditTime(auditTimeInMs)).subscribe(observer) : this._scrolled.subscribe(observer); this._scrolledCount++; return () => { subscription.unsubscribe(); this._scrolledCount--; if (!this._scrolledCount) { this._removeGlobalListener(); } }; }) : of();
/** * @return {?} */ ngAfterContentInit() { this._drawers.changes.pipe(startWith(null)).subscribe(() => { this._validateDrawers(); this._drawers.forEach((drawer) => { this._watchDrawerToggle(drawer); this._watchDrawerPosition(drawer); this._watchDrawerMode(drawer); }); if (!this._drawers.length || this._isDrawerOpen(this._start) || this._isDrawerOpen(this._end)) { this._updateContentMargins(); } this._changeDetectorRef.markForCheck(); }); this._doCheckSubject.pipe(debounceTime(10), // Arbitrary debounce time, less than a frame at 60fps // Arbitrary debounce time, less than a frame at 60fps takeUntil(this._destroyed)).subscribe(() => this._updateContentMargins()); }
function stopEventHandler() { const stopSubject$ = new Subject(); const stop$ = stopSubject$.pipe( switchMap(executeStopJobRunMutation), catchError(error => { return stop$.pipe( startWith({ errorMessage: error && error.response && error.response.message, done: true }) ); }) ); return { stop$, stopHandler: (jobId, jobRunId, onSuccess) => { stopSubject$.next({ jobId, jobRunId, onSuccess }); } }; }
/** * Stream that emits whenever the hovered menu item changes. * @return {?} */ _hovered() { return this._itemChanges.pipe(startWith(this._items), switchMap(items => merge(...items.map(item => item._hovered)))); }
/** * Event emitted when the drawer has started closing. * @return {?} */ get closedStart() { return this._animationStarted.pipe(filter(e => e.fromState !== e.toState && e.toState === 'void'), map(() => { })); }
/** * Event emitted when the drawer has started opening. * @return {?} */ get openedStart() { return this._animationStarted.pipe(filter(e => e.fromState !== e.toState && e.toState.indexOf('open') === 0), map(() => { })); }
/** * @param {?} _elementRef * @param {?} _focusTrapFactory * @param {?} _focusMonitor * @param {?} _platform * @param {?} _ngZone * @param {?} _doc */ constructor(_elementRef, _focusTrapFactory, _focusMonitor, _platform, _ngZone, _doc) { this._elementRef = _elementRef; this._focusTrapFactory = _focusTrapFactory; this._focusMonitor = _focusMonitor; this._platform = _platform; this._ngZone = _ngZone; this._doc = _doc; this._elementFocusedBeforeDrawerWasOpened = null; /** * Whether the drawer is initialized. Used for disabling the initial animation. */ this._enableAnimations = false; this._position = 'start'; this._mode = 'over'; this._disableClose = false; this._autoFocus = true; /** * Emits whenever the drawer has started animating. */ this._animationStarted = new Subject(); /** * Emits whenever the drawer is done animating. */ this._animationEnd = new Subject(); /** * Current state of the sidenav animation. */ this._animationState = 'void'; /** * Event emitted when the drawer open state is changed. */ this.openedChange = // Note this has to be async in order to avoid some issues with two-bindings (see #8872). new EventEmitter(/* isAsync */ /* isAsync */ true); /** * Event emitted when the drawer's position changes. */ this.onPositionChanged = new EventEmitter(); /** * An observable that emits when the drawer mode changes. This is used by the drawer container to * to know when to when the mode changes so it can adapt the margins on the content. */ this._modeChanged = new Subject(); this._opened = false; this.openedChange.subscribe((opened) => { if (opened) { if (this._doc) { this._elementFocusedBeforeDrawerWasOpened = /** @type {?} */ (this._doc.activeElement); } if (this._isFocusTrapEnabled && this._focusTrap) { this._trapFocus(); } } else { this._restoreFocus(); } }); /** * Listen to `keydown` events outside the zone so that change detection is not run every * time a key is pressed. Instead we re-enter the zone only if the `ESC` key is pressed * and we don't have close disabled. */ this._ngZone.runOutsideAngular(() => { fromEvent(this._elementRef.nativeElement, 'keydown').pipe(filter(event => event.keyCode === ESCAPE && !this.disableClose)).subscribe(event => this._ngZone.run(() => { this.close(); event.stopPropagation(); })); }); // We need a Subject with distinctUntilChanged, because the `done` event // fires twice on some browsers. See https://github.com/angular/angular/issues/24084 this._animationEnd.pipe(distinctUntilChanged((x, y) => { return x.fromState === y.fromState && x.toState === y.toState; })).subscribe((event) => { const { fromState, toState } = event; if ((toState.indexOf('open') === 0 && fromState === 'void') || (toState === 'void' && fromState.indexOf('open') === 0)) { this.openedChange.emit(this._opened); } }); }
uri, index }); const addRepositoryEvent$ = new Subject(); const addRepository$ = addRepositoryEvent$.pipe( switchMap(repository => { return addRepositoryGraphql( repository.name, repository.uri, repository.priority ).pipe( tap(() => { repository.complete(); }) ); }), catchError(error => { // Add the error as value and continue return addRepository$.pipe( startWith({ error: getErrorMessage(error.response), pendingRequest: false }) ); }) ); const RepositoriesAdd = componentFromStream(props$ => { return props$.pipe( combineLatest(addRepository$.pipe(startWith({})), (props, result) => { return (
}); const deleteEvent$ = new Subject(); const deleteRepository$ = deleteEvent$.pipe( switchMap(repository => { return removePackageRepositoryGraphql(repository.name, repository.url).pipe( startWith({ pendingRequest: true }), map(result => { return { result, pendingRequest: false }; }), tap(() => { repository.complete(); }) ); }), startWith({ pendingRequest: false }), catchError(error => { return deleteRepository$.pipe( startWith({ error: getErrorMessage(error.response), pendingRequest: false }) ); }) ); const RepositoriesDelete = componentFromStream(props$ => { return props$.pipe(