rxjs#from TypeScript Examples

The following examples show how to use rxjs#from. 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: emote.component.ts    From App with MIT License 6 votes vote down vote up
/**
	 * Get all sizes of the current emote
	 */
	getSizes(): Observable<EmoteComponent.SizeResult[]> {
		return from([1, 2, 3, 4]).pipe(
			map(s => ({
				scope: s,
				url: this.restService.CDN.Emote(String(this.emote?.getID()), s),
				width: this.emote?.width[s - 1],
				height: this.emote?.height[s - 1]
			} as EmoteComponent.SizeResult)),
			toArray()
		);
	}
Example #2
Source File: ApiService.ts    From argo-react with MIT License 6 votes vote down vote up
getPinataPinDetails = (id: any): Observable<any> => {
  return defer(() => {
    return from<Promise<any>>(
      fetch(`${config.urls.API_URL}/deploymentData/pinata/pins/${id}`, {
        headers: {
          "Content-Type": "application/json; charset=utf-8",
          Authorization: `Bearer ${localStorage.getItem("jwt-token")}`,
        },
        method: "GET",
      }).then((res) => res.json()),
    );
  });
}
Example #3
Source File: route.component.ts    From router with MIT License 6 votes vote down vote up
private loadAndRender(route: Route) {
    if (route.load) {
      return from(
        route
          .load()
          .then(
            (componentOrModule: NgModuleRef<ModuleWithRoute> | Type<any>) => {
              let component: Type<any>;

              if ((componentOrModule as any).ɵmod) {
                const moduleRef: NgModuleRef<ModuleWithRoute> =
                  createNgModuleRef(
                    componentOrModule as Type<any>,
                    this.viewContainerRef.injector
                  );
                component = moduleRef.instance.routeComponent;
              } else {
                component = componentOrModule as Type<any>;
              }

              this.renderComponent(component);
            }
          )
      );
    } else {
      this.showTemplate();
      return of(true);
    }
  }
Example #4
Source File: wowup-api.service.ts    From WowUp with GNU General Public License v3.0 6 votes vote down vote up
public getBlockList(): Observable<BlockListRepresentation> {
    const cached = this._cacheService.get<BlockListRepresentation>(BLOCKLIST_CACHE_KEY);
    if (cached) {
      return of(cached);
    }

    const url = new URL(`${API_URL}/blocklist`);

    return from(this._circuitBreaker.getJson<BlockListRepresentation>(url)).pipe(
      tap((response) => {
        this._cacheService.set(BLOCKLIST_CACHE_KEY, response, BLOCKLIST_CACHE_TTL_SEC);
      })
    );
  }
Example #5
Source File: myhttpinterceptor.ts    From CloudeeCMS with Apache License 2.0 6 votes vote down vote up
intercept(req: HttpRequest<any>, next: HttpHandler) {
    // only intercept requests towards API-GW
    if (req.url.search(environment.API_Gateway_Endpoint) === -1) {
      return next.handle(req);
    } else {

      return from(Auth.currentSession()).pipe(
        switchMap(data => {
          const headers = req.headers.set('Authorization', data.getIdToken().getJwtToken());
          const requestClone = req.clone({ headers });
          return next.handle(requestClone);
        })
      );
    }
  }
Example #6
Source File: user.structure.ts    From App with MIT License 6 votes vote down vote up
/**
	 * Get emote aliases of the user
	 */
	getEmoteAliases(): Observable<UserStructure.EmoteAlias[]> {
		return this.dataOnce().pipe(
			switchMap(data => from(data?.emote_aliases ?? [])),
			map(a => ({
				emoteID: a[0],
				name: a[1]
			} as UserStructure.EmoteAlias)),
			toArray()
		);
	}
Example #7
Source File: microfrontend-platform.ts    From scion-microfrontend-platform with Eclipse Public License 2.0 6 votes vote down vote up
private static installClientStartupProgressMonitor(): void {
    const monitor = new ProgressMonitor();
    MicrofrontendPlatform.whenState(PlatformState.Started).then(() => {
      monitor.done();
    });
    MicrofrontendPlatform.whenState(PlatformState.Stopped).then(() => {
      MicrofrontendPlatform._startupProgress$ = new Subject<number>();
    });

    monitor.progress$
      .pipe(takeUntil(from(MicrofrontendPlatform.whenState(PlatformState.Started))))
      .subscribe(MicrofrontendPlatform._startupProgress$);
  }
Example #8
Source File: popover.service.ts    From mylog14 with GNU General Public License v3.0 6 votes vote down vote up
private presentPopover(popover: HTMLIonPopoverElement, dismissTime?: number): Observable<any> {
    const manualDismiss$ = defer(() => popover.present())
      .pipe(
        switchMap(() => from(popover.onDidDismiss())),
      );
    const autoDismiss$ = defer(() => popover.present())
      .pipe(
        delay(dismissTime),
        switchMap(() => popover.dismiss()),
      );
    return (dismissTime) ? autoDismiss$ : manualDismiss$;
  }
Example #9
Source File: index.ts    From dbm with Apache License 2.0 6 votes vote down vote up
/**
 * Copy all files matching the given pattern
 *
 * Note that this function rebases all files that match the pattern to the
 * target folder, even if the pattern resolves to a parent folder.
 *
 * @param pattern - Pattern
 * @param options - Options
 *
 * @returns File observable
 */
export function copyAll(
  pattern: string, options: CopyOptions
): Observable<string> {
  return resolve(pattern, { ...options, cwd: options.from })
    .pipe(
      mergeMap(file => copy({
        ...options,
        from: `${options.from}/${file}`,
        to:   `${options.to}/${file.replace(/(\.{2}\/)+/, "")}`
      }), 16)
    )
}
Example #10
Source File: liquidity-providing.service.ts    From rubic-app with GNU General Public License v3.0 6 votes vote down vote up
public transfer(tokenId: string, address: string): Observable<unknown> {
    return from(
      this.web3PrivateService[BLOCKCHAIN_NAME.BINANCE_SMART_CHAIN].tryExecuteContractMethod(
        this.lpContractAddress,
        LP_PROVIDING_CONTRACT_ABI,
        'transfer',
        [address, tokenId]
      )
    ).pipe(
      catchError((error: unknown) => {
        this.errorService.catchAnyError(error as RubicError<ERROR_TYPE.TEXT>);
        return EMPTY;
      }),
      tap(() => {
        this.setDepositsLoading(true);

        const updatedDeposits = this.deposits.filter(deposit => deposit.tokenId !== tokenId);
        this._deposits$.next(updatedDeposits);
      })
    );
  }