How to use the @bentley/bentleyjs-core.using function in @bentley/bentleyjs-core

To help you get started, we’ve selected a few @bentley/bentleyjs-core 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 imodeljs / imodeljs / ui / components / src / ui-components / tree / component / Tree.tsx View on Github external
private async handleCheckboxes(prevProps: TreeProps, newProps: TreeProps, force?: boolean) {
    const checkboxInfoChanged = (prevProps.checkboxInfo !== newProps.checkboxInfo);
    if ((force || checkboxInfoChanged) && newProps.checkboxInfo) {
      // note: using `pauseRendering()` here - need it to fire `ChangesApplied`
      // event after checkboxes are asynchronously updated
      await using((this.state.model.pauseRendering()), async (_r) => {
        // note: calling this may actually mutate `model` in state - in
        // that case a `ChangesApplied` event will be emitted and the
        // `_onModelChanged` callback will be called
        await this.state.model.updateTreeCheckboxes(newProps.checkboxInfo!);
      });
    }
  }
github imodeljs / imodeljs / presentation / components / src / tree / WithFilteringSupport.tsx View on Github external
private async loadDataProvider(filter: string) {
      if (this._asyncsTracker.pendingAsyncs.size > 0) {
        // avoid excessive filtering requests while previous request is still in progress
        return;
      }

      const filterBeingApplied = createFilterKey(this.props.dataProvider, filter);
      const nodePaths = await using(this._asyncsTracker.trackAsyncTask(), async (_r) => {
        return this.props.dataProvider.getFilteredNodePaths(filter);
      });

      const currFilter = createFilterKey(this.props.dataProvider, this.props.filter);
      if (!_.isEqual(currFilter, filterBeingApplied)) {
        if (currFilter.filter) {
          // the filter has changed while we were waiting for `getFilteredNodePaths` result - need
          // to restart the load
          await this.loadDataProvider(currFilter.filter);
        } else {
          // the filter has been cleared while we were waiting for `getFilteredNodePaths` result - the
          // state should already be cleared so we can just return
        }
        return;
      }
github imodeljs / imodeljs / ui / components / src / ui-components / breadcrumb / breadcrumbdetails / BreadcrumbDetails.tsx View on Github external
private _onTreeNodeChanged = (_items: Array) => {
    using((this._tree as any).pauseRendering(), async () => { // tslint:disable-line:no-floating-promises
      await this._tree.reload();
    });
  }
github imodeljs / imodeljs / presentation / testing / src / ContentBuilder.ts View on Github external
public async createContent(rulesetOrId: Ruleset | string, instanceKeys: InstanceKey[], displayType: string = DefaultContentDisplayTypes.PropertyPane) {
    if (typeof rulesetOrId === "string")
      return this.doCreateContent(rulesetOrId, instanceKeys, displayType);

    return using(await Presentation.presentation.rulesets().add(rulesetOrId), async (ruleset: RegisteredRuleset) => {
      return this.doCreateContent(ruleset.id, instanceKeys, displayType);
    });
  }
github imodeljs / imodeljs / ui / components / src / ui-components / tree / component / BeInspireTree.ts View on Github external
private updateSelection(selectHandler: (predicate: Inspire.NodeIteratee) => void, nodesToSelect: string[] | ((payload: TNodePayload) => boolean) | undefined, muteEvents: boolean) {
    const predicate = this.createSelectedNodePredicate(nodesToSelect);
    if (!predicate)
      return;

    using(this.mute((muteEvents) ? [BeInspireTreeEvent.NodeSelected, BeInspireTreeEvent.NodeDeselected] : []), (_r) => {
      this._tree.disableDeselection();
      selectHandler(predicate);
      this._tree.enableDeselection();
    });
  }
github imodeljs / imodeljs / ui / components / src / ui-components / tree / component / BeInspireTree.ts View on Github external
public selectBetween(node1: BeInspireTreeNode, node2: BeInspireTreeNode, muteEvents = true): Array> {
    return using(this.mute((muteEvents) ? [BeInspireTreeEvent.NodeSelected] : []), (_r) => {
      const nodesBetween = this.getVisibleNodesBetween(node1, node2);
      nodesBetween.forEach((n) => n.select());
      return nodesBetween;
    });
  }
github imodeljs / imodeljs / ui / components / src / ui-components / tree / component / BeInspireTree.ts View on Github external
public async updateNodesCheckboxes(nodes: BeInspireTreeNodes, checkboxInfo: ((payload: TNodePayload) => CheckBoxInfo | Promise), muteEvents = true) {
    await using(this.pauseRendering(), async (_r1) => {
      await using(this.mute((muteEvents) ? [BeInspireTreeEvent.NodeChecked, BeInspireTreeEvent.NodeUnchecked] : []), async (_r2) => {
        const promises = new Array>();
        nodes.forEach((n) => {
          if (!n.payload)
            return;

          const status = checkboxInfo(n.payload);
          if (isPromiseLike(status))
            promises.push(status.then((s) => this.updateNodeCheckboxInfo(n, s)));
          else
            this.updateNodeCheckboxInfo(n, status);
        });
        if (promises.length !== 0)
          await Promise.all(promises);
      });
    });