rxjs#noop TypeScript Examples

The following examples show how to use rxjs#noop. 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: broker-gateway.ts    From scion-microfrontend-platform with Eclipse Public License 2.0 6 votes vote down vote up
public requestReply$<T = any>(channel: MessagingChannel, message: IntentMessage | TopicMessage): Observable<TopicMessage<T>> {
    return new Observable((observer: Observer<TopicMessage>): TeardownLogic => {
      if (isPlatformStopped()) {
        observer.error(GatewayErrors.PLATFORM_STOPPED_ERROR);
        return noop;
      }

      const replyTo = UUID.randomUUID();
      const unsubscribe$ = new Subject<void>();
      const requestError$ = new Subject<never>();

      // Add 'ReplyTo' topic to the message headers where to receive the response(s).
      message.headers.set(MessageHeaders.ReplyTo, replyTo);

      // Receive replies sent to the reply topic.
      merge(this.subscribeToTopic$<T>(replyTo), requestError$)
        .pipe(takeUntil(merge(this._platformStopping$, unsubscribe$)))
        .subscribe({
          next: reply => observer.next(reply),
          error: error => observer.error(error),
          complete: noop, // As per the API, the Observable never completes.
        });

      // Post the request to the broker.
      this.postMessage(channel, message)
        .catch(error => requestError$.error(error));

      return (): void => unsubscribe$.next();
    });
  }
Example #2
Source File: emote-list.component.ts    From App with MIT License 6 votes vote down vote up
onOpenCardContextMenu(emote: EmoteStructure): void {
		if (!this.contextMenu) {
			return undefined;
		}

		this.contextMenu.contextEmote = emote;
		emote.getOwner().pipe(
			tap(usr => !!this.contextMenu ? this.contextMenu.contextUser = (usr ?? null) : noop())
		).subscribe();
	}
Example #3
Source File: demos.ts    From alauda-ui with MIT License 6 votes vote down vote up
notify2() {
    const notificationRef = this.notificationService.success({
      title: '标题',
      footerRef: this.footerTpl,
      duration: 0,
    });
    notificationRef.instance.beforeClosed.subscribe(noop);
    notificationRef.instance.afterClosed.subscribe(noop);
  }
Example #4
Source File: table.tsx    From ali-react-table with MIT License 6 votes vote down vote up
static defaultProps = {
    hasHeader: true,
    isStickyHeader: true,
    stickyTop: 0,

    footerDataSource: [] as any[],
    isStickyFooter: true,
    stickyBottom: 0,
    hasStickyScroll: true,
    stickyScrollHeight: 'auto',

    useVirtual: 'auto',
    estimatedRowHeight: 48,

    isLoading: false,
    components: {},
    getRowProps: noop,
    dataSource: [] as any[],
  }
Example #5
Source File: switch-org.page.ts    From fyle-mobile-app with MIT License 6 votes vote down vote up
async switchOrg(org: Org) {
    const originalEou = await this.authService.getEou();
    from(this.loaderService.showLoader())
      .pipe(switchMap(() => this.orgService.switchOrg(org.id)))
      .subscribe(
        () => {
          globalCacheBusterNotifier.next();
          if (originalEou) {
            this.trackSwitchOrg(org, originalEou);
          }
          this.userEventService.clearTaskCache();
          this.recentLocalStorageItemsService.clearRecentLocalStorageCache();
          from(this.proceed()).subscribe(noop);
        },
        async (err) => {
          await this.secureStorageService.clearAll();
          await this.storageService.clearAll();
          this.userEventService.logout();
          globalCacheBusterNotifier.next();
          await this.loaderService.hideLoader();
        }
      );
  }
Example #6
Source File: angular-context.spec.ts    From s-libs with MIT License 6 votes vote down vote up
describe('extendMetadata', () => {
  it('allows animations to be unconditionally disabled', () => {
    @Component({ template: '' })
    class BlankComponent {}
    const ctx = new ComponentContext(BlankComponent, {
      imports: [BrowserAnimationsModule],
    });
    ctx.run(() => {
      expect(ctx.inject(ANIMATION_MODULE_TYPE)).toBe('NoopAnimations');
    });
  });

  it('allows the user to override providers', () => {
    const errorHandler = { handleError: noop };
    const ctx = new AngularContext({
      providers: [{ provide: ErrorHandler, useValue: errorHandler }],
    });
    ctx.run(() => {
      expect(ctx.inject(ErrorHandler)).toBe(errorHandler);
    });
  });
});
Example #7
Source File: table.d.ts    From yakit with GNU Affero General Public License v3.0 6 votes vote down vote up
static defaultProps: {
        hasHeader: boolean;
        isStickyHeader: boolean;
        stickyTop: number;
        footerDataSource: any[];
        isStickyFooter: boolean;
        stickyBottom: number;
        hasStickyScroll: boolean;
        stickyScrollHeight: string;
        useVirtual: string;
        estimatedRowHeight: number;
        isLoading: boolean;
        components: {};
        getRowProps: typeof noop;
        dataSource: any[];
    };
Example #8
Source File: admin.guard.ts    From App with MIT License 5 votes vote down vote up
private runGuard(): Observable<boolean> {
		return super.canLoad().pipe(
			switchMap(() => this.clientService.canAccessAdminArea()),
			tap(ok => ok ? noop() : this.router.navigate(['/'], {replaceUrl: true})),
			take(1)
		);
	}
Example #9
Source File: demos.ts    From alauda-ui with MIT License 5 votes vote down vote up
notify() {
    const notificationRef = this.notificationService.success({
      title: '标题',
      contentRef: this.template,
    });
    notificationRef.instance.beforeClosed.subscribe(noop);
    notificationRef.instance.afterClosed.subscribe(noop);
  }
Example #10
Source File: cross-tree-table.tsx    From ali-react-table with MIT License 5 votes vote down vote up
static defaultProps = {
    defaultOpenKeys: [] as string[],
    onChangeOpenKeys: noop,
  }
Example #11
Source File: app.component.ts    From fyle-mobile-app with MIT License 5 votes vote down vote up
ngOnInit() {
    if ((window as any) && (window as any).localStorage) {
      const lstorage = (window as any).localStorage;
      Object.keys(lstorage)
        .filter((key) => key.match(/^fyle/))
        .forEach((key) => lstorage.removeItem(key));
    }

    this.checkAppSupportedVersion();
    from(this.routerAuthService.isLoggedIn()).subscribe((loggedInStatus) => {
      if (loggedInStatus) {
        this.sidemenuRef.showSideMenu();
        this.pushNotificationService.initPush();
      }
    });

    this.userEventService.onSetToken(() => {
      setTimeout(() => {
        this.sidemenuRef.showSideMenu();
      }, 500);
    });

    this.userEventService.onLogout(() => {
      this.trackingService.onSignOut();
      this.freshChatService.destory();
      this.isSwitchedToDelegator = false;
      this.router.navigate(['/', 'auth', 'sign_in']);
    });

    this.setupNetworkWatcher();

    this.router.events.subscribe((ev) => {
      // adding try catch because this may fail due to network issues
      // noop is no op - basically an empty function
      try {
        this.trackingService.updateIdentityIfNotPresent().then(noop).catch(noop);
      } catch (error) {}

      if (ev instanceof NavigationStart) {
        this.previousUrl = this.router.url;
      }
      if (ev instanceof NavigationEnd) {
        if (
          ev.urlAfterRedirects.indexOf('enterprise') > -1 &&
          !(ev.urlAfterRedirects.indexOf('delegated_accounts') > -1)
        ) {
          setTimeout(() => this.menuController.swipeGesture(true), 500);
        } else {
          setTimeout(() => this.menuController.swipeGesture(false), 500);
        }
      }
    });
  }
Example #12
Source File: renew-script.component.ts    From dev-manager-desktop with Apache License 2.0 5 votes vote down vote up
saveScript(content: string): void {
    dialog.showSaveDialog(getCurrentWindow(), {
      defaultPath: `renew-devmode-${this.device.name}.sh`
    }).then(value => {
      // this.electron.fs.writeFileSync(value.filePath, content, { encoding: 'utf8', mode: 0o755 });
    }).catch(noop);
  }
Example #13
Source File: cross-tree-table.d.ts    From yakit with GNU Affero General Public License v3.0 5 votes vote down vote up
static defaultProps: {
        defaultOpenKeys: string[];
        onChangeOpenKeys: typeof noop;
    };
Example #14
Source File: message-interception.spec.ts    From scion-microfrontend-platform with Eclipse Public License 2.0 4 votes vote down vote up
describe('Message Interception', () => {

  let interceptor1: SpyObj<MessageInterceptor>;
  let interceptor2: SpyObj<MessageInterceptor>;
  let interceptor3: SpyObj<MessageInterceptor>;
  let publisher: Spy;
  let publishChain: PublishInterceptorChain<TopicMessage>;

  beforeEach(() => {
    interceptor1 = createSpyObj('interceptor-1', ['intercept']);
    interceptor1.intercept.and.callFake((message: TopicMessage, next: Handler<TopicMessage>) => next.handle(message));

    interceptor2 = createSpyObj('interceptor-2', ['intercept']);
    interceptor2.intercept.and.callFake((message: TopicMessage, next: Handler<TopicMessage>) => next.handle(message));

    interceptor3 = createSpyObj('interceptor-3', ['intercept']);
    interceptor3.intercept.and.callFake((message: TopicMessage, next: Handler<TopicMessage>) => next.handle(message));

    publisher = createSpy('publisher');
    publishChain = chainInterceptors([interceptor1, interceptor2, interceptor3], publisher);
  });

  it('should invoke the publisher even if no interceptors are given', async () => {
    publisher = createSpy('publisher');
    publishChain = chainInterceptors([], publisher);
    const message: TopicMessage = {headers: new Map(), topic: 'topic'};

    publishChain.publish(message);
    expect(publisher).toHaveBeenCalledWith(message);
  });

  it('should pass a message through the interceptors in registration order', async () => {
    const message: TopicMessage = {headers: new Map(), topic: 'topic'};
    publishChain.publish(message);

    // assert interceptor invocation arguments
    expect(interceptor1.intercept).toHaveBeenCalledWith(message, any(Handler));
    expect(interceptor2.intercept).toHaveBeenCalledWith(message, any(Handler));
    expect(interceptor3.intercept).toHaveBeenCalledWith(message, any(Handler));
    expect(publisher).toHaveBeenCalledWith(message);

    // assert interceptor invocation order
    expect(interceptor1.intercept).toHaveBeenCalledBefore(interceptor2.intercept);
    expect(interceptor2.intercept).toHaveBeenCalledBefore(interceptor3.intercept);
    expect(interceptor3.intercept).toHaveBeenCalledBefore(publisher);

    // assert interceptor being invoked only once
    expect(interceptor1.intercept).toHaveBeenCalledTimes(1);
    expect(interceptor2.intercept).toHaveBeenCalledTimes(1);
    expect(interceptor3.intercept).toHaveBeenCalledTimes(1);
    expect(publisher).toHaveBeenCalledTimes(1);
  });

  it('should allow to reject publishing by throwing an error', async () => {
    interceptor2.intercept.and.throwError('MESSAGE REJECTED BY INTERCEPTOR 2');

    // Run the test
    const message: TopicMessage = {headers: new Map(), topic: 'topic'};
    expect(() => publishChain.publish(message)).toThrowError(/MESSAGE REJECTED BY INTERCEPTOR 2/);

    // Verify
    expect(interceptor1.intercept).toHaveBeenCalledWith(message, any(Handler));
    expect(interceptor2.intercept).toHaveBeenCalledWith(message, any(Handler));
    expect(interceptor3.intercept).not.toHaveBeenCalled();
    expect(publisher).not.toHaveBeenCalled();
  });

  it('should allow to swallow a message by not calling the next handler', async () => {
    interceptor2.intercept.and.callFake(noop);

    // Run the test
    const message: TopicMessage = {headers: new Map(), topic: 'topic'};
    publishChain.publish(message);

    // Verify
    expect(interceptor1.intercept).toHaveBeenCalledWith(message, any(Handler));
    expect(interceptor2.intercept).toHaveBeenCalledWith(message, any(Handler));
    expect(interceptor3.intercept).not.toHaveBeenCalled();
    expect(publisher).not.toHaveBeenCalled();
  });

  it('should allow to modify a message', async () => {
    interceptor1.intercept.and.callFake((message: TopicMessage<string[]>, next: Handler<TopicMessage>) => {
      message.headers.set('HEADER_INTERCEPTOR_1', true);
      message.body.push('INTERCEPTOR_1');
      next.handle(message);
    });
    interceptor2.intercept.and.callFake((message: TopicMessage<string[]>, next: Handler<TopicMessage>) => {
      message.headers.set('HEADER_INTERCEPTOR_2', true);
      message.body.push('INTERCEPTOR_2');
      next.handle(message);
    });
    interceptor3.intercept.and.callFake((message: TopicMessage<string[]>, next: Handler<TopicMessage>) => {
      message.headers.set('HEADER_INTERCEPTOR_3', true);
      message.body.push('INTERCEPTOR_3');
      next.handle(message);
    });

    // Run the test
    const message: TopicMessage = {headers: new Map(), topic: 'topic', body: []};
    publishChain.publish(message);

    // Verify
    expect(interceptor1.intercept).toHaveBeenCalledWith(message, any(Handler));
    expect(interceptor2.intercept).toHaveBeenCalledWith(message, any(Handler));
    expect(interceptor3.intercept).toHaveBeenCalledWith(message, any(Handler));
    expect(publisher).toHaveBeenCalledWith({
      body: ['INTERCEPTOR_1', 'INTERCEPTOR_2', 'INTERCEPTOR_3'],
      headers: new Map().set('HEADER_INTERCEPTOR_1', true).set('HEADER_INTERCEPTOR_2', true).set('HEADER_INTERCEPTOR_3', true),
      topic: 'topic',
    } as TopicMessage);
  });
});
Example #15
Source File: buildCrossTreeTable.tsx    From ali-react-table with MIT License 4 votes vote down vote up
export default function buildCrossTreeTable(
  options: BuildCrossTreeTableOptions,
): Pick<BaseTableProps, 'columns' | 'dataSource'> {
  const {
    primaryColumn = { name: '' },
    openKeys,
    onChangeOpenKeys,
    indentSize,
    isLeafNode: isLeafNodeOpt = standardIsLeafNode,
  } = options

  // 有的时候 leftTree/topTree 是通过 node.children 传入的
  // 此时 leftTree/topTree 等于 null 和等于空数组是等价的
  // 故在这里兼容 leftTree/topTree 为空的情况
  const leftTree = options.leftTree ?? []
  const topTree = options.topTree ?? []

  const pipeline = new TablePipeline({
    state: {},
    setState: noop,
    ctx: { primaryKey: ROW_KEY },
  })

  pipeline.input({ dataSource: getDataSource(), columns: getColumns() })
  pipeline.use(
    features.treeMode({
      openKeys,
      onChangeOpenKeys,
      indentSize,
      isLeafNode(row: CrossTreeTableRenderRow, nodeMeta) {
        // 调用上层 isLeafNodeOpt 时,会从 row.node 中读取该表格行对应的 leftTreeNode
        return isLeafNodeOpt(row.node, nodeMeta)
      },
    }),
  )

  return {
    dataSource: pipeline.getDataSource(),
    columns: pipeline.getColumns(),
  }

  /** 获取表格的列配置 */
  function getColumns(): ArtColumn[] {
    return [
      {
        ...primaryColumn,
        getValue(row: CrossTreeTableRenderRow) {
          return row.node.value
        },
        getCellProps(value: any, row: any) {
          if (primaryColumn.getCellProps) {
            return primaryColumn.getCellProps(row.node, row.nodes.length - 1)
          }
        },
        render(value: any, row: any) {
          if (primaryColumn.render) {
            return primaryColumn.render(row.node, row.nodes.length - 1)
          }
          return value
        },
      },
      ...getDataPartColumns(),
    ]

    /** 获取表格数据部分的列配置 */
    function getDataPartColumns() {
      return dfs(topTree, { depth: 0 })

      function dfs(nodes: TopCrossTreeNode[], ctx: { depth: number }): ArtColumn[] {
        const result: ArtColumn[] = []

        for (const node of nodes) {
          if (standardIsLeafNode(node)) {
            result.push(getDataColumn(node, ctx.depth))
          } else {
            const { key, value, children, ...others } = node
            result.push({
              ...others,
              name: value,
              children: dfs(children, { depth: ctx.depth + 1 }),
            })
          }
        }

        return result
      }
    }

    function getDataColumn(topNode: TopCrossTreeNode, topDepth: number): ArtColumn {
      const columnGetValue = (row: CrossTreeTableRenderRow) => {
        const leftDepth = row.nodes.length - 1
        const leftNode = row.node
        if (options.getValue) {
          return options.getValue(leftNode, topNode, leftDepth, topDepth)
        }
        return null
      }
      const { key, value, children, ...others } = topNode
      return {
        ...others,
        getValue: columnGetValue,
        name: value,
        children: null,
        render(value: any, row: CrossTreeTableRenderRow) {
          if (options.render) {
            const leftDepth = row.nodes.length - 1
            const leftNode = row.node
            return options.render(value, leftNode, topNode, leftDepth, topDepth)
          }
          return value
        },
        getCellProps(value, row: CrossTreeTableRenderRow) {
          if (options.getCellProps) {
            const leftDepth = row.nodes.length - 1
            const leftNode = row.node
            return options.getCellProps(value, leftNode, topNode, leftDepth, topDepth)
          }
        },
      }
    }
  }

  function getDataSource(): CrossTreeTableRenderRow[] {
    return dfs(leftTree, { nodes: [] })

    function dfs(nodes: LeftCrossTreeNode[], ctx: { nodes: LeftCrossTreeNode[] }): CrossTreeTableRenderRow[] {
      const result: CrossTreeTableRenderRow[] = []

      for (const node of nodes) {
        if (node.hidden) {
          // 跳过被隐藏的节点
          continue
        }

        if (standardIsLeafNode(node)) {
          result.push({
            [ROW_KEY]: node.key,
            node,
            nodes: [...ctx.nodes, node],
          })
        } else {
          const nodes = [...ctx.nodes, node]
          ctx.nodes.push(node)
          const children = dfs(node.children, ctx)
          result.push({ [ROW_KEY]: node.key, node, nodes, children })
          ctx.nodes.pop()
        }
      }

      return result
    }
  }
}