switchMap(({ type }) => { const state = state$.value; const meta = challengeMetaSelector(state); const { nextChallengePath, introPath, challengeType } = meta; const closeChallengeModal = of(closeModal('completion')); let submitter = () => of({ type: 'no-user-signed-in' }); if ( !(challengeType in submitTypes) || !(submitTypes[challengeType] in submitters) ) { throw new Error( 'Unable to find the correct submit function for challengeType ' + challengeType ); } if (isSignedInSelector(state)) { submitter = submitters[submitTypes[challengeType]]; } return submitter(type, state).pipe( tap(() => navigate(introPath ? introPath : nextChallengePath)), concat(closeChallengeModal), filter(Boolean) ); })
switchMap(tests => { return from(tests).pipe( map(({ message }) => message), filter(overEvery(isString, Boolean)), map(updateConsole), concat(of(updateTests(tests))) ); }),
subscribe() { const mesos$ = container.get(MesosStreamType); const masterRequest$ = container.get(MesosMasterRequestType).pipe( tap(response => { const master = mesosStreamParsers.getMaster( this.getMaster(), JSON.parse(response) ); CompositeState.addState(master); this.setMaster(master); }) ); const parsers = pipe(...Object.values(mesosStreamParsers)); const data$ = mesos$.pipe( merge(masterRequest$), distinctUntilChanged(), map(message => parsers(this.getLastMesosState(), JSON.parse(message))), tap(state => this.setState(state), console.error) ); const wait$ = masterRequest$.pipe(zip(mesos$.pipe(take(1)))); const eventTrigger$ = data$.pipe( merge( // A lot of DCOS UI rely on the MesosStateStore emitting // MESOS_STATE_CHANGE events. After the switch to the stream, we lost this // event. To avoid a deeper refactor, we introduced this fake emitter. // // TODO: https://jira.mesosphere.com/browse/DCOS-18277 interval(Config.getRefreshRate()) ) ); // Since we introduced the fake event above, we have to guarantee certain // refresh limits to the UI. They are: // // MOST once every (Config.getRefreshRate() * 0.5) ms. due to sampleTime. // LEAST once every tick of Config.getRefreshRate() ms in // Observable.interval // // TODO: https://jira.mesosphere.com/browse/DCOS-18277 this.stream = wait$ .pipe( concat(eventTrigger$), sampleTime(Config.getRefreshRate() * 0.5), retryWhen(linearBackoff(RETRY_DELAY, -1, MAX_RETRY_DELAY)) ) .subscribe( () => Promise.resolve().then(this.onStreamData), this.onStreamError ); }
switchMap(({ checkChallengePayload, tests }) => { const postTests = of( updateConsole('// tests completed'), 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) ); })
function submitProject(type, state) { if (type === types.checkChallenge) { return empty(); } const { solution, githubLink } = projectFormValuesSelector(state); const { id, challengeType } = challengeMetaSelector(state); const { username } = userSelector(state); const challengeInfo = { id, challengeType, solution }; if (challengeType === challengeTypes.backEndProject) { challengeInfo.githubLink = githubLink; } const update = { endpoint: '/project-completed', payload: challengeInfo }; return postChallenge(update, username).pipe( concat(of(updateProjectFormValues({}))) ); }