1 | # IndustryState [![Build Status](https://travis-ci.org/invrs/industry-state.svg?branch=master)](https://travis-ci.org/invrs/industry-state)
|
2 |
|
3 | Immutable state for your factories.
|
4 |
|
5 | ## Requirements
|
6 |
|
7 | This extension requires that the factory function returns a stateful object.
|
8 |
|
9 | ## Usage
|
10 |
|
11 | ```js
|
12 | import { factory } from "industry"
|
13 | import { functions } from "industry-functions"
|
14 | import { instance } from "industry-instance"
|
15 | import { standard_io } from "industry-standard-io"
|
16 | import { state } from "industry-state"
|
17 |
|
18 | class Test {
|
19 | init() {
|
20 | this.state({ a: 1 })
|
21 | }
|
22 |
|
23 | a({ state: { a } }) {
|
24 | return a
|
25 | }
|
26 | }
|
27 |
|
28 | let test = factory(Test)
|
29 | .set("functions", functions)
|
30 | .set("instance", instance)
|
31 | .set("state", state)
|
32 | .set("standard_io", standard_io)
|
33 |
|
34 | test({ b: 2 })
|
35 | test().state() // { a: 1, b: 2 }
|
36 | test.a() // { value: 1 }
|
37 | ```
|