Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | 6x 6x 6x 6x 6x 6x 6x 6x 31x 31x 134x 144x 33x 6x | import { ModuleWithProviders, NgModule } from '@angular/core';
import { ReplaySubject } from 'rxjs';
import { map } from 'rxjs/operators';
import { NotRoleToggleDirective } from './directives/not-role-toggle.directive';
import { whenTruthy } from './utils/operators';
import { RoleToggleService, checkRole } from './utils/role-toggle/role-toggle.service';
@NgModule({
declarations: [NotRoleToggleDirective],
exports: [NotRoleToggleDirective],
})
export class RoleToggleModule {
private static roleIds$ = new ReplaySubject<string[]>(1);
static forTesting(...roleIds: string[]): ModuleWithProviders<RoleToggleModule> {
RoleToggleModule.switchTestingRoles(...roleIds);
return {
ngModule: RoleToggleModule,
providers: [
{
provide: RoleToggleService,
useValue: {
hasRole: (roleId: string | string[]) =>
RoleToggleModule.roleIds$.pipe(
whenTruthy(),
map(roles => checkRole(roles, roleId))
),
},
},
],
};
}
static switchTestingRoles(...roleIds: string[]) {
RoleToggleModule.roleIds$.next(roleIds);
}
}
export { RoleToggleService } from './utils/role-toggle/role-toggle.service';
|