Socket
Book a DemoInstallSign in
Socket

obstate

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

obstate

Generic object state management with events

0.1.4
latest
Source
npmnpm
Version published
Weekly downloads
286
75.46%
Maintainers
1
Weekly downloads
 
Created
Source

ObState

Generic object state management with events

obstate Tests

Simple state manager that uses objects to store and track state. Manage the object normally as it additionally provides events to listen to state changes.

ObState uses Proxys to handle state changes, and then emits events using a standard EventEmitter interface.

Usage

Import the createStateObject method and use it to wrap an object (a new object is returned, the old is not mutated):

import { createStateObject } from "obstate";

const state = createStateObject({
    name: "Jane Doe",
    age: 24
});

state.on(
    "before",
    ({ property, newValue, currentValue }) =>
        console.log(`Will update '${property}': ${currentValue} => ${newValue}`)
);
state.on(
    "update",
    ({ property, newValue, oldValue }) =>
        console.log(`Did update '${property}':  ${oldValue} => ${newValue}`)
);

Object.assign(state, {
    name: "John Doe",
    age: 22
});

The example above would output:

Will update 'name': Jane Doe => John Doe
Did update 'name':  Jane Doe => John Doe
Will update 'age': 24 => 22
Did update 'age':  24 => 22

React

react-obstate is a react toolkit that provides hooks for using state instances in React components.

Keywords

state

FAQs

Package last updated on 16 Jul 2023

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.