Automatically use unstated-suspense on all your container's API methods.
It supports methods returning promises, it re-throws any thrown exceptions, and it supports bubbling up the suspension to parent containers (in case you're using unstated-compose).
Only methods defined in your container, and not somewhere further down in its prototype chain, will be autosuspended.
npm install --save unstated-suspense-autosuspend
It supports a second optional options object which by default looks like this:
{
bubbles: Infinity, // How many levels to bubble up the suspension
methods: /^(?!_|middleware|(?:(?:get|is|has)(?![a-z0-9])))/, // Methods matching this regex will be autosuspended
middlewares: true // Suspend middlewares as well
}
Alternatively you can assign your options for unstated-suspense-autosuspend
to your container's autosuspend
property.
import autosuspend from 'unstated-suspense-autosuspend';
import {Container} from 'unstated-suspense';
class App extends Container {
// autosuspend = false; // Disables `unstated-suspense-autosuspend` for this container
// autosuspend = { bubbles: false } // Disables bubbling
// autosuspend = { methods: /^api/ } // Only methods whose names start with "api" will be autosuspended
constructor () {
super ();
autosuspend ( this );
// autosuspend ( this, {...} ) // Passing custom options via the API
}
middlewareFoo () {} // Not autosuspended, it's name doesn't match `options.methods`
_foo () {} // Not autosuspended, it's name doesn't match `options.methods`
update () { // Autosuspended
this.setFoo ( 11 );
this.setBar ( 12 );
}
setFoo ( foo ) { // Autosuspended
this.setState ({ foo });
}
setBar ( bar ) { // Autosuspended
this.setState ({ bar });
}
}
- unstated-with-containers: Higher-Order Component for subscribing to containers.
- unstated-connect2: Connect containers to components, without sacrificing performance.
- unstated-hmr: Preserve containers' states across Hot-Module-Replacements.
- unstated-compose: Compose multiple containers into one.
-
unstated-compose-suspense: Add suspend/unsuspend support to
unstated-compose
. -
unstated-compose-suspense-middleware: Add middlewares support to
unstated-compose-suspense
. - unstated-suspense: Suspend/unsuspend updates propagation from your containers.
-
unstated-suspense-middleware: Add middlewares support to
unstated-suspense
.
MIT © Fabio Spampinato