rxjs#of TypeScript Examples
The following examples show how to use
rxjs#of.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: home.component.spec.ts From one-platform with MIT License | 6 votes |
describe('HomeComponent', () => {
let component: HomeComponent;
let fixture: ComponentFixture<HomeComponent>;
const appService = {
autorun: jest.fn(() => of({})),
fetchProjects: jest.fn(() => Promise.resolve({ listLHProjects: [] })),
};
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [HomeComponent],
imports: [
RouterTestingModule,
FormsModule,
SharedModule,
ApolloTestingModule,
ReactiveFormsModule,
],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
providers: [
{ provide: PlaygroundService, useValue: appService },
{ provide: 'Window', useValue: window },
Apollo,
],
}).compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(HomeComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
Example #2
Source File: gas-settings.component.ts From gnosis.1inch.exchange with MIT License | 6 votes |
ngOnInit(): void {
this.gasPrice$ = this.txSpeedSelect.valueChanges.pipe(
switchMap((txSpeed: TxSpeed) => {
console.log(`txSpeed=`, txSpeed);
if (txSpeed !== 'custom') {
return of(this.getGasPrice(txSpeed));
}
return this.gasPriceInput.valueChanges.pipe(
startWith(this.gasPriceInput.value),
filter(() => !this.gasPriceInput.errors),
map((value) => {
this.customGasPrice = value;
return [formatGasPrice(value), value];
})
);
}),
map(([gasPriceBN, gasPrice]) => {
this.gasPriceChange.next({
gasPriceBN,
gasPrice,
txSpeed: this.txSpeedSelect.value
});
return gasPrice;
}),
shareReplay({ bufferSize: 1, refCount: true })
);
this.subscription.add(
this.gasPrice$.subscribe()
);
}
Example #3
Source File: websocket-client.ts From closer-sdk.js with MIT License | 6 votes |
/**
* Cold observable
* @param command Message
*/
public ask(command: roomCommand.SendMessage | roomCommand.SendCustomMessage): Observable<chatEvents.Received> {
const ref = this.uuidGenerator.next();
const newCommand = { ...command, ref };
return merge(
of(newCommand).pipe(
tap((cmd: typeof newCommand) => this.send(cmd)),
ignoreElements(),
),
this.connection$.pipe(
filter(chatEvents.Received.isReceived),
filter(rec => rec.ref === ref),
),
this.connection$.pipe(
filter(errorEvents.Error.isError),
filter(rec => rec.ref === ref),
mergeMap(err => throwError(err, undefined)),
),
).pipe(
timeout(this.askTimeoutMs),
take(1),
);
}
Example #4
Source File: is-there-wallets.guard.ts From xBull-Wallet with GNU Affero General Public License v3.0 | 6 votes |
guardLogic(): Observable<boolean | UrlTree> {
return this.walletsQuery.isThereWallet$
.pipe(switchMap(status => {
if (!!status) {
return of(true);
}
return this.router.navigate(['/create-account'])
.then(_ => false);
}));
}
Example #5
Source File: auth.service.ts From rubic-app with GNU General Public License v3.0 | 6 votes |
private activateProviderAndSignIn(address: string): Observable<void> {
return from(this.walletConnectorService.activate()).pipe(
switchMap(() => {
if (compareAddresses(address, this.walletConnectorService.address)) {
this.currentUser$.next({ address: this.walletConnectorService.address });
return of() as Observable<void>;
}
return this.serverlessSignIn();
})
);
}
Example #6
Source File: builder.ts From nx-plugins with MIT License | 6 votes |
export function runBuilder(
options: NxDeployItDeployBuilderSchema,
context: BuilderContext
): Observable<BuilderOutput> {
if (!context?.target?.project) {
return of({ success: false });
}
const configuration = context.target.configuration || 'dev';
const project = getProjectConfig(context);
const applicationType = getApplicationType(project.architect);
return from(context.getTargetOptions(context.target)).pipe(
switchMap((targetOptions: DeployTargetOptions) => {
const cwd = dirname(
resolve(context.workspaceRoot, targetOptions.main as string)
);
createStackIfNotExist(cwd, configuration, context.target.project);
const adapter = getAdapterByApplicationType(
applicationType,
project,
options
);
return adapter.deploy(
context,
cwd,
options,
configuration,
targetOptions
);
})
);
}
Example #7
Source File: auth.service.ts From ng-devui-admin with MIT License | 6 votes |
login(account: string, password: string) {
for (let i = 0; i < USERS.length; i++) {
if (account === USERS[i].account && password === USERS[i].password) {
let { userName, gender, phoneNumber, email } = USERS[i];
let userInfo: User = { userName, gender, phoneNumber, email };
return of(userInfo);
}
}
return throwError('Please make sure you have input correct account and password');
}
Example #8
Source File: index.ts From dbm with Apache License 2.0 | 6 votes |
/**
* Write a file, but only if the contents changed
*
* @param file - File
* @param data - File data
*
* @returns File observable
*/
export function write(file: string, data: string): Observable<string> {
let contents = cache.get(file)
if (contents === data) {
return of(file)
} else {
cache.set(file, data)
return defer(() => fs.writeFile(file, data))
.pipe(
mapTo(file),
process.argv.includes("--verbose")
? tap(file => console.log(`${now()} + ${file}`))
: identity
)
}
}
Example #9
Source File: ajax-flow.ts From RcloneNg with MIT License | 6 votes |
protected requestCache(pre: CombErr<Tin>): Observable<CombErr<Tout>> {
return ajax(this.requestAjax(pre)).pipe(
map(x => [{ ajaxRsp: x }, []] as CombErr<AjaxFlowInteralNode>),
catchError(
(err): Observable<CombErr<AjaxFlowInteralNode>> =>
of([{}, [err]] as CombErr<AjaxFlowInteralNode>)
),
map(x => this.reconstructAjaxResult(x))
);
}
Example #10
Source File: pages.service.ts From FireAdmin with MIT License | 6 votes |
private pipePages(pagesObservable: Observable<Page[]>) {
return pagesObservable.pipe(mergeMap(async (pages: Page[]) => {
const activeSupportedLanguages = this.settings.getActiveSupportedLanguages().map((lang: Language) => lang.key);
//pages.forEach((page: Page) => { // forEach loop doesn't seems to work well with async/await
for (let page of pages) {
// console.log(page);
page.translations = page.translationId ? await this.getTranslations(page.translationId).pipe(take(1)).toPromise() : {};
// console.log(page.translations);
const pageLanguages = Object.keys(page.translations);
page.author = page.createdBy ? this.users.getFullName(page.createdBy) : of(null);
page.isTranslatable = !activeSupportedLanguages.every((lang: string) => pageLanguages.includes(lang));
}
//});
return pages;
}));
}
Example #11
Source File: fake-backend.service.ts From ng-conf-2020-workshop with MIT License | 6 votes |
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
this.users = JSON.parse(this.localStorage.getItem('users')) || [];
return of(null).pipe(mergeMap(() => {
// login user
if (request.url.endsWith('/login') && request.method === 'POST') {
return this.loginHandle(request);
}
// register user
if (request.url.endsWith('/register') && request.method === 'POST') {
const user = this.getStorageUser(request);
return this.registerHandle(user);
}
// login user with external provider
if (request.url.endsWith('/extlogin') && request.method === 'POST') {
const user = this.getStorageExtUser(request);
return this.registerHandle(user, true);
}
// Microsoft-specific OIDC discovery URI
if (request.url.endsWith('ms-discovery/keys') && request.method === 'GET') {
return of(new HttpResponse({ status: 200, body: msKeys }));
}
return next.handle(request);
}))
.pipe(materialize())
.pipe(dematerialize());
}