# @jaszhix/state

> Small state management library that handles dispatching callbacks on state change, or manual triggers

Latest version **1.0.4** (published 2020-01-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install @jaszhix/state
pnpm add @jaszhix/state
yarn add @jaszhix/state
bun add @jaszhix/state
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2020-01-31 |
| First published | 2019-08-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 190.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jason Hicks |
| Maintainers | jaszhix |

## Links

- npm: https://www.npmjs.com/package/@jaszhix/state
- Repository: https://github.com/jaszhix/state
- Homepage: https://github.com/jaszhix/state#readme
- Issues: https://github.com/jaszhix/state/issues
- npm.io page: https://npm.io/package/@jaszhix/state

## Recent versions

- 1.0.4 (latest) — 2020-01-31
- 1.0.3 — 2019-08-11
- 1.0.2 — 2019-08-11
- 1.0.1 — 2019-08-04
- 1.0.0 — 2019-08-02

## README

# state

This is a small state management library that handles dispatching callbacks on state change, or manual triggers. Simplicity and performance are the main priorities for this library.

## Install

- `yarn add @jaszhix/state`

## Examples

### Basic Usage

```js
import init from '@jaszhix/state';

// Initialize the store
const state = init({foo: null});

// Setup the callback for 'foo' value change
const id = state.connect('foo', ({foo}) => {
  // Handle this property's value change
  console.log(foo); // 'bar'
});

state.set({foo: 'bar'});

// Later in the application lifecycle (e.g., when a component unmounts), you can disconnect the key from the callback queue.
state.disconnect(id);
```

### Manual Triggers

```js
import init from '@jaszhix/state';

// Initialize the store
const state = init({foo: null});

// Setup the callback for 'foo' value change
const id = state.connect({
  action1: (bool) => {
    // Handle the action
    console.log(bool); // true
  }
});

state.trigger('action1', true);
```

Check src/index.test.ts for more examples.

## Contributing

- `yarn`
- `yarn build`
- `yarn start`

---
_Source: https://npm.io/package/@jaszhix/state · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
