How to use the react-async.globalScope.__REACT_ASYNC__ function in react-async

To help you get started, we’ve selected a few react-async 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 async-library / react-async / packages / react-async-devtools / src / index.js View on Github external
import React from "react"
import { ActionTypes, reducer, globalScope } from "react-async"

import { Root, Range, Checkbox, Label, Small, Ol, Li, Button } from "./components"

const storage = globalScope.sessionStorage

const state = {
  intercept: (storage && storage.getItem("intercept") === "true") || false,
  latency: (storage && storage.getItem("latency")) || "0",
  update: () => {},
}

globalScope.__REACT_ASYNC__.devToolsDispatcher = (action, dispatch) => {
  const run = () => {
    dispatch(action)
    state.update(action)
  }
  switch (action.type) {
    case ActionTypes.start:
      if (state.intercept) {
        dispatch({ ...action, payload: undefined })
        state.update(action, run)
      } else run()
      break
    case ActionTypes.fulfill:
    case ActionTypes.reject:
      setTimeout(run, state.latency * 1000)
      break
    default: