# mobx-box

> A MobX utility, treat mutations -anywhere- as actions by default.

Latest version **0.0.8** (published 2018-08-01) · MIT license · 0 weekly downloads

## Install

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

## 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.0.8 |
| Published | 2018-08-01 |
| First published | 2017-04-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | sonaye |

## Links

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

## Recent versions

- 0.0.8 (latest) — 2018-08-01
- 0.0.7 — 2018-03-17
- 0.0.6 — 2017-08-04
- 0.0.4 — 2017-07-28
- 0.0.3 — 2017-07-05
- 0.0.2 — 2017-04-21
- 0.0.1 — 2017-04-03

## README

# mobx-box

[![npm version](https://badge.fury.io/js/mobx-box.svg)](https://badge.fury.io/js/mobx-box)

Discussion [here](https://github.com/mobxjs/mobx/issues/839).

**[tl;dr](https://github.com/mobxjs/mobx/issues/839#issuecomment-306010275)**

```diff
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

```bash
yarn add mobx mobx-box
```

## Example

[![Edit o43pjz1p6z](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/o43pjz1p6z)

```js
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);
```

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