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

Suspend/unsuspend updates propagation from your containers.

License

Notifications You must be signed in to change notification settings

fabiospampinato/unstated-suspense

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unstated Suspense

Suspend/unsuspend updates propagation from your containers.

It allows you to update the state multiple times while still triggering only one update of the components.

Install

npm install --save unstated-suspense

Usage

import {Container} from 'unstated-suspense';

class App extends Container {
  state = { foo: 1, bar: 2 };
  update () {
    this.suspend (); // After calling `suspend` the components won't be notified of any state update
    this.setFoo ( 11 ); // This will change the state, but it won't trigger an update of the components
    this.setBar ( 12 ); // This will change the state, but it won't trigger an update of the components
    this.unsuspend (); // Now updates are no longer suspended. If the state has been updated it will notify the components, just once (instead of twice in this particular case)
  }
  setFoo ( foo ) {
    this.setState ({ foo });
  }
  setBar ( bar ) {
    this.setState ({ bar });
  }
}

Note: If you call suspend N times you should call unsuspend N time also to resume updates propagation.

Related

License

MIT © Fabio Spampinato

About

Suspend/unsuspend updates propagation from your containers.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published