Registry / web-framework / redux-bundler-async-resources

redux-bundler-async-resources

JSON →
library2.0.1jsnpmunverified

This package provides bundle factories for `redux-bundler`, specializing in the management of asynchronous data resources. It offers `createAsyncResourceBundle` for handling single remote resources and `createAsyncResourcesBundle` for managing collections of async resources, each with its own lifecycle, including loading, staleness, and expiration. Key features include configurable `staleAfter` and `expireAfter` durations to manage data freshness and automatic removal, a `dependencyKey` mechanism for conditional fetching and automatic cache invalidation based on upstream selector changes, and support for `doAdjust` actions to optimistically update resource state after mutations. The current stable version is 2.0.1. Releases appear to be ad-hoc, driven by new features or bug fixes, rather than a strict time-based cadence. It differentiates itself by providing a more robust and opinionated approach to async resource management within the `redux-bundler` ecosystem, extending beyond `redux-bundler`'s native capabilities.

npm install redux-bundler-async-resources
INSTALL
IMPORT
SIG · REDUX-BUNDLER-ASYN
R
redux-bundler-async-resources
web-frameworkjavascriptv2.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createAsyncResourceBundle
import { createAsyncResourceBundle } from 'redux-bundler-async-resources'
const createAsyncResourceBundle = require('redux-bundler-async-resources').createAsyncResourceBundle
Primary factory for managing single async resources. Use named import.
createAsyncResourcesBundle
import { createAsyncResourcesBundle } from 'redux-bundler-async-resources'
import createAsyncResourcesBundle from 'redux-bundler-async-resources'
Factory for managing collections of async resources. Introduced in v1.1.0. Note the plural 'Resources'.
makeAsyncResourceBundleKeys
import { makeAsyncResourceBundleKeys } from 'redux-bundler-async-resources'
import * as bundleKeys from 'redux-bundler-async-resources'
Helper for automated processing of single async resource bundle keys. Use named import.
makeAsyncResourcesBundleKeys
import { makeAsyncResourcesBundleKeys } from 'redux-bundler-async-resources'
Helper for automated processing of plural async resources bundle keys. Introduced in v1.1.1.

Demonstrates how to define an async resource bundle for fetching and managing a single list of hot car deals, integrating it with a React component using `redux-bundler-hook`.

import { createSelector } from 'redux-bundler'; import { createAsyncResourceBundle } from 'redux-bundler-async-resources'; import React from 'react'; // Assume redux-bundler-hook is installed and configured for useConnect import { useConnect } from 'redux-bundler-hook'; // Mock shopApi for demonstration purposes const shopApi = { fetchHotCarDeals: () => { return new Promise(resolve => { setTimeout(() => { const deals = [{ id: 1, name: 'Sedan Deal', price: 25000 }, { id: 2, name: 'SUV Offer', price: 35000 }]; console.log('Fetched hot car deals:', deals); resolve(deals); }, 1500); // Simulate network delay }); } }; // bundles/hotCarDeals.js const hotCarDealsBundle = { ...createAsyncResourceBundle({ name: 'hotCarDeals', staleAfter: 180000, // refresh every 3 minutes expireAfter: 60 * 60000, // delete if not refreshed in an hour getPromise: ({ shopApi: apiContext }) => apiContext.fetchHotCarDeals(), }), reactShouldFetchHotCarDeals: createSelector( 'selectHotCarDealsIsPendingForFetch', shouldFetch => { if (shouldFetch) { return { actionCreator: 'doFetchHotCarDeals' }; } } ), }; // Component usage example (HotCarDeals.js) const ErrorMessage = ({ error }) => <div style={{ color: 'red' }}>Error: {error?.message}</div>; const Spinner = () => <div>Loading...</div>; const CarDealsList = ({ deals }) => ( <div> <h3>Hot Car Deals</h3> <ul> {deals.map(deal => ( <li key={deal.id}>{deal.name}: ${deal.price}</li> ))} </ul> </div> ); export default function HotCarDealsComponent() { // In a real app, 'shopApi' would be part of your main bundle's context const { hotCarDeals, hotCarDealsError } = useConnect( 'selectHotCarDeals', 'selectHotCarDealsError' ); if (!hotCarDeals && hotCarDealsError) { return <ErrorMessage error={hotCarDealsError} />; } if (!hotCarDeals) { return <Spinner />; } return <CarDealsList deals={hotCarDeals} />; } // To run this: // 1. Create a root bundler (e.g., composeBundles(hotCarDealsBundle, { getShopApi: () => shopApi })) // 2. Wrap your app in <BundlerProvider bundler={store} /> // 3. Render <HotCarDealsComponent />
Debug
Known issues
breakingVersion 1.1.0 introduced a reimplementation of `createAsyncResourceBundle`. While aiming for 'same naming conventions, implementation logic, and same extra features', internal behavior or edge cases might have changed. Users upgrading from versions prior to 1.1.0 should thoroughly test their existing bundles.
fix
Review usage of `createAsyncResourceBundle` and associated selectors/actions for any unexpected behavior or performance changes. Consult the changelog for details if available.
affects: >=1.1.0
gotchaMisunderstanding `staleAfter` vs. `expireAfter` can lead to unexpected data persistence or removal. `staleAfter` marks data for refresh but keeps it, while `expireAfter` completely removes it from the store if not refreshed.
fix
Carefully configure `staleAfter` for desired background refresh frequency and `expireAfter` for explicit cache invalidation. Set `Infinity` to disable either mechanism.
affects: >=1.0.0
gotchaThe `dependencyKey` mechanism introduced in v1.2.0 will force-clear a resource bundle when its associated selector's value changes. If the dependency selector frequently changes for non-material reasons, it can lead to excessive re-fetching.
fix
Ensure `dependencyKey` selectors return stable, memoized values. Avoid using selectors that return new object/array instances on every render unless explicit re-fetching is desired.
affects: >=1.2.0
gotchaIntegration with `redux-bundler-async-resources-hooks` (especially for `v1.2.1`) requires specific versions. Mismatched versions between the two packages can lead to unexpected behavior or runtime errors.
fix
Always ensure compatible versions of `redux-bundler-async-resources` and `redux-bundler-async-resources-hooks`. Refer to the respective package release notes for compatibility guidance.
affects: >=1.2.1
gotchaThe `getPromise` function requires context parameters (e.g., `shopApi`). If these are not provided to your `redux-bundler` store (e.g., through `composeBundles({ getShopApi: () => myApi })`), the promise will fail to execute or throw an error.
fix
Ensure all necessary dependencies for `getPromise` are injected into the bundler's context via the `composeBundles` configuration.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'fetchHotCarDeals')
The `shopApi` object or similar dependency required by `getPromise` was not injected into the `redux-bundler` context.
fix
Pass the necessary API client or service into `composeBundles` when initializing the store, e.g., `composeBundles(myBundle, { getShopApi: () => shopApiInstance })`.
ReferenceError: require is not defined
Attempting to use CommonJS `require()` syntax in an ESM-only context or a mixed environment not properly configured for CommonJS.
fix
Update imports to use ES Modules syntax: `import { createAsyncResourceBundle } from 'redux-bundler-async-resources';`.
Error: A selector 'selectMyResourceNameIsPendingForFetch' could not be found. Check your bundle definition.
The `name` option in `createAsyncResourceBundle` does not match the expected selector name used in `createSelector` or `useConnect`, or the bundle itself is not correctly added to the root bundler.
fix
Verify the `name` property passed to `createAsyncResourceBundle` exactly matches the base name used in selectors (e.g., 'hotCarDeals' for `selectHotCarDealsIsPendingForFetch`). Ensure the bundle is included in your `composeBundles` call.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies
redux-bundlerrequiredCore framework for creating bundles and managing state.
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
redux-bundler-async-resources — npm install redux-bundler-async-resources · libregistry