Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
(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) {
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
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,
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,
[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(
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
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;
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
[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,