Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@zenstack/zen-store

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zenstack/zen-store

A simple reactive state store

  • 0.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Zen Store ☮️

A simple reactive state store

installation

yarn add @zenstack/zen-store

or

npm install @zenstack/zen-store

Usage

Create A State Store

import { createStateStore } from "@zenstack/zen-store";
const initialState = 0;
const stateStore = createStateStore(initialState);

//you can also use a class if you are object oriented
import { StateStore } from "@zenstack/zen-bus";
const initialState = 0;
const stateStore = new StateStore(initialState);

Retrieve State

The store offers an API, .getState() to retrieve the current state

const currentState = store.getState();

Update State

The store offers an API, .setState(:newState) to update the state

const newState = 5;
store.setState(newState);

Subscribe To State

The store offers an API, .subscribe(:handler) to subscribe to updates in the store. The .subscribe(:handler) returns an unsubscribe function that can be executed to detach the handler from the event.

const logState = (state) => console.log(state);

// .subscribe() returns an unsubscribe method
const unsubscribe = store.subscribe(logState);

// logState will be triggered
store.setState('some new state');

// logState will not be triggered after unsubscribing
unsubscribe();
store.setState('some other new state');

Keywords

FAQs

Package last updated on 13 Feb 2021

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc