Skip to content
This repository has been archived by the owner on Aug 10, 2019. It is now read-only.

Automatically use unstated-suspense on all your container's API methods.

License

Notifications You must be signed in to change notification settings

fabiospampinato/unstated-suspense-autosuspend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unstated Suspense Autosuspend

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.

Install

npm install --save unstated-suspense-autosuspend

Usage

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)/, // 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 });
  }
}

Related

License

MIT © Fabio Spampinato

About

Automatically use unstated-suspense on all your container's API methods.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages