An open API service indexing awesome lists of open source software.

https://github.com/dev-siri/reactivity-stores

Simple TypeScript-first state management with reactive stores.
https://github.com/dev-siri/reactivity-stores

Last synced: about 1 year ago
JSON representation

Simple TypeScript-first state management with reactive stores.

Awesome Lists containing this project

README

          

# Reactive Stores

Reactive is a powerful tool for managing application state in a reactive and efficient manner. It provides a clean and organized way to handle global state, reactivity, and state updates.

## Installation

You can install the library using your preferred package manager:

```bash
pnpm add reactive-stores
```

## Usage

Import the library and start using it to manage your application's state. Here's a simple example of how you might use the library:

```ts
// Type modules for end-to-end type safety
import Store, { mergeStores, type State } from "reactive-stores";

// Create stores
const counterStore = new Store("counter-store", { count: 0 });
const inputStore = new Store("input-store", {
email: "hello@example.com",
password: "********",
});

// Merge stores
const mergedStore = mergeStores<{
"counter-store": State;
"input-store": State;
}>("merged-store", [counterStore, inputStore]);

// Subscribe to stores
const currentCount = counterStore.subscribe((count) =>
console.log("Current count:", count)
);

// and update it
counterStore.set({ count: (prevCount) => ++prevCount });
```

## Features

- **Global State Management:** Manage global application state that can be accessed and updated from different components.

- **Reactivity:** Automatically update components when the state changes, reducing manual handling and improving consistency.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.