0.0.8 • Published 6 years ago

mobx-box v0.0.8

Weekly downloads
24
License
MIT
Repository
github
Last release
6 years ago

mobx-box

npm version

Discussion here.

tl;dr

const store = new class {
-  @observable foo = '';
-  @observable bar = '';
-
-  @action setFoo = value => (this.foo = value);
-  @action setBar = value => (this.bar = value);
+  @box foo = '';
+  @box bar = '';
}();

console.log(store.foo); // ''
console.log(store.bar); // ''

- store.setFoo('Lorem');
- store.setBar('Ipsum');
+ // these are mobx actions (internally), not direct mutations, they don't violate strict mode
+ store.foo = 'Lorem';
+ store.bar = 'Ipsum';

console.log(store.foo); // 'Lorem'
console.log(store.bar); // 'Ipsum'

Install

yarn add mobx mobx-box

Example

Edit o43pjz1p6z

import React from 'react';

import { configure } from 'mobx';
import { observer } from 'mobx-react';

import box from 'mobx-box';

configure({ enforceActions: true });

const store = new class {
  @box foo = 0;

  // or without decorators
  constructor() {
    box(this, 'bar', 0);
  }
}();

const Example = () => (
  <div>
    <button onClick={() => (store.foo = Date.now())}>{store.foo}</button>
    <button onClick={() => (store.bar = Date.now())}>{store.bar}</button>
  </div>
);

export default observer(Example);
0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago