2020There are some[ demo] ( https://jsfiddle.net/1q772uL0/20/ ) on fiddle. Here's the simplest:
2121
2222``` typescript
23- import {observable ,observe }from " dob"
23+ import {observable ,observe }from " dob" ;
2424
25- const obj= observable ({ a:1 })
25+ const obj= observable ({ a:1 });
2626
2727observe (()=> {
28- console .log (" obj.a has changed to" ,obj .a )
29- })// <· obj.a has changed to 1
28+ console .log (" obj.a has changed to" ,obj .a );
29+ }); // <· obj.a has changed to 1
3030
31- obj .a = 2 // <· obj.a has changed to 2
31+ obj .a = 2 ; // <· obj.a has changed to 2
3232```
3333
3434You can enjoy the benefits of proxy, for example` obj.a = { b: 5 } ` is effective.
3535
3636##Use in react component
3737
3838``` typescript
39- import {Action ,observable ,combineStores ,inject }from ' dob'
40- import {Connect }from ' dob-react'
39+ import {Action ,observable ,combineStores ,inject }from " dob" ;
40+ import {Connect }from " dob-react" ;
4141
4242@observable
4343export class UserStore {
44- name= ' bob'
44+ name= " bob" ;
4545}
4646
4747export class UserAction {
48- @inject (UserStore ) UserStore: UserStore ;
48+ @inject (UserStore ) UserStore: UserStore ;
4949
50- @Action setName () {
51- this .store .name = ' lucy'
52- }
50+ @Action
51+ setName() {
52+ this .store .name = " lucy" ;
53+ }
5354}
5455
55- @Connect (combineStores ({
56+ @Connect (
57+ combineStores ({
5658UserStore ,
5759UserAction
58- }))
60+ })
61+ )
5962class App extends React .Component {
60- render() {
61- return (
62- < span onClick = {this.props.UserAction.setName }>
63- {this .props .UserStore .name }
64- < / span >
65- )
66- }
63+ render() {
64+ return (
65+ < span onClick = {this.props.UserAction.setName }>
66+ {this .props .UserStore .name }
67+ < / span >
68+ );
69+ }
6770}
6871```
6972
@@ -72,58 +75,66 @@ class App extends React.Component {
7275##Use in react project
7376
7477``` typescript
75- import {Action ,observable ,combineStores ,inject }from ' dob'
76- import {Provider ,Connect }from ' dob-react'
78+ import {Action ,observable ,combineStores ,inject }from " dob" ;
79+ import {Provider ,Connect }from " dob-react" ;
7780
7881@observable
7982export class UserStore {
80- name= ' bob'
83+ name= " bob" ;
8184}
8285
8386export class UserAction {
84- @inject (UserStore ) UserStore: UserStore ;
87+ @inject (UserStore ) UserStore: UserStore ;
8588
86- @Action setName () {
87- this .store .name = ' lucy'
88- }
89+ @Action
90+ setName() {
91+ this .store .name = " lucy" ;
92+ }
8993}
9094
9195@Connect
9296class App extends React .Component {
93- render() {
94- return (
95- < span onClick = {this.props.UserAction.setName }>
96- {this .props .UserStore .name }
97- < / span >
98- )
99- }
97+ render() {
98+ return (
99+ < span onClick = {this.props.UserAction.setName }>
100+ {this .props .UserStore .name }
101+ < / span >
102+ );
103+ }
100104}
101105
102106ReactDOM .render (
103- < Provider {
104- ... combineStores ({
105- UserStore ,
106- UserAction
107- })
108- }>
109- < App / >
110- < / Provider >
111- ,document .getElementById (' react-dom' ))
107+ < Provider
108+ {... combineStores ({
109+ UserStore ,
110+ UserAction
111+ })}
112+ >
113+ < App / >
114+ < / Provider > ,
115+ document .getElementById (" react-dom" )
116+ );
112117```
113118
114119##Project Examples
115120
116- - [ dob-react simple example] ( https://github.com/ascoders/dob-example )
117- - [ dob-react hackernews] ( https://github.com/dobjs/dob-react-hackernews )
118- - [ dob-react todoMVC] ( https://github.com/dobjs/dob-react-todomvc )
119- - [ dob-react complex online web editor] ( https://github.com/ascoders/gaea-editor )
120- - [ dob-redux todoMVC] ( https://github.com/dobjs/dob-redux-todomvc )
121+ * [ dob-react simple example] ( https://github.com/ascoders/dob-example )
122+ * [ dob-react hackernews] ( https://github.com/dobjs/dob-react-hackernews )
123+ * [ dob-react todoMVC] ( https://github.com/dobjs/dob-react-todomvc )
124+ * [ dob-react complex online web editor] ( https://github.com/ascoders/gaea-editor )
125+ * [ dob-redux todoMVC] ( https://github.com/dobjs/dob-redux-todomvc )
121126
122127##Ecosystem
123128
124- - [ dob-react] ( https://github.com/dobjs/dob-react ) - Connect dob to react! Here is a basic[ demo] ( https://jsfiddle.net/yp90Lep9/21/ ) , and here is a[ demo] ( https://jsfiddle.net/g19ehhgu/11/ ) with fractal.[ Quick start] ( ./docs/dob-react.md ) .
125- - [ dob-react-devtools] ( https://github.com/dobjs/dob-react-devtools ) - Devtools for dob-react, with action and ui two way binding.
126- - [ dob-redux] ( https://github.com/dobjs/dob-redux ) - You can use both dob and Redux by using it! Enjoy the type and convenience of dob, and the ecology of Redux.
129+ * [ dob-react] ( https://github.com/dobjs/dob-react ) - Connect dob to react! Here is a basic[ demo] ( https://jsfiddle.net/yp90Lep9/21/ ) , and here is a[ demo] ( https://jsfiddle.net/g19ehhgu/11/ ) with fractal.[ Quick start] ( ./docs/dob-react.md ) .
130+ * [ dob-react-devtools] ( https://github.com/dobjs/dob-react-devtools ) - Devtools for dob-react, with action and ui two way binding.
131+ * [ dob-redux] ( https://github.com/dobjs/dob-redux ) - You can use both dob and Redux by using it! Enjoy the type and convenience of dob, and the ecology of Redux.
132+
133+ ##Communication
134+
135+ Talk to us about dob using DingDing.
136+
137+ <img src =" https://user-images.githubusercontent.com/7970947/40582019-39bdd16e-619b-11e8-8e82-43cf529a9fff.JPG " width =500/ >
127138
128139##Note
129140
@@ -133,26 +144,26 @@ Do not allow circular dependencies between store and action, It's impossible to
133144
134145``` typescript
135146class A {
136- @inject (B ) b
147+ @inject (B ) b;
137148}
138149class B {
139- @inject (A ) a
150+ @inject (A ) a;
140151}
141152```
142153
143154###Do not deconstruct to the last level on dynamic object
144155
145156``` typescript
146- const obj= observable ({ a:1 })
157+ const obj= observable ({ a:1 });
147158
148159// good
149- obj .a = 5
160+ obj .a = 5 ;
150161// bad
151- let { a }= obj
152- a = 5
162+ let { a }= obj ;
163+ a = 5 ;
153164```
154165
155166##Inspired
156167
157- - [ mobx] ( https://github.com/mobxjs/mobx )
158- - [ nx-js] ( https://github.com/nx-js/observer-util )
168+ * [ mobx] ( https://github.com/mobxjs/mobx )
169+ * [ nx-js] ( https://github.com/nx-js/observer-util )