You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
##### <center>A [Five minute, interactive introduction](https://mweststrate.github.io/mobservable/getting-started.html) to Mobservable and React</center>
15
14
16
-
Mobservable is light-weight standalone library to create reactive primitives, functions, arrays and objects.
17
-
The goal of mobservable is simple:
18
15
19
-
1. Write simple views. Views should be subscription free.
20
-
2. Write simple controllers and stores. Change data without thinking about how this should be reflected in views.
21
-
3. Allow flexible model design, be able to use mutable objects, arrays, classes, real references, and cyclic data structures in your app.
22
-
4. Performance: find the absolute minimum amount of changes that are needed to update views.
23
-
5. Views* should be updated atomically and sychronously without showing stale or intermediate values.
Mobservable is born as part of an enterprise scale visual editor,
26
-
which needs high performance rendering and covers over 400 different domain concepts.
27
-
So the best performance and the simplest possible controller and view code are both of the utmost importance.
28
-
See [this blog](https://www.mendix.com/tech-blog/making-react-reactive-pursuit-high-performing-easily-maintainable-react-apps/) for more details about that journey.
29
-
Mobservable applies reactive programming behind the scenes and is inspired by MVVM frameworks like knockout and ember, yet less obtrusive to use.
18
+
## Introduction
30
19
31
-
\* 'Views' should be interpreted in the broadest sense: User interface, derived data, backend storage; anything that can be derived from your data in a pure manner is a view of the data.
20
+
Mobservable is a library to create reactive state and views. Mobservable updates views automatically when the state changes, and thereby achieves [inversion of control](https://en.wikipedia.org/wiki/Inversion_of_control). This has major benefits for the simplicity, maintainability and performance of your code. This is the promise of Mobservable:
21
+
* Write complex applications which unmatched simple code.
22
+
* Enable unobtrusive state management: be free to use mutable objects, cyclic references, classes and real references to store state.
23
+
* Write declarative views that track their own dependencies. No subscriptions, cursors or other redundant declarations to manage.
24
+
* Build [high performing](mendix.com/tech-blog/making-react-reactive-pursuit-high-performing-easily-maintainable-react-apps/) React applications without Flux or Immutable data structures.
25
+
* Predictable behavior: all views are updated synchronously and atomically.
32
26
33
27
## The essentials
34
28
35
-
Mobservable can be summarized in two functions that will fundamentally simplify the way you write Reactjs applications. Lets take a look at this really really simple timer application:
29
+
Mobservable can be summarized in two functions that will fundamentally simplify the way you write React applications. Lets take a look at this really really simple timer application:
36
30
37
31
```javascript
38
32
var timerData = {
@@ -52,8 +46,10 @@ var Timer = React.createClass({
So what will this app do? It does nothing! The timer increases every second, but the UI never responds to that. After the interval updates the timer we should force the UI to update.
56
-
But that is the kind of dependency we want to avoid in our code. So let's apply two simple functions of mobservable instead to fix this issue:
49
+
So what will this app do? It does nothing! The timer increases every second, but the will UI never update. To fix that, we should force the UI to refresh somehow upon each interval.
50
+
But that is the kind of dependency we should avoid in our code. We shouldn't have to _pull_ data from our state to update the UI. Instead, the data structures should be in control and call the UI when it needs an update. The state should be _pushed_ throughout our application. This is called inversion of control.
51
+
52
+
We can apply two simple functions of Mobservable to achieve this.
57
53
58
54
### mobservable.makeReactive
59
55
@@ -75,7 +71,7 @@ var Timer = mobservable.reactiveComponent(React.createClass{
75
71
}));
76
72
```
77
73
78
-
Thats all folks! Its as simple as that. The `Timer` will now automatically update each time `timerData.secondsPassed` is altered.
74
+
Its as simple as that. The `Timer` will now automatically update each time `timerData.secondsPassed` is altered.
79
75
The actual interesting thing about these changes are the things that are *not* in the code:
80
76
81
77
* The `setInterval` method didn't alter. It still treats `timerData` as a plain JS object.
@@ -93,118 +89,24 @@ It does not only work for plain objects, but also for arrays, functions, classes
The following simple todo application can be found up & running on https://mweststrate.github.io/mobservable. A full TodoMVC implementation can be found [here](https://github.com/mweststrate/todomvc/tree/master/examples/react-mobservable).
99
-
Note how the array, function and primitive of `todoStore` will all become reactive. There are just three calls to `mobservable` and all the components are kept in sync with the `todoStore`.
*[Edit](https://mweststrate.github.io/mobservable/getting-started.html#demo) a simple ToDo application online.
196
96
*`npm install mobservable --save`
197
-
*clone the boilerplate repository containing the above example from: https://github.com/mweststrate/react-mobservable-boilerplate
198
-
*or fork this [JSFiddle](https://jsfiddle.net/mweststrate/wgbe4guu/)
97
+
*Clone the boilerplate repository containing the above example from: https://github.com/mweststrate/react-mobservable-boilerplate.
98
+
*Or fork this [JSFiddle](https://jsfiddle.net/mweststrate/wgbe4guu/).
199
99
200
100
## Examples
201
101
102
+
* The [ports of the _Notes_ and _Kanban_ examples](https://github.com/survivejs/mobservable-demo) from the book "SurviveJS - Webpack and React" to mobservable.
202
103
* A simple webshop using [React + mobservable](https://jsfiddle.net/mweststrate/46vL0phw) or [JQuery + mobservable](http://jsfiddle.net/mweststrate/vxn7qgdw).
*[Simple timer](https://jsfiddle.net/mweststrate/wgbe4guu/) application in JSFiddle.
204
105
*[TodoMVC](https://rawgit.com/mweststrate/todomvc/immutable-to-observable/examples/react-mobservable/index.html#/), based on the ReactJS TodoMVC.
205
106
206
107
## Read more
207
108
109
+
*[Five minute interactive introducton](https://mweststrate.github.io/mobservable/getting-started.html) to Mobservable and React
208
110
*[Making React reactive: the pursuit of high performing, easily maintainable React apps](https://www.mendix.com/tech-blog/making-react-reactive-pursuit-high-performing-easily-maintainable-react-apps/)
209
111
*[Pure rendering in the light of time and state](https://medium.com/@mweststrate/pure-rendering-in-the-light-of-time-and-state-4b537d8d40b1)
@@ -239,20 +141,28 @@ Useful to bridge reactive code to imperative code.
239
141
240
142
## FAQ
241
143
242
-
**Is mobservable a framework?**
144
+
##### Is mobservable a framework?
243
145
244
146
Mobservabe is *not* a framework. It does not tell you how to structure your code, where to store state or how to process events. Yet it might free you from frameworks that poses all kinds of restrictions on your code in the name of performance.
245
147
246
-
**Can I combine flux with mobservable?**
148
+
##### Can I combine flux with mobservable?
247
149
248
150
Flux implementations that do not work on the assumption that the data in their stores is immutable should work well with mobservable.
249
151
However, the need for flux is less when using mobservable.
250
152
Mobservable already optimizes rendering and since it works with most kinds of data, including cycles and classes.
251
153
So other programming paradigms like classic MVC are now can be easily applied in applications that combine ReactJS with mobservable.
252
154
253
-
**Can I use mobservable together with framework X?**
155
+
##### Can I use mobservable together with framework X?
254
156
255
157
Probably.
256
158
Mobservable is framework agnostic and can be applied in any JS environment.
257
159
It just ships with a small function to transform Reactjs components into reactive view functions for convenience.
258
160
Mobservable works just as well server side, and is already combined with JQuery (see this [Fiddle](http://jsfiddle.net/mweststrate/vxn7qgdw)) and [Deku](https://gist.github.com/mattmccray/d8740ea97013c7505a9b).
161
+
162
+
##### Can I record states and re-hydrate them?
163
+
164
+
Yes, some examples are coming shortly!
165
+
166
+
##### Can you tell me how it works?
167
+
168
+
Sure, join the reactiflux channel our checkout [dnode.ts](dnode.ts). Or, submit an issue to motivate me to make some nice drawings :).
0 commit comments