# simate

> A very simple state management tool for your JavaScript applications

Latest version **0.1.1** (published 2021-03-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install simate
pnpm add simate
yarn add simate
bun add simate
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2021-03-13 |
| First published | 2021-03-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 12.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Shikhar Sharma |
| Maintainers | ceoshikhar |
| Keywords | react, state, state management, tool |

## Links

- npm: https://www.npmjs.com/package/simate
- Repository: https://github.com/ceoshikhar/simate
- Homepage: https://github.com/ceoshikhar/simate#readme
- Issues: https://github.com/ceoshikhar/simate/issues
- npm.io page: https://npm.io/package/simate

## Dependencies (1)

- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.13.10

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.1.1 (latest) — 2021-03-13
- 0.1.0 — 2021-03-13
- 0.0.46 — 2021-03-13
- 0.0.45 — 2021-03-13
- 0.0.44 — 2021-03-13
- 0.0.43 — 2021-03-13
- 0.0.42 — 2021-03-11
- 0.0.41 — 2021-03-11
- 0.0.40 — 2021-03-11
- 0.0.0 — 2021-03-11

## README

<div align="center">
  <h1>Documentation</h1>
  <p>API documentation for <a href="https://github.com/ceoshikhar/simate">Simate</a></p>
</div>

# `simate`

A `simate` is the core of our state management. Create a `simate` instance via `createSimate`. This instance is where the magic happens. All the methods are on the simate instance.

### `createSimate`

Create a simate instance

```ts
import { createSimate } from 'simate';

const count = createSimate(69);
// 69 is initial value for `count`. It is optional.

// You can also set initial value by calling a function as the argument.
function initVal() {
  return 420;
}
const count = createSimate(initVal()); // count = 420;

// You can explicitly provide type for your simate as generic.
const mySimate = createSimate<string | number>('Hello World!');
// mySimate can be a string or a number.
```

# Simate instance's methods

### `.get()`

Provides the current value

```ts
const value = count.get(); // Simate's value is 69
```

### `.set()`

Allows you to mutate the value

```ts
count.set(420); // Simate's value is now 420
// ----OR----
// You can also pass a function which takes the `prev`(current value of simate)
// as the argument.
// The return value of the function will be the next value of the simate.
count.set((prev) => prev + 1);
```

### `.attach()`

Attach a change listener to a simate so that it is triggered everytime the simate's value is mutated via `.set()` method. You can attach as many callback functions you want. This helps us achieve the "reactivity".

**NOTE:** Do not use this method inside the function that you are attaching.

```ts
function doSomethingWhenSimateValueChanges() {
  // ...
}
count.attach(doSomethingWhenSimateValueChanges);
```

# Detach a callback function from a `simate`

### `detach()`

An object is returned by `simate.attach()` which has `detach()` method on it. You can call `detach()` to stop it from being triggered when the simate's value changes.

```ts
function doSomethingWhenSimateValueChanges() {
  // ...
}

const listener = count.attach(doSomethingWhenSimateValueChanges);

listener.detach();
// `doSomethingWhenSimateValueChanges` will no longer be triggered.
```

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