Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
protected render(doc: DocumentContents): Observable {
let addTitleAndToc: () => void;
this.setNoIndex(doc.id === FILE_NOT_FOUND_ID || doc.id === FETCHING_ERROR_ID);
return this.void$.pipe(
// Security: `doc.contents` is always authored by the documentation team
// and is considered to be safe.
tap(() => this.nextViewContainer.innerHTML = doc.contents || ''),
tap(() => addTitleAndToc = this.prepareTitleAndToc(this.nextViewContainer, doc.id)),
switchMap(() => this.elementsLoader.loadContainedCustomElements(this.nextViewContainer)),
tap(() => this.docReady.emit()),
switchMap(() => this.swapViews(addTitleAndToc)),
tap(() => this.docRendered.emit()),
catchError(err => {
const errorMessage = (err instanceof Error) ? err.stack : err;
this.logger.error(new Error(`[DocViewer] Error preparing document '${doc.id}': ${errorMessage}`));
this.nextViewContainer.innerHTML = '';
this.setNoIndex(true);
return this.void$;
}),
);
}
private _subscribeToClosingActions(): Subscription {
const firstStable = this._zone.onStable.asObservable().pipe(first());
const optionChanges = this.dropdown.options.changes.pipe(
tap(() => this._positionStrategy.reapplyLastPosition()),
// Defer emitting to the stream until the next tick, because changing
// bindings in here will cause "changed after checked" errors.
delay(0)
);
// When the zone is stable initially, and when the option list changes...
return (
merge(firstStable, optionChanges)
.pipe(
// create a new stream of panelClosingActions, replacing any previous streams
// that were created, and flatten it so our stream only emits closing events...
switchMap(() => {
this._resetActiveItem();
this.dropdown.setVisibility();
if (this.panelOpen) {
// tslint:disable-next-line:no-non-null-assertion
this._overlayRef!.updatePosition();
}
return this.panelClosingActions;
}),
// when the first closing event occurs...
first()
)
// set the value, close the panel, and complete.
.subscribe(event => this._setValueAndClose(event))
);
callback: innerCreate,
parentMenu: preMenu,
allow_html: true
}, ref_window);
let taskFilter = new Subject();
function inputTerm(term: string) {
taskFilter.next(term);
}
bindInput();
let filterTrigger = taskFilter.pipe(
debounceTime(1000),
distinctUntilChanged(),
switchMap((term: string) => {
reGenerateMenu(term);
return 'whatever';
})
);
filterTrigger.subscribe();
//helpers
function reGenerateMenu(term: string) {
// close old task list menu and add a new one;
taskMenu.close(undefined, true);
let values = [];
values.push({content: filterInputHtml});
let filteredTaskNames = _.filter(self.taskInjectableNames, (type) => {
return _.toLower(type).includes(_.toLower(term));
});
for (let injectableName of filteredTaskNames.slice(0, 9)) {
switchMap(() => userService.credentialsExist()
.pipe(
switchMap(() => authService.refreshAuth()
.pipe(
switchMap((token) => of(authActions.refreshAuthSuccess(token))),
catchError((error) => [authActions.refreshAuthFail(error.message)])
)
)
)
)
delete(user: UserModel) {
this.confirmService.confirm({message: `Voulez-vous vraiment supprimer l\'utilisateur ${user.login}\u00A0?`}).pipe(
switchMap(() => this.userService.delete(user.id)),
switchMap(() => this.userService.list())
).subscribe(users => this.users = sortBy(users, u => u.login));
}
export class LabelEffects {
@Effect()
load = this.actions.pipe(
ofType(LabelActionTypes.LOAD), switchMap(action => {
return this.repositoryDatabase.getValues(action.payload.repository)
.labels.pipe(take(1), map(labels => new LoadLabelsComplete({labels})));
}));
/**
* After the items are loaded from the local database, request updates from GitHub periodically
* if the user is authenticated.
*/
@Effect({dispatch: false})
update = this.actions.pipe(
ofType(LabelActionTypes.LOAD),
switchMap(() => this.store.select(selectIsAuthenticated).pipe(take(1))),
tap(isAuthenticated => {
if (isAuthenticated) {
this.updater.update('labels');
}
}));
@Effect({dispatch: false})
persistGithubUpdatesToLocalDb = this.actions.pipe(
ofType(LabelActionTypes.UPDATE_FROM_GITHUB),
withLatestFrom(this.store.select(selectRepositoryName)), tap(([action, repository]) => {
this.repositoryDatabase.update(repository, 'labels', action.payload.labels);
}));
@Effect({dispatch: false})
persistRemoveAllToLocalDb = this.actions.pipe(
ofType(LabelActionTypes.REMOVE_ALL),
changePassword() {
this.passwordChangeFailed = false;
if (this.passwordChangeForm.invalid) {
return;
}
this.currentUserService.checkPassword(this.passwordChangeForm.value.oldPassword).pipe(
switchMap(() => this.currentUserService.changePassword(this.passwordChangeForm.value.newPassword))
).subscribe(
() => this.router.navigate(['/']),
() => this.passwordChangeFailed = true
);
}
}
run() {
this.activity$
.pipe(
take(1),
switchMap(task => this.testRunner.runFromTask({ taskId: task.id, inputs: task.input }))
).subscribe();
}
switchMap((authToken: ITokenExpiration) => timer(authToken.nextRefresh * 1000, authToken.refreshInterval * 1000)
.pipe(
takeWhile(() => state$.value.auth.isAuthenticated),
switchMap(() => userService.credentialsExist()
.pipe(
switchMap(() => authService.refreshAuth()
.pipe(
switchMap((token) => of(authActions.refreshAuthSuccess(token))),
catchError((error) => [authActions.refreshAuthFail(error.message)])
)
)
)
)
)
),
private getOrganizations(): Observable {
return this.store$.select(selectOrganizationsLoaded).pipe(
tap(loaded => {
if (!loaded) {
this.store$.dispatch(new OrganizationsAction.Get());
}
}),
filter(loaded => loaded),
switchMap(() => this.store$.select(selectAllOrganizations))
);
}