1.0.11 • Published 24 days ago

faster-mobx v1.0.11

Weekly downloads
-
License
MIT
Repository
github
Last release
24 days ago

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

  • observable
  • makeObservable
  • autorun
  • reaction
  • runInAction (with async support)
  • observer (React support)
  • 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

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 on a 3.20GHz CPU with one thread.

FunctionMobxFaster MobxSpeedup
observable570k ops/sec33M ops/sec58x
makeObservable (1 property)750k ops/sec33M ops/sec44x
makeObservable (26 properties)54k ops/sec33M ops/sec611x
autorun12M ops/sec6M ops/sec0.5x
get23M ops/sec55M ops/sec2.4x
set19M ops/sec30M ops/sec1.6x

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

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

24 days ago

1.0.10

1 month ago

1.0.9

1 month ago

1.0.8

1 month ago

1.0.5

9 months ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago