# faster-mobx

> MobX is a state management library designed to notify observers of changes to an observable object's state.

Latest version **1.0.17** (published 2024-11-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install faster-mobx
pnpm add faster-mobx
yarn add faster-mobx
bun add faster-mobx
```

## Health

**Score 30/100 (F)** — status: maintenance-mode.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.17 |
| Published | 2024-11-14 |
| First published | 2023-03-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 202.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Trant Labs |
| Maintainers | samuelscheit |
| Keywords | mobx, state-management, redux, zustand, recoil |

## Links

- npm: https://www.npmjs.com/package/faster-mobx
- Repository: https://github.com/trantlabs/faster-mobx
- Homepage: https://github.com/trantlabs/faster-mobx#readme
- Issues: https://github.com/trantlabs/faster-mobx/issues
- npm.io page: https://npm.io/package/faster-mobx

## Dependencies (3)

- [jest](https://npm.io/package/jest.md) ^29.7.0
- [@types/bun](https://npm.io/package/@types/bun.md) ^1.0.11
- [@types/jest](https://npm.io/package/@types/jest.md) ^29.5.12

## Alternatives

- [@reckona/mreact-store](https://npm.io/package/@reckona/mreact-store.md) — 976 weekly downloads
- [regular-state](https://npm.io/package/regular-state.md) — 410 weekly downloads
- [@pacote/flux-actions](https://npm.io/package/@pacote/flux-actions.md) — 65 weekly downloads
- [@pilotlab/lux-debug](https://npm.io/package/@pilotlab/lux-debug.md) — 39 weekly downloads
- [vue-persist-state](https://npm.io/package/vue-persist-state.md) — 19 weekly downloads

## Recent versions

- 1.0.17 (latest) — 2024-11-14
- 1.0.16 — 2024-11-02
- 1.0.14 — 2024-09-11
- 1.0.13 — 2024-06-26
- 1.0.12 — 2024-06-02
- 1.0.11 — 2024-04-18
- 1.0.10 — 2024-04-11
- 1.0.9 — 2024-04-08
- 1.0.8 — 2024-04-07
- 1.0.5 — 2023-08-02
- 1.0.4 — 2023-03-29
- 1.0.3 — 2023-03-23
- 1.0.2 — 2023-03-16
- 1.0.1 — 2023-03-15
- 1.0.0 — 2023-03-15

## README

# Faster Mobx

MobX is a state management library designed to notify observers of changes to an observable object's state.

However, the `observable` function of MobX has performance issues when handling large amounts of objects with many properties.

To address this issue, the `faster-mobx` library has been developed, providing a **50-500x faster** `observable` implementation of MobX that can be used as a drop in replacement.

## Features

-   [x] `observable`
-   [x] `makeObservable`
-   [x] `autorun`
-   [x] `reaction`
-   [x] `runInAction` (with async support)
-   [x] `observer` (React support)
-   [x] `observable.map`
-   [ ] `computed`
-   [ ] `action`
-   [ ] `toJS`
-   [ ] `trace`

## Installation

```
# with npm
npm i faster-mobx

# with yarn
yarn add faster-mobx

# with pnpm
pnpm add faster-mobx
```

## Usage

```js
import { observable, autorun, makeObservable } from "faster-mobx";

const data = observable({
	name: "John",
	age: 20,
});

autorun(() => {
	console.log(data.name);
});

data.name = "Jane";

// with classes

class User {
	name = "John";
	age = 20;

	constructor() {
		// all properties will be observable
		// if you extend this class, you MUST NOT call makeObservable again in the child class
		// the return is important to make it reactive
		return makeObservable(this);
	}
}
```

## Benchmark

Benchmark was done using [benchmark.js](https://benchmarkjs.com/) on a 3.20GHz CPU with one thread.

| Function                       |     Mobx     | Faster Mobx | Speedup |
| ------------------------------ | :----------: | :---------: | :-----: |
| observable                     | 570k ops/sec | 33M ops/sec |   58x   |
| makeObservable (1 property)    | 750k ops/sec | 33M ops/sec |   44x   |
| makeObservable (26 properties) | 54k ops/sec  | 33M ops/sec |  611x   |
| autorun                        | 12M ops/sec  | 6M ops/sec  |  0.5x   |
| get                            | 23M ops/sec  | 55M ops/sec |  2.4x   |
| set                            | 19M ops/sec  | 30M ops/sec |  1.6x   |

You can run the benchmark yourself by cloning the repo and running the following commands:

```bash
git clone https://github.com/trantlabs/faster-mobx
cd faster-mobx
npm install
npm run benchmark
```

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