How to use the redux-bundler.createSelector 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 / stats.js View on Github external
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',
  'selectIpfsReady',
  (shouldUpdate, ipfsReady) => {
    if (shouldUpdate && ipfsReady) {
      return { actionCreator: 'doFetchStats' }
    }
  }
)

export default bundle
github ipfs-shipyard / ipfs-webui / src / bundles / config.js View on Github external
(config) => getURLFromAddress('API', config) || 'https://ipfs.io'
)

bundle.selectGatewayUrl = createSelector(
  'selectConfigObject',
  (config) => getURLFromAddress('Gateway', config) || 'https://ipfs.io'
)

bundle.selectBootstrapPeers = createSelector(
  'selectConfigObject',
  (config) => config && config.Bootstrap
)

// TODO: this is a work-around for IPFS companion blocking the config API
// see: https://github.com/ipfs-shipyard/ipfs-companion/issues/454
bundle.selectIsConfigBlocked = createSelector(
  'selectConfigRaw',
  ({ errorType }) => errorType === 'Access to config.get API is globally blocked for window.ipfs'
)

// Fetch the config if we don't have it or it's more than `staleAfter` ms old
bundle.reactConfigFetch = createSelector(
  'selectConfigShouldUpdate',
  'selectIpfsReady',
  (shouldUpdate, ipfsReady) => {
    if (shouldUpdate && ipfsReady) {
      return { actionCreator: 'doFetchConfig' }
    }
  }
)

function getURLFromAddress (name, config) {
github ipfs-shipyard / ipfs-webui / src / bundles / repo-stats.js View on Github external
return repoStats.repoSize.toString()
    }
  }
)

bundle.selectRepoNumObjects = createSelector(
  'selectRepoStats',
  (repoStats) => {
    if (repoStats && repoStats.numObjects) {
      return repoStats.numObjects.toString()
    }
  }
)

// Fetch the config if we don't have it or it's more than `staleAfter` ms old
bundle.reactRepoStatsFetch = createSelector(
  'selectRepoStatsShouldUpdate',
  'selectIpfsReady',
  (shouldUpdate, ipfsReady) => {
    if (shouldUpdate && ipfsReady) {
      return { actionCreator: 'doFetchRepoStats' }
    }
  }
)

export default bundle
github abuinitski / redux-bundler-async-resources / src / features / RetryFeature.js View on Github external
enhanceBundle(bundle) {
    const { selectors } = this.#bundleKeys

    return {
      ...bundle,

      [selectors.error]: createSelector(
        selectors.raw,
        ({ error }) => error
      ),

      [selectors.errorAt]: createSelector(
        selectors.raw,
        ({ errorAt }) => errorAt
      ),

      [selectors.errorIsPermanent]: createSelector(
        selectors.error,
        error => isErrorPermanent(error)
      ),

      [selectors.hasError]: createSelector(
        selectors.errorAt,
github abuinitski / redux-bundler-async-resources / src / createAsyncResourceBundle.js View on Github external
return features.enhanceBundle({
    name,

    reducer: makeReducer(
      features.enhanceActionHandlers(actionHandlers, { rawInitialState: InitialState }),
      enhancedInitialState
    ),

    [selectors.raw]: state => state[name],

    [selectors.data]: createSelector(
      selectors.raw,
      ({ data }) => data
    ),

    [selectors.dataAt]: createSelector(
      selectors.raw,
      ({ dataAt }) => dataAt
    ),

    [selectors.isPresent]: createSelector(
      selectors.dataAt,
      dataAt => Boolean(dataAt)
    ),

    [selectors.isLoading]: createSelector(
      selectors.raw,
      ({ isLoading }) => isLoading
    ),

    [selectors.isPendingForFetch]: createSelector(
      selectors.hasError,
github abuinitski / redux-bundler-async-resources / src / createInfiniteScrollAsyncCollectionBundle.js View on Github external
[selectors.isRefreshing]: createSelector(
      selectors.raw,
      ({ refreshRequestId }) => Boolean(refreshRequestId)
    ),

    [selectors.isPresent]: createSelector(
      selectors.dataAt,
      dataAt => Boolean(dataAt)
    ),

    [selectors.isLoadingMore]: createSelector(
      selectors.raw,
      ({ loadMoreRequestId }) => Boolean(loadMoreRequestId)
    ),

    [selectors.canLoadMore]: createSelector(
      selectors.isPresent,
      selectors.isRefreshing,
      selectors.isLoadingMore,
      selectors.hasMore,
      selectors.loadMoreErrorIsPermanent,
      selectors.isDependencyResolved,
      (isPresent, isRefreshing, isLoadingMore, hasMore, loadMoreErrorIsPermanent, isDependencyResolved) =>
        isDependencyResolved && isPresent && !isRefreshing && !isLoadingMore && hasMore && !loadMoreErrorIsPermanent
    ),

    [selectors.hasMore]: createSelector(
      selectors.raw,
      ({ hasMore }) => hasMore
    ),

    [selectors.loadMoreError]: createSelector(
github abuinitski / redux-bundler-async-resources / src / features / RetryFeature.js View on Github external
const { selectors } = this.#bundleKeys

    return {
      ...bundle,

      [selectors.error]: createSelector(
        selectors.raw,
        ({ error }) => error
      ),

      [selectors.errorAt]: createSelector(
        selectors.raw,
        ({ errorAt }) => errorAt
      ),

      [selectors.errorIsPermanent]: createSelector(
        selectors.error,
        error => isErrorPermanent(error)
      ),

      [selectors.hasError]: createSelector(
        selectors.errorAt,
        errorAt => Boolean(errorAt)
      ),

      [selectors.retryAt]: this.#autoRetryEnabled
        ? createSelector(
            selectors.errorAt,
            selectors.errorIsPermanent,
            (errorAt, errorIsPermanent) => {
              if (!errorAt || errorIsPermanent) {
                return null
github dwarvesf / template-react-app / template / src / bundles / routes.js View on Github external
name: 'About',
    C: loadable(() => import('@/pages/About')),
  },

  '*': {
    name:'NotFound',
    C: loadable(() => import('@/pages/NotFound')),
  },
});

bundle.selectRouteName = createSelector(
  'selectRoute',
  route => route.name,
);

bundle.selectRouteComponent = createSelector(
  'selectRoute',
  route => {
    return route.C || (() => null);
  },
);

export default bundle;
github ipfs-shipyard / ipfs-share-files / src / bundles / routes.js View on Github external
import { createRouteBundle, createSelector } from 'redux-bundler'
import PAGES from '../constants/pages'
import Page from '../page/Page'

const bundle = createRouteBundle({
  '/:hash': Page,
  '/add/:hash': Page,
  '*': Page
}, { routeInfoSelector: 'selectHash' })

bundle.selectCurrentPage = createSelector(
  'selectRouteInfo',
  ({ url, params }) => (url.startsWith('/add') || !params.hash) ? PAGES.add : PAGES.download
)

export default bundle
github abuinitski / redux-bundler-async-resources / src / createInfiniteScrollAsyncCollectionBundle.js View on Github external
[selectors.data]: createSelector(
      selectors.raw,
      ({ items }) => items
    ),

    [selectors.dataAt]: createSelector(
      selectors.raw,
      ({ itemsAt }) => itemsAt
    ),

    [selectors.isRefreshing]: createSelector(
      selectors.raw,
      ({ refreshRequestId }) => Boolean(refreshRequestId)
    ),

    [selectors.isPresent]: createSelector(
      selectors.dataAt,
      dataAt => Boolean(dataAt)
    ),

    [selectors.isLoadingMore]: createSelector(
      selectors.raw,
      ({ loadMoreRequestId }) => Boolean(loadMoreRequestId)
    ),

    [selectors.canLoadMore]: createSelector(
      selectors.isPresent,
      selectors.isRefreshing,
      selectors.isLoadingMore,
      selectors.hasMore,
      selectors.loadMoreErrorIsPermanent,
      selectors.isDependencyResolved,