How to use the redux-bundler.createAsyncResourceBundle function in redux-bundler

To help you get started, we’ve selected a few redux-bundler 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 ipfs-shipyard / ipfs-webui / src / bundles / explore.js View on Github external
import { createAsyncResourceBundle, createSelector } from 'redux-bundler'
import { resolveIpldPath, quickSplitPath } from '../lib/path'

// Find all the nodes and path boundaries traversed along a given path
const bundle = createAsyncResourceBundle({
  name: 'explore',
  actionBaseType: 'EXPLORE',
  getPromise: async (args) => {
    const { store, getIpfs } = args
    const hash = store.selectHash()
    let path = decodeURIComponent(hash.replace('/explore', ''))
    if (!path) return null
    const { cidOrFqdn, rest } = quickSplitPath(path)
    const { targetNode, canonicalPath, localPath, nodes, pathBoundaries } = await resolveIpldPath(getIpfs, cidOrFqdn, rest)
    return {
      path,
      targetNode,
      canonicalPath,
      localPath,
      nodes,
      pathBoundaries
github ipfs-shipyard / ipfs-webui / src / bundles / peer-locations.js View on Github external
export default function (opts) {
  opts = opts || {}
  // Max number of locations to retrieve concurrently.
  // HTTP API are throttled to max 4-6 at a time by the browser itself.
  opts.concurrency = opts.concurrency || 4
  // Cache options
  opts.cache = opts.cache || {}

  const peerLocResolver = new PeerLocationResolver(opts)

  const bundle = createAsyncResourceBundle({
    name: 'peerLocations',
    actionBaseType: 'PEER_LOCATIONS',
    getPromise: async ({ store, getIpfs }) => {
      const peers = store.selectPeers()
      return peerLocResolver.findLocations(peers, getIpfs)
    },
    staleAfter: UPDATE_EVERY,
    retryAfter: UPDATE_EVERY,
    persist: false,
    checkIfOnline: false
  })

  bundle.reactPeerLocationsFetch = createSelector(
    'selectRouteInfo',
    'selectPeerLocationsShouldUpdate',
    'selectIpfsConnected',
github ipfs-shipyard / ipfs-webui / src / bundles / identity.js View on Github external
import { createAsyncResourceBundle, createSelector } from 'redux-bundler'

const bundle = createAsyncResourceBundle({
  name: 'identity',
  actionBaseType: 'IDENTITY',
  getPromise: ({ getIpfs }) => getIpfs().id(),
  staleAfter: Infinity,
  persist: false,
  checkIfOnline: false
})

bundle.selectIdentityLastSuccess = state => state.identity.lastSuccess

// Update identity after we (re)connect with ipfs
bundle.reactIdentityFetch = createSelector(
  'selectIpfsConnected',
  'selectIdentityIsLoading',
  'selectIdentityLastSuccess',
  'selectConnectedLastError',
github ipfs-shipyard / ipfs-webui / src / bundles / stats.js View on Github external
import { createAsyncResourceBundle, createSelector } from 'redux-bundler'

const bundle = createAsyncResourceBundle({
  name: 'stats',
  getPromise: async ({ getIpfs }) => {
    const bw = await getIpfs().stats.bw()
    return { bw }
  },
  staleAfter: 3000,
  retryAfter: 3000,
  persist: false,
  checkIfOnline: false
})

bundle.selectStatsLastSuccess = state => state.stats.lastSuccess

// Fetch the config if we don't have it or it's more than `staleAfter` ms old
bundle.reactStatsFetch = createSelector(
  'selectStatsShouldUpdate',
github ipfs-shipyard / ipfs-webui / src / bundles / config.js View on Github external
import toUri from 'multiaddr-to-uri'
import { createAsyncResourceBundle, createSelector } from 'redux-bundler'

const bundle = createAsyncResourceBundle({
  name: 'config',
  getPromise: async ({ getIpfs }) => {
    // SEE: https://github.com/ipfs/js-ipfs-api/issues/822
    const rawConf = await getIpfs().config.get()
    let conf

    if (Buffer.isBuffer(rawConf)) {
      conf = rawConf.toString()
    } else {
      conf = JSON.stringify(rawConf, null, '\t')
    }

    // stringy json for quick compares
    return conf
  },
  staleAfter: 60000,
github ipfs-shipyard / ipfs-webui / src / bundles / node-bandwidth.js View on Github external
import { createAsyncResourceBundle, createSelector } from 'redux-bundler'
import ms from 'milliseconds'

const bundle = createAsyncResourceBundle({
  name: 'nodeBandwidth',
  actionBaseType: 'NODE_BANDWIDTH',
  getPromise: async ({ getIpfs }) => {
    try {
      const stats = await getIpfs().stats.bw()
      return stats
    } catch (err) {
      if (/bandwidth reporter disabled in config/.test(err)) {
        return { disabled: true }
      }

      throw err
    }
  },
  staleAfter: ms.seconds(3),
  retryAfter: ms.seconds(3),
github ipfs-shipyard / ipfs-webui / src / bundles / repo-stats.js View on Github external
import { createAsyncResourceBundle, createSelector } from 'redux-bundler'

const bundle = createAsyncResourceBundle({
  name: 'repoStats',
  getPromise: async ({ getIpfs }) => {
    return getIpfs().repo.stat()
  },
  staleAfter: 60000,
  persist: false,
  checkIfOnline: false
})

bundle.selectRepoSize = createSelector(
  'selectRepoStats',
  (repoStats) => {
    if (repoStats && repoStats.repoSize) {
      return repoStats.repoSize.toString()
    }
  }
github ipfs-shipyard / ipfs-webui / src / bundles / peers.js View on Github external
import { createAsyncResourceBundle, createSelector } from 'redux-bundler'
import ms from 'milliseconds'

const bundle = createAsyncResourceBundle({
  name: 'peers',
  actionBaseType: 'PEERS',
  getPromise: ({ getIpfs }) => getIpfs().swarm.peers({ verbose: true }),
  staleAfter: ms.seconds(10),
  persist: false,
  checkIfOnline: false
})

bundle.selectPeersCount = createSelector(
  'selectPeers',
  (peers) => {
    if (!Array.isArray(peers)) return 0
    return peers.length
  }
)