How to use the rxjs.Subject function in rxjs

To help you get started, we’ve selected a few rxjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SchweizerischeBundesbahnen / scion-workbench / projects / scion / microfrontend-platform / src / lib / client / ɵmessage-client.ts View on Github external
return new Observable((observer: Observer): TeardownLogic => {
      const unsubscribe$ = new Subject();
      const deliveryError$ = new Subject();

      // Wait until the message is delivered.
      merge(this._brokerGateway.message$, deliveryError$)
        .pipe(
          filterByTopic(messageId),
          first(),
          timeoutWith(new Date(Date.now() + this._config.deliveryTimeout), throwError(`[MessageDispatchError] Broker did not report message delivery state within the ${this._config.deliveryTimeout}ms timeout. [message=${JSON.stringify(envelope)}]`)),
          takeUntil(merge(this._destroy$, unsubscribe$)),
          mergeMap(statusMessage => statusMessage.body.ok ? EMPTY : throwError(statusMessage.body.details)),
        )
        .subscribe(observer); // dispatch next, error and complete

      // Dispatch the message to the broker.
      this._brokerGateway.postMessage(envelope).catch(error => deliveryError$.error(error));

      return (): void => unsubscribe$.next();
github Azure / pcs-remote-monitoring-webui / src / components / pages / devices / flyouts / deviceDetails / deviceDetails.js View on Github external
showRawMessage: false,
      currentModuleStatus: undefined
    };
    this.baseState = this.state;
    this.columnDefs = [
      {
        ...rulesColumnDefs.ruleName,
        cellRendererFramework: undefined // Don't allow soft select from an open flyout
      },
      rulesColumnDefs.severity,
      rulesColumnDefs.alertStatus,
      rulesColumnDefs.explore
    ];

    this.resetTelemetry$ = new Subject();
    this.telemetryRefresh$ = new Subject();
    if (this.props.moduleStatus) {
      this.state = {
        ...this.state,
        currentModuleStatus: this.props.moduleStatus
      };
    } else {
      this.props.fetchModules(this.props.device.id);
    }
  }
github sourcegraph / sourcegraph / browser / src / shared / backend / search.tsx View on Github external
export const createSuggestionFetcher = (
    first = 5,
    requestGraphQL: PlatformContext['requestGraphQL']
): ((input: SuggestionInput) => void) => {
    const fetcher = new Subject()

    fetcher
        .pipe(
            distinctUntilChanged(),
            debounceTime(200),
            switchMap(({ query, handler }) =>
                fetchSuggestions(query, first, requestGraphQL).pipe(
                    take(first),
                    map(createSuggestion),
                    // createSuggestion will return null if we get a type we don't recognize
                    filter((f): f is Suggestion => !!f),
                    toArray(),
                    map((suggestions: Suggestion[]) => ({
                        suggestions,
                        suggestHandler: handler,
                    })),
github canalplus / rx-player / src / core / buffers / buffer_orchestrator.ts View on Github external
function manageEveryBuffers(
    bufferType : IBufferType,
    basePeriod : Period
  ) : Observable {
    // Each Period for which there is currently a Buffer, chronologically
    const periodList = new SortedList((a, b) => a.start - b.start);
    const destroyBuffers$ = new Subject();
    let hasLoadedABuffer = false; // true after the first PeriodBuffer is ready

    /**
     * @param {Object} period
     * @returns {Observable}
     */
    function launchConsecutiveBuffersForPeriod(
      period : Period
    ) : Observable {
      return manageConsecutivePeriodBuffers(bufferType, period, destroyBuffers$).pipe(
        tap((message) => {
          if (message.type === "periodBufferReady") {
            if (!hasLoadedABuffer) {
              hasLoadedABuffer = true;
            }
            periodList.add(message.value.period);
github DestinyItemManager / DIM / src / app / inventory / d2-stores.ts View on Github external
function makeD2StoresService(): D2StoreServiceType {
  let _stores: D2Store[] = [];

  // A subject that keeps track of the current account. Because it's a
  // behavior subject, any new subscriber will always see its last
  // value.
  const accountStream = new BehaviorSubject(null);

  // The triggering observable for force-reloading stores.
  const forceReloadTrigger = new Subject();

  // A stream of stores that switches on account changes and supports reloading.
  // This is a ConnectableObservable that must be connected to start.
  const storesStream = accountStream.pipe(
    // Only emit when the account changes
    distinctUntilChanged(compareAccounts),
    // But also re-emit the current value of the account stream
    // whenever the force reload triggers
    merge(forceReloadTrigger.pipe(switchMap(() => accountStream.pipe(take(1))))),
    // Whenever either trigger happens, load stores
    switchMap(loadingTracker.trackPromise(loadStores)),
    // Keep track of the last value for new subscribers
    publishReplay(1)
  ) as ConnectableObservable;

  // TODO: If we can make the store structures immutable, we could use
github esrlabs / chipmunk / application / client.core / src / app / environment / services / service.hotkeys.ts View on Github external
export class HotkeysService implements IService {

    private _logger: Toolkit.Logger = new Toolkit.Logger('HotkeysService');
    private _subscriptions: { [key: string]: Toolkit.Subscription | Subscription } = {};
    private _dialogGuid: string = Toolkit.guid();
    private _paused: boolean = false;
    private _input: boolean = false;

    private _subjects = {
        newTab: new Subject(),
        closeTab: new Subject(),
        openTextFile: new Subject(),
        openDltFile: new Subject(),
        focusSearchInput: new Subject(),
        openSearchFiltersTab: new Subject(),
        selectNextRow: new Subject(),
        selectPrevRow: new Subject(),
        focusMainView: new Subject(),
        focusSearchView: new Subject(),
        showHotkeysMapDialog: new Subject(),
        sidebarToggle: new Subject(),
        toolbarToggle: new Subject(),
        recentFiles: new Subject(),
        recentFilters: new Subject(),
    };

    constructor() {
    }

    public init(): Promise {
        return new Promise((resolve) => {
github ReactiveX / rxjs / src / internal / Subject-spec.ts View on Github external
it('should pump values to multiple subscribers', (done: MochaDone) => {
    const subject = new Subject();
    const expected = ['foo', 'bar'];

    let i = 0;
    let j = 0;

    subject.subscribe(function (x) {
      expect(x).to.equal(expected[i++]);
    });

    subject.subscribe(function (x) {
      expect(x).to.equal(expected[j++]);
    }, null, done);

    subject.next('foo');
    subject.next('bar');
    subject.complete();
github esrlabs / chipmunk / application / client.libs / chipmunk.client.components / projects / chipmunk-client-complex / src / lib / docking / service.ts View on Github external
parent: DockDef.Container | null;
}

interface IContainerData {
    target: DockDef.Container;
    parent: DockDef.Container | null;
    key: string;
}

export class DocksService {

    private _subjects = {
        dock: new Subject(),
        resized: new Subject(),
        moved: new Subject(),
        resizeStarted: new Subject(),
        resizeFinished: new Subject(),
        dragStarted: new Subject(),
        dragFinished: new Subject(),
        dragOver: new Subject(),
        dragDrop: new Subject(),
    };
    private _dock: DockDef.Container;
    private _sessionId: string = '';

    constructor(sessionId: string, dock: DockDef.Container) {
        this._sessionId = sessionId;
        this._dock = dock;
    }

    public destroy() {
    }
github gvergnaud / evolui / example / src / components / StateManagement.js View on Github external
get(obj, key) {
      return obj[key] ? obj[key] : obj[key] = new Subject()
    }
  })
github mapillary / mapillary-js / src / component / marker / MarkerSet.ts View on Github external
constructor() {
        this._hash = {};
        this._index = rbush(16, [".lon", ".lat", ".lon", ".lat"]);

        this._indexChanged$ = new Subject();
        this._updated$ = new Subject();
    }