Skip to content

Commit

Permalink
Merge branch 'master' into mobx3
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate committed Nov 22, 2016
2 parents e374a7c + 90f8f10 commit fdbcbd2
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 3 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 2.7.0
# 3.0.0

### Automatic inference of computed properties has been deprecated.

Expand Down Expand Up @@ -84,6 +84,11 @@ See [#621](https://github.com/mobxjs/mobx/issues/621)
* `ObservableMap.toJs` (use `toJS`)
* invoking `observe` and `inject` with plain javascript objects

# 2.6.3

* Fixed #603: exceptions in transaction breaks future reactions
* Improved typings of `toJS`
* Introduced `setReactionScheduler`. Internal api used by mobx-react@4 to be notified when reactions will be run

# 2.6.2

Expand Down
73 changes: 72 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ _Simple, scalable state management_
[![Coverage Status](https://coveralls.io/repos/mobxjs/mobx/badge.svg?branch=master&service=github)](https://coveralls.io/github/mobxjs/mobx?branch=master)
[![Join the chat at https://gitter.im/mobxjs/mobx](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/mobxjs/mobx?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Discuss MobX on Hashnode](https://hashnode.github.io/badges/mobx.svg)](https://hashnode.com/n/mobx)
[![OpenCollective](https://opencollective.com/mobx/backers/badge.svg)](#backers)
[![OpenCollective](https://opencollective.com/mobx/sponsors/badge.svg)](#sponsors)
[![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://mobxjs.github.io/mobx/donate.html)

![npm install mobx](https://nodei.co/npm/mobx.png?downloadRank=true&downloads=true)
Expand Down Expand Up @@ -114,7 +116,7 @@ If you are using React, you can turn your (stateless function) components into r
```javascript
import React, {Component} from 'react';
import ReactDOM from 'react-dom';
import {observer} from "mobx-react";
import {observer} from 'mobx-react';

@observer
class TodoListView extends Component {
Expand Down Expand Up @@ -293,3 +295,72 @@ See the [changelog](https://github.com/mobxjs/mobx/blob/master/CHANGELOG.md#200)
Was MobX key in making your project a success? Share the victory by using the [donate button](https://mobxjs.github.io/mobx/donate.html)!
MobX is developed largely in free time, so any ROI is appreciated :-).
If you leave a name you will be added to the [sponsors](https://github.com/mobxjs/mobx/blob/master/sponsors.md) list :).

### Backers
Support us with a monthly donation and help us continue our activities. [[Become a backer](https://opencollective.com/mobx#backer)]

<a href="https://opencollective.com/mobx/backer/0/website" target="_blank"><img src="https://opencollective.com/mobx/backer/0/avatar.svg"></a>
<a href="https://opencollective.com/mobx/backer/1/website" target="_blank"><img src="https://opencollective.com/mobx/backer/1/avatar.svg"></a>
<a href="https://opencollective.com/mobx/backer/2/website" target="_blank"><img src="https://opencollective.com/mobx/backer/2/avatar.svg"></a>
<a href="https://opencollective.com/mobx/backer/3/website" target="_blank"><img src="https://opencollective.com/mobx/backer/3/avatar.svg"></a>
<a href="https://opencollective.com/mobx/backer/4/website" target="_blank"><img src="https://opencollective.com/mobx/backer/4/avatar.svg"></a>
<a href="https://opencollective.com/mobx/backer/5/website" target="_blank"><img src="https://opencollective.com/mobx/backer/5/avatar.svg"></a>
<a href="https://opencollective.com/mobx/backer/6/website" target="_blank"><img src="https://opencollective.com/mobx/backer/6/avatar.svg"></a>
<a href="https://opencollective.com/mobx/backer/7/website" target="_blank"><img src="https://opencollective.com/mobx/backer/7/avatar.svg"></a>
<a href="https://opencollective.com/mobx/backer/8/website" target="_blank"><img src="https://opencollective.com/mobx/backer/8/avatar.svg"></a>
<a href="https://opencollective.com/mobx/backer/9/website" target="_blank"><img src="https://opencollective.com/mobx/backer/9/avatar.svg"></a>
<a href="https://opencollective.com/mobx/backer/10/website" target="_blank"><img src="https://opencollective.com/mobx/backer/10/avatar.svg"></a>
<a href="https://opencollective.com/mobx/backer/11/website" target="_blank"><img src="https://opencollective.com/mobx/backer/11/avatar.svg"></a>
<a href="https://opencollective.com/mobx/backer/12/website" target="_blank"><img src="https://opencollective.com/mobx/backer/12/avatar.svg"></a>
<a href="https://opencollective.com/mobx/backer/13/website" target="_blank"><img src="https://opencollective.com/mobx/backer/13/avatar.svg"></a>
<a href="https://opencollective.com/mobx/backer/14/website" target="_blank"><img src="https://opencollective.com/mobx/backer/14/avatar.svg"></a>
<a href="https://opencollective.com/mobx/backer/15/website" target="_blank"><img src="https://opencollective.com/mobx/backer/15/avatar.svg"></a>
<a href="https://opencollective.com/mobx/backer/16/website" target="_blank"><img src="https://opencollective.com/mobx/backer/16/avatar.svg"></a>
<a href="https://opencollective.com/mobx/backer/17/website" target="_blank"><img src="https://opencollective.com/mobx/backer/17/avatar.svg"></a>
<a href="https://opencollective.com/mobx/backer/18/website" target="_blank"><img src="https://opencollective.com/mobx/backer/18/avatar.svg"></a>
<a href="https://opencollective.com/mobx/backer/19/website" target="_blank"><img src="https://opencollective.com/mobx/backer/19/avatar.svg"></a>
<a href="https://opencollective.com/mobx/backer/20/website" target="_blank"><img src="https://opencollective.com/mobx/backer/20/avatar.svg"></a>
<a href="https://opencollective.com/mobx/backer/21/website" target="_blank"><img src="https://opencollective.com/mobx/backer/21/avatar.svg"></a>
<a href="https://opencollective.com/mobx/backer/22/website" target="_blank"><img src="https://opencollective.com/mobx/backer/22/avatar.svg"></a>
<a href="https://opencollective.com/mobx/backer/23/website" target="_blank"><img src="https://opencollective.com/mobx/backer/23/avatar.svg"></a>
<a href="https://opencollective.com/mobx/backer/24/website" target="_blank"><img src="https://opencollective.com/mobx/backer/24/avatar.svg"></a>
<a href="https://opencollective.com/mobx/backer/25/website" target="_blank"><img src="https://opencollective.com/mobx/backer/25/avatar.svg"></a>
<a href="https://opencollective.com/mobx/backer/26/website" target="_blank"><img src="https://opencollective.com/mobx/backer/26/avatar.svg"></a>
<a href="https://opencollective.com/mobx/backer/27/website" target="_blank"><img src="https://opencollective.com/mobx/backer/27/avatar.svg"></a>
<a href="https://opencollective.com/mobx/backer/28/website" target="_blank"><img src="https://opencollective.com/mobx/backer/28/avatar.svg"></a>
<a href="https://opencollective.com/mobx/backer/29/website" target="_blank"><img src="https://opencollective.com/mobx/backer/29/avatar.svg"></a>

### Sponsors

Become a sponsor and get your logo on our README on Github with a link to your site. [[Become a sponsor](https://opencollective.com/mobx#sponsor)]

<a href="https://opencollective.com/mobx/sponsor/0/website" target="_blank"><img src="https://opencollective.com/mobx/sponsor/0/avatar.svg"></a>
<a href="https://opencollective.com/mobx/sponsor/1/website" target="_blank"><img src="https://opencollective.com/mobx/sponsor/1/avatar.svg"></a>
<a href="https://opencollective.com/mobx/sponsor/2/website" target="_blank"><img src="https://opencollective.com/mobx/sponsor/2/avatar.svg"></a>
<a href="https://opencollective.com/mobx/sponsor/3/website" target="_blank"><img src="https://opencollective.com/mobx/sponsor/3/avatar.svg"></a>
<a href="https://opencollective.com/mobx/sponsor/4/website" target="_blank"><img src="https://opencollective.com/mobx/sponsor/4/avatar.svg"></a>
<a href="https://opencollective.com/mobx/sponsor/5/website" target="_blank"><img src="https://opencollective.com/mobx/sponsor/5/avatar.svg"></a>
<a href="https://opencollective.com/mobx/sponsor/6/website" target="_blank"><img src="https://opencollective.com/mobx/sponsor/6/avatar.svg"></a>
<a href="https://opencollective.com/mobx/sponsor/7/website" target="_blank"><img src="https://opencollective.com/mobx/sponsor/7/avatar.svg"></a>
<a href="https://opencollective.com/mobx/sponsor/8/website" target="_blank"><img src="https://opencollective.com/mobx/sponsor/8/avatar.svg"></a>
<a href="https://opencollective.com/mobx/sponsor/9/website" target="_blank"><img src="https://opencollective.com/mobx/sponsor/9/avatar.svg"></a>
<a href="https://opencollective.com/mobx/sponsor/10/website" target="_blank"><img src="https://opencollective.com/mobx/sponsor/10/avatar.svg"></a>
<a href="https://opencollective.com/mobx/sponsor/11/website" target="_blank"><img src="https://opencollective.com/mobx/sponsor/11/avatar.svg"></a>
<a href="https://opencollective.com/mobx/sponsor/12/website" target="_blank"><img src="https://opencollective.com/mobx/sponsor/12/avatar.svg"></a>
<a href="https://opencollective.com/mobx/sponsor/13/website" target="_blank"><img src="https://opencollective.com/mobx/sponsor/13/avatar.svg"></a>
<a href="https://opencollective.com/mobx/sponsor/14/website" target="_blank"><img src="https://opencollective.com/mobx/sponsor/14/avatar.svg"></a>
<a href="https://opencollective.com/mobx/sponsor/15/website" target="_blank"><img src="https://opencollective.com/mobx/sponsor/15/avatar.svg"></a>
<a href="https://opencollective.com/mobx/sponsor/16/website" target="_blank"><img src="https://opencollective.com/mobx/sponsor/16/avatar.svg"></a>
<a href="https://opencollective.com/mobx/sponsor/17/website" target="_blank"><img src="https://opencollective.com/mobx/sponsor/17/avatar.svg"></a>
<a href="https://opencollective.com/mobx/sponsor/18/website" target="_blank"><img src="https://opencollective.com/mobx/sponsor/18/avatar.svg"></a>
<a href="https://opencollective.com/mobx/sponsor/19/website" target="_blank"><img src="https://opencollective.com/mobx/sponsor/19/avatar.svg"></a>
<a href="https://opencollective.com/mobx/sponsor/20/website" target="_blank"><img src="https://opencollective.com/mobx/sponsor/20/avatar.svg"></a>
<a href="https://opencollective.com/mobx/sponsor/21/website" target="_blank"><img src="https://opencollective.com/mobx/sponsor/21/avatar.svg"></a>
<a href="https://opencollective.com/mobx/sponsor/22/website" target="_blank"><img src="https://opencollective.com/mobx/sponsor/22/avatar.svg"></a>
<a href="https://opencollective.com/mobx/sponsor/23/website" target="_blank"><img src="https://opencollective.com/mobx/sponsor/23/avatar.svg"></a>
<a href="https://opencollective.com/mobx/sponsor/24/website" target="_blank"><img src="https://opencollective.com/mobx/sponsor/24/avatar.svg"></a>
<a href="https://opencollective.com/mobx/sponsor/25/website" target="_blank"><img src="https://opencollective.com/mobx/sponsor/25/avatar.svg"></a>
<a href="https://opencollective.com/mobx/sponsor/26/website" target="_blank"><img src="https://opencollective.com/mobx/sponsor/26/avatar.svg"></a>
<a href="https://opencollective.com/mobx/sponsor/27/website" target="_blank"><img src="https://opencollective.com/mobx/sponsor/27/avatar.svg"></a>
<a href="https://opencollective.com/mobx/sponsor/28/website" target="_blank"><img src="https://opencollective.com/mobx/sponsor/28/avatar.svg"></a>
<a href="https://opencollective.com/mobx/sponsor/29/website" target="_blank"><img src="https://opencollective.com/mobx/sponsor/29/avatar.svg"></a>
11 changes: 11 additions & 0 deletions src/core/reaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,16 @@ WhyRun? reaction '${this.name}':
*/
const MAX_REACTION_ITERATIONS = 100;

let reactionScheduler: (fn: () => void) => void = f => f();

export function runReactions() {
// invariant(globalState.inBatch > 0, "INTERNAL ERROR runReactions should be called only inside batch");
if (globalState.isRunningReactions === true || globalState.inTransaction > 0)
return;
reactionScheduler(runReactionsHelper);
}

function runReactionsHelper() {
globalState.isRunningReactions = true;
const allReactions = globalState.pendingReactions;
let iterations = 0;
Expand All @@ -184,3 +190,8 @@ export function runReactions() {
}

export const isReaction = createInstanceofPredicate("Reaction", Reaction);

export function setReactionScheduler(fn: (f: () => void) => void) {
const baseScheduler = reactionScheduler;
reactionScheduler = f => fn(() => baseScheduler(f));
}
4 changes: 3 additions & 1 deletion src/mobx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import { allowStateChanges } from "./core/action";
import { spyReport, spyReportEnd, spyReportStart, isSpyEnabled } from "./core/spy";
import { Lambda } from "./utils/utils";
import { isComputingDerivation } from "./core/derivation";
import { setReactionScheduler } from "./core/reaction";

export const extras = {
allowStateChanges,
Expand All @@ -79,7 +80,8 @@ export const extras = {
shareGlobalState,
spyReport,
spyReportEnd,
spyReportStart
spyReportStart,
setReactionScheduler
};

// Experimental or internal api's (exposed for testing for example)
Expand Down
1 change: 1 addition & 0 deletions test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ test('correct api should be exposed', function(t) {
'isComputingDerivation',
'isSpyEnabled',
'resetGlobalState',
'setReactionScheduler',
'shareGlobalState',
'spyReport',
'spyReportEnd',
Expand Down
8 changes: 8 additions & 0 deletions test/observables.js
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,14 @@ test('603 - transaction should not kill reactions', t => {

}

t.equal(a.observers.length, 1)
t.equal(d.$mobx.observing.length, 1)
t.deepEqual(__mobxGlobal.inBatch, 0)
t.deepEqual(__mobxGlobal.inTransaction, 0)
t.deepEqual(__mobxGlobal.pendingReactions.length, 0)
t.deepEqual(__mobxGlobal.pendingUnobservations.length, 0)
t.deepEqual(__mobxGlobal.trackingDerivation, null)

t.equal(b, 2)
a.set(3)
t.equal(b, 3)
Expand Down
51 changes: 51 additions & 0 deletions test/perf/perf.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

One observers many observes one - Started/Updated in 35/26 ms.
500 props observing sibling - Started/Updated in 3/5 ms.
Late dependency change - Updated in 59ms.
Unused computables - Updated in 0 ms.
Unused observables - Updated in 9 ms.
Array reduce - Started/Updated in 30/25 ms.
Array loop - Started/Updated in 125/173 ms.
Order system batched: false tracked: true Started/Updated in 448/44 ms.
Order system batched: true tracked: true Started/Updated in 93/43 ms.
Order system batched: false tracked: false Started/Updated in 131/65 ms.
Order system batched: true tracked: false Started/Updated in 110/46 ms.

Create array - Created in 473ms.

Create array (non-recursive) Created in 169ms.
Observable with many observers + dispose: 1240ms
expensive sort: created 5023
expensive sort: updated 15817
expensive sort: disposed641
native plain sort: updated 1643
computed memoization 1ms
create folders 1ms.
create displayfolders 1ms.
create text 271ms.
collapse folder 1ms.
uncollapse folder 0ms.
change name of folder 327ms.
search 47ms.
unsearch 228ms.
reactive folder tree [total]
878ms.
create folders 28ms.
create displayfolders 1ms.
create text 116ms.
collapse folder 3ms.
uncollapse folder 6ms.
change name of folder 10ms.
search 29ms.
unsearch 20ms.
reactive folder tree [total]
214ms.
create boxes 106ms.
mutations 380ms.
total 498ms.
create boxes 118ms.
mutations 945ms.
total 1175ms.


Completed performance suite in 30.532 sec.

0 comments on commit fdbcbd2

Please sign in to comment.