How to use the mobx-utils.fromResource function in mobx-utils

To help you get started, we’ve selected a few mobx-utils 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 OpenZeppelin / crafty / app / src / util.js View on Github external
export const createFromEthereumBlock = (blockNumber) => (initial, dataFn, fn) => {
  let disposer
  let isBusy = observable.box(false)
  const resource = fromResource(
    (sink) => {
      disposer = reaction(
        () => [dataFn(), blockNumber],
        async ([data]) => {
          try {
            runInAction(() => isBusy.set(true))
            sink(await fn(data))
          } catch (error) {
            // @TODO(handle errors)
            console.error(error)
            debugger
          } finally {
            runInAction(() => isBusy.set(false))
          }
        },
        { fireImmediately: true }
github PacktPublishing / MobX-Quick-Start-Guide / src / Chapter08 / fromResource.js View on Github external
constructor() {
            this.data = fromResource(
                async sink => {
                    this.socket = new WebSocketConnection();
                    await this.socket.subscribe('data');

                    const result = await this.socket.get();

                    sink(result);
                },
                () => {
                    this.socket.unsubscribe('data');
                    this.socket = null;
                },
            );
        }
    }