New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

mutable-store

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mutable-store - npm Package Compare versions

Comparing version
1.0.0
to
1.0.1
+79
Readme.md
# Mutable Store
A lightweight, type-safe state management library for JavaScript/TypeScript applications that embraces mutability with a subscription pattern.
## Features
- 📦 Tiny footprint with zero dependencies
- 🔄 Subscribe to state changes
- 🧩 Works with plain JavaScript objects or class instances
- 📐 Fully typed with TypeScript
- 🛠️ Simple, intuitive API
## Installation
```bash
npm install mutable-store
```
## Usage
```ts
import { createMutableStore } from "mutable-store";
const store = createMutableStore({
count: 0,
increment() {
this.count++;
},
});
store.subscribe((sub) => {
console.log(sub);
});
store.increment();
```
## API
### createMutableStore(state: any)
Creates a mutable store from a plain JavaScript object or class instance.
#### Parameters
- `state`: The state object or class instance to make mutable.
#### Returns
The mutable state object with a `subscribe` method for subscribing to changes.
### subscribe(fn: (sub: subType) => void)
Subscribes to state changes.
// example on how to subscribe and unsubscribe
```typescript
const store = createMutableStore({
count: 0,
increment() {
this.count++;
},
});
const unsubscribe = store.subscribe((sub) => {
console.log(sub);
});
store.increment(); // { setterName: 'increment', args: [] }
unsubscribe(); // unsubscribe from the state changes
```
#### Parameters
- `fn`: The function to call when the state changes.
#### Returns
A function to unsubscribe from the state changes.
+1
-1
{
"name": "mutable-store",
"version": "1.0.0",
"version": "1.0.1",
"description": "a mutable state management library for javascript",

@@ -5,0 +5,0 @@ "main": "index.js",