How to use the mobx-react.disposeOnUnmount function in mobx-react

To help you get started, we’ve selected a few mobx-react 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 ixrock / XTranslate / src / components / input-translation / input-translation.tsx View on Github external
async componentDidMount() {
    if (this.text) this.translate();
    this.input.focus();

    var activeTab = await getActiveTab();
    sendTabMessage(activeTab.id, {
      type: MessageType.GET_SELECTED_TEXT
    });
    onMessage(({ payload, type }) => {
      if (type === MessageType.SELECTED_TEXT) {
        this.translateText(payload);
      }
    });
    // auto-translate when affecting params to translate is changing
    disposeOnUnmount(this, [
      reaction(() => [this.favorite, toJS(this.params)], () => {
        if (this.translation) this.translate();
      }, { delay: 100 })
    ]);
  }
github NUbots / NUsight2 / src / client / components / localisation / nugus_robot / stories / nugus_robot.stories.tsx View on Github external
private createModel() {
    const robotModel = RobotModel.of({
      id: 'Darwin #1',
      connected: true,
      enabled: true,
      name: 'Darwin #1',
      address: '127.0.0.1',
      port: 1234,
    })
    const model = LocalisationRobotModel.of(robotModel)
    this.props.animate && disposeOnUnmount(this, reaction(
      () => 2 * Math.PI * now('frame') / 1000,
      t => this.simulateWalk(model, t),
      { fireImmediately: true },
    ))
    return computed(() => NUgusViewModel.of(model).robot, { equals: () => false })
  }
github NUbots / NUsight2 / src / client / components / classifier / classified_image / stories / classified_image.stories.tsx View on Github external
async componentDidMount() {
    const image = await loadImage(imageUrl)
    runInAction(() => this.props.model.rawImage = { type: 'image', image })
    disposeOnUnmount(this, reaction(() => this.props.animate && now('frame'), this.update))
  }
github FH-Potsdam / shifted-maps / components / Visualisation / PlaceCircleLabel.tsx View on Github external
componentDidMount() {
    this.labelCanvas = document.createElement('canvas');
    this.ctx = this.labelCanvas.getContext('2d');

    disposeOnUnmount(this, autorun(this.drawLabel));

    this.checkFont();
  }
github NUbots / NUsight2 / src / client / components / robot_selector / stories / robot_selector.stories.tsx View on Github external
componentDidMount() {
    disposeOnUnmount(this, reaction(
      () => now('frame'),
      this.updateStats,
      { fireImmediately: true },
    ))
  }
}
github NUbots / NUsight2 / src / client / components / localisation / view.tsx View on Github external
componentDidMount(): void {
    document.addEventListener('pointerlockchange', this.onPointerLockChange, false)
    document.addEventListener('mousemove', this.onMouseMove, false)
    document.addEventListener('keydown', this.onKeyDown, false)
    document.addEventListener('keyup', this.onKeyUp, false)
    document.addEventListener('wheel', this.onWheel, false)
    disposeOnUnmount(this, reaction(() => now('frame'), this.onAnimationFrame))
  }
github NUbots / NUsight2 / src / client / components / classifier / visualizer / stories / visualizer.stories.tsx View on Github external
componentDidMount() {
    disposeOnUnmount(this, reaction(() => now('frame'), this.update))
  }
github NUbots / NUsight2 / src / client / components / three / three.tsx View on Github external
componentDidMount() {
    this.renderer = new WebGLRenderer({ canvas: this.ref!, antialias: true })
    const stage = this.props.stage(this.canvas)
    disposeOnUnmount(this, autorun(() => this.renderStage(stage.get()), { scheduler: requestAnimationFrame }))
  }
github NUbots / NUsight2 / src / client / components / three / stories / three.stories.tsx View on Github external
componentDidMount() {
    this.update(0)
    this.props.animate && disposeOnUnmount(this, reaction(() => now('frame'), this.update))
  }
github ixrock / XTranslate / src / components / animate / animate.tsx View on Github external
componentDidMount() {
    disposeOnUnmount(this, [
      reaction(() => this.props.enter, enter => {
        if (enter) this.enter();
        else this.leave();
      }, {
        delay: Animate.VISIBILITY_DELAY_MS,
        fireImmediately: true,
      })
    ])
  }