# simple-reactor

> I was unable to find my own verison of this. Something simple and easy to use. Hence why I've created my own!

Latest version **2.1.1** (published 2023-12-11) · ISC license · 0 weekly downloads

## Install

```sh
npm install simple-reactor
pnpm add simple-reactor
yarn add simple-reactor
bun add simple-reactor
```

## 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 | 2.1.1 |
| Published | 2023-12-11 |
| First published | 2023-07-15 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | slimbo |

## Links

- npm: https://www.npmjs.com/package/simple-reactor
- npm.io page: https://npm.io/package/simple-reactor

## Recent versions

- 2.1.1 (latest) — 2023-12-11
- 2.1.0 — 2023-12-11
- 1.1.0 — 2023-07-15
- 1.0.1 — 2023-07-15
- 1.0.0 — 2023-07-15

## README

# Super Simple Reactive Variables
I was unable to find my own verison of this. Something simple and easy to use. Hence why I've created my own!

# Usage
Import the library.
`import { observeable } from 'simple-reactor'` or `import anyname from 'simple-reactor'`

> JSDoc's are provided. Alongside typescript definitions.

Create a new observable with any value you want:
```js
const obs = new observable(1);
```

Subscribe to it to know when the value changes:
```js
obs.subscribe((value, unsub) => {
    console.log('Value: ', value);
    unsub();
})
```

> The second paramater is a function used to unsubscribe from the object. It can be safely ommited if now wanting to be used.

And change it like so:
```js
obs.set(2);
```

If you want to use the value, just use get:
```js
obs.get();
```

## Full Code
```js
import { observable } from 'simple-reactor';

const obs = new observable(1);
obs.subscribe((value, unsub) => {
    console.log('value', value);
    if (value == 3) ubsub();
})
obs.set(2);
obs.set(3);
```

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