# @bytesoftio/store

> ## Installation

Latest version **3.0.0** (published 2020-11-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install @bytesoftio/store
pnpm add @bytesoftio/store
yarn add @bytesoftio/store
bun add @bytesoftio/store
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2020-11-26 |
| First published | 2020-05-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 10.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Maxim Kott |
| Maintainers | maximkott |

## Links

- npm: https://www.npmjs.com/package/@bytesoftio/store
- Repository: https://github.com/bytesoftio/store
- npm.io page: https://npm.io/package/@bytesoftio/store

## Dependencies (2)

- [lodash](https://npm.io/package/lodash.md) ^4.17.15
- [@bytesoftio/value](https://npm.io/package/@bytesoftio/value.md) ^3.0.0

## Recent versions

- 3.0.0 (latest) — 2020-11-26
- 2.0.5 — 2020-07-20
- 2.0.4 — 2020-05-03
- 2.0.3 — 2020-05-02
- 2.0.2 — 2020-05-02
- 2.0.1 — 2020-05-02
- 2.0.0 — 2020-05-01

## README

# @bytesoftio/store

## Installation

`yarn add @bytesoftio/store` or `npm install @bytesoftio/store`

## Table of contents

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->


- [Description](#description)
- [createStore](#createstore)
- [ObservableStore](#observablestore)
- [Usage in React](#usage-in-react)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## Description

Similar to the [@bytesoftio/value](https://github.com/bytesoftio/value) package, except this one is optimized for use with objects. It comes with
differs, mergers and can be used with a custom mapper / connector. Thanks to the [@bytesoftio/use-store](https://github.com/bytesoftio/use-store) package, this library allows you to write stores that can be used in any environment as well as inside React through hooks.

## createStore

Creates a new instance of `ObservableStore` .

```ts
import { createStore } from "@bytesoftio/store"

// create a new store from initial state
const store = createStore({some: "data"})
```

## ObservableStore

A very simple observable like object.

```ts
import { createStore } from "@bytesoftio/store"

const store = createStore({firstName: "John", lastName: "Doe"})

// get the underlying store value, read only
store.get()

// update all of the store data
store.set({firstName: "Steve", lastName: "Jobs"})

// update some of the store data
store.add({lastName: "Wozniak"})

// reset store back to initial state {firstName: "John", lastName: "Doe"}
store.reset()

// reset store state and change its initial value
store.reset({firstName: "James", lastName: "Bond"})

// listen to state changes outside
store.listen(state => console.log(state))
```

## Usage in React

To learn how to use this package inside React, please refer to the [@bytesoftio/use-store](https://github.com/bytesoftio/use-store) package.

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