Socket
Book a DemoInstallSign in
Socket

watchable-stores

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

watchable-stores

Data model with observer / observable pattern for front-end purpose.

2.0.2
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

watchable-stores

Data model with observer / observable pattern for front-end purpose.

The lib is very easy to use :

dashboard view

We can define an interface to represent the data stored in the Store (here: IUserData).

Then, we create our store, by instanciating a new class extending WatchableStore. In the constructor, we have to invoke the super method, it will pass the content as initial data to our store.

WatchableStore provides us 2 methods :

  • watch(cb: (data: IUserData) => any): number;
  • unwatch(id: number): void;

Here are how we can use it.

dashboard view dashboard view

Our first class is a React class that just render a text input. The second one displays the list of users.

In the first one, when we click on the "Add user" button, it will trigger the function addUser of our store. By doing this, all the components listening our store will be notified that the data has been updated. It means that our second class "UserList" will be able to manage the new users.

/!\ Do not forget to unwatch the store when you destroy your component.

Keywords

Store

FAQs

Package last updated on 23 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.