Skip to content

Commit 847ec7e

Browse files
committed
chore: update start example to be classless
1 parent d519643 commit 847ec7e

File tree

2 files changed

+25
-33
lines changed

2 files changed

+25
-33
lines changed

README.md

+13-17
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ MobX is made possible by the generosity of the sponsors below, and many other [i
4444
<a href="https://www.easeus.com/?utm_source=github_mobxjs_sponsorship&utm_medium=readme&utm_campaign=sponsorship"><img src="https://mobx.js.org/assets/easeus.png" align="center" width="100" title="EaseUS" alt="EaseUS"/></a>
4545

4646
**🥉 Bronze sponsors (\$500+ total contributions):**<br/>
47+
4748
<a href="https://www.bugsnag.com/platforms/react-error-reporting?utm_source=MobX&utm_medium=Website&utm_content=open-source&utm_campaign=2019-community&utm_term=20190913"><img src="https://mobx.js.org/assets/bugsnag.jpg" align="center" width="100" title="Bugsnag" alt="Bugsnag"/></a>
4849
<a href="https://space307.com/?utm_source=sponsorship&utm_medium=mobx&utm_campaign=readme"><img src="https://mobx.js.org/assets/space307.png" align="center" width="100" title="Space307" alt="Space307"/></a>
4950
<a href="https://mantro.net/jobs/warlock"><img src="https://mobx.js.org/assets/mantro.png" align="center" width="100" title="mantro GmbH" alt="mantro GmbH"></a>
@@ -106,26 +107,22 @@ So what does code that uses MobX look like?
106107
import React from "react"
107108
import ReactDOM from "react-dom"
108109
import { makeAutoObservable } from "mobx"
109-
import { observer } from "mobx-react"
110+
import { observer } from "mobx-react-lite"
110111

111112
// Model the application state.
112-
class Timer {
113-
secondsPassed = 0
114-
115-
constructor() {
116-
makeAutoObservable(this)
117-
}
118-
119-
increase() {
120-
this.secondsPassed += 1
121-
}
122-
123-
reset() {
124-
this.secondsPassed = 0
125-
}
113+
function createTimer() {
114+
return makeAutoObservable({
115+
secondsPassed: 0,
116+
increase() {
117+
this.secondsPassed += 1
118+
},
119+
reset() {
120+
this.secondsPassed = 0
121+
}
122+
})
126123
}
127124

128-
const myTimer = new Timer()
125+
const myTimer = createTimer()
129126

130127
// Build a "user interface" that uses the observable state.
131128
const TimerView = observer(({ timer }) => (
@@ -178,7 +175,6 @@ The **[MobX Quick Start Guide](https://www.packtpub.com/product/mobx-quick-start
178175
- [React Amsterdam 2016: State Management Is Easy](https://www.youtube.com/watch?v=ApmSsu3qnf0&feature=youtu.be) by Michel Weststrate, _20 min_, [slides](https://speakerdeck.com/mweststrate/state-management-is-easy-introduction-to-mobx).
179176
- {🚀} [React Live 2019: Reinventing MobX](https://www.youtube.com/watch?v=P_WqKZxpX8g) by Max Gallo, _27 min_.
180177

181-
182178
## Credits
183179

184180
MobX is inspired by reactive programming principles, which are for example used in spreadsheets. It is inspired by model–view–viewmodel frameworks like [MeteorJS's Tracker](https://docs.meteor.com/api/tracker.html), [Knockout](https://knockoutjs.com/) and [Vue.js](https://vuejs.org/), but MobX brings _transparent functional reactive programming_ (TFRP, a concept which is further explained in the [MobX book](https://www.packtpub.com/product/mobx-quick-start-guide/9781789344837)) to the next level and provides a standalone implementation. It implements TFRP in a glitch-free, synchronous, predictable and efficient manner.

docs/README.md

+12-16
Original file line numberDiff line numberDiff line change
@@ -103,26 +103,22 @@ So what does code that uses MobX look like?
103103
import React from "react"
104104
import ReactDOM from "react-dom"
105105
import { makeAutoObservable } from "mobx"
106-
import { observer } from "mobx-react"
106+
import { observer } from "mobx-react-lite"
107107

108108
// Model the application state.
109-
class Timer {
110-
secondsPassed = 0
111-
112-
constructor() {
113-
makeAutoObservable(this)
114-
}
115-
116-
increase() {
117-
this.secondsPassed += 1
118-
}
119-
120-
reset() {
121-
this.secondsPassed = 0
122-
}
109+
function createTimer() {
110+
return makeAutoObservable({
111+
secondsPassed: 0,
112+
increase() {
113+
this.secondsPassed += 1
114+
},
115+
reset() {
116+
this.secondsPassed = 0
117+
}
118+
})
123119
}
124120

125-
const myTimer = new Timer()
121+
const myTimer = createTimer()
126122

127123
// Build a "user interface" that uses the observable state.
128124
const TimerView = observer(({ timer }) => (

0 commit comments

Comments
 (0)