Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate authored Dec 21, 2017
2 parents 9744a54 + 2960778 commit bbc6550
Show file tree
Hide file tree
Showing 14 changed files with 333 additions and 141 deletions.
61 changes: 34 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
<p align="center">
<img src="docs/logo.png" height="100">
<h3 align="center">mobx-state-tree</h3>
<p align="center"><i>Opinionated, transactional, MobX powered state container combining the best features of the immutable and mutable world for an optimal DX</i><p>
</p>

[![npm version](https://badge.fury.io/js/mobx-state-tree.svg)](https://badge.fury.io/js/mobx-state-tree)
[![Build Status](https://travis-ci.org/mobxjs/mobx-state-tree.svg?branch=master)](https://travis-ci.org/mobxjs/mobx-state-tree)
[![Coverage Status](https://coveralls.io/repos/github/mobxjs/mobx-state-tree/badge.svg?branch=master)](https://coveralls.io/github/mobxjs/mobx-state-tree?branch=master)
[![Join the chat at https://gitter.im/mobxjs/mobx-state-tree](https://badges.gitter.im/mobxjs/mobx-state-tree.svg)](https://gitter.im/mobxjs/mobx-state-tree?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

</br>

<p>
<img src="docs/mobx-state-tree-logo-gradient.svg" align="left" height="145" width="100"
style="margin-right: 20px"/>
<h4 style="margin: 0;">mobx-state-tree</h4>
<p>
<i>
Opinionated, transactional, MobX powered state container combining the best features of the immutable and mutable world for an optimal DX
</i>
</p>
</p>

> Mobx and MST are amazing pieces of software, for me it is the missing brick when you build React based apps. Thanks for the great work!
Nicolas Galle [full post](https://medium.com/@nicolasgall/i-started-to-use-react-last-year-and-i-loved-it-1ce8d53fec6a)
</br>

> Mobx and MST are amazing pieces of software, for me it is the missing brick when you build React based apps. Thanks for the great work!# Contents
Nicolas Galle [full post](https://medium.com/@nicolasgall/i-started-to-use-react-last-year-and-i-loved-it-1ce8d53fec6a)
Introduction blog post [The curious case of MobX state tree](https://medium.com/@mweststrate/the-curious-case-of-mobx-state-tree-7b4e22d461f)

---
# Contents

* [Installation](#installation)
Expand Down Expand Up @@ -224,14 +231,14 @@ const TodoStore = types
selectedTodo: types.reference(Todo) // 5
})
.views(self => {
return {
get completedTodos() { // 6
return self.todos.filter(t => t.done)
},
findTodosByUser(user) { // 7
return self.todos.filter(t => t.assignee === user)
}
};
return {
get completedTodos() { // 6
return self.todos.filter(t => t.done)
},
findTodosByUser(user) { // 7
return self.todos.filter(t => t.assignee === user)
}
};
})
.actions(self => {
return {
Expand All @@ -241,7 +248,7 @@ const TodoStore = types
title
})
}
};
};
})
```
Expand Down Expand Up @@ -418,7 +425,7 @@ someModel.actions(self => {
#### Action listeners versus middleware
The difference between action listeners and middleware is: Middleware can intercept the action that is about to be invoked, modify arguments, return types etc. Action listeners cannot intercept, and are only notified. Action listeners receive the action arguments in a serializable format, while middleware receive the raw arguments. (`onAction` is actually just a built-in middleware)
The difference between action listeners and middleware is: Middleware can intercept the action that is about to be invoked, modify arguments, return types etc. Action listeners cannot intercept, and are only notified. Action listeners receive the action arguments in a serializable format, while middleware receives the raw arguments. (`onAction` is actually just a built-in middleware)
For more details on creating middleware, see the [docs](docs/middleware.md)
Expand All @@ -444,10 +451,10 @@ const UserStore = types
})
.views(self => ({
get amountOfChildren() {
return users.filter(user => user.age < 18).length
return self.users.filter(user => user.age < 18).length
},
amountOfPeopleOlderThan(age) {
return users.filter(user => user.age > age).length
return self.users.filter(user => user.age > age).length
}
}))

Expand Down Expand Up @@ -550,7 +557,7 @@ console.log(storeInstance.selectedTodo.title)
- Each model can define zero or one `identifier()` properties
- The identifier property of an object cannot be modified after initialization
- Each identifiers / type combination should be unique within the entire tree
- Each identifier / type combination should be unique within the entire tree
- Identifiers are used to reconcile items inside arrays and maps - wherever possible - when applying snapshots
- The `map.put()` method can be used to simplify adding objects that have identifiers to [maps](API.md#typesmap)
- The primary goal of identifiers is not validation, but reconciliation and reference resolving. For this reason identifiers cannot be defined or updated after creation. If you want to check if some value just looks as an identifier, without providing the above semantics; use something like: `types.refinement(types.string, v => v.match(/someregex/))`
Expand Down Expand Up @@ -761,7 +768,7 @@ The object that is returned from the `volatile` initializer function can contain
2. The volatile properties will be only observable be [observable _references_](https://mobx.js.org/refguide/modifiers.html). Values assigned to them will be unmodified and not automatically converted to deep observable structures.
3. Like normal properties, they can only be modified through actions
5. Volatile props will not show up in snapshots, and cannot be updated by applying snapshots
5. Volatile props is preserved during the lifecycle of an instance. See also [reconciliation](#reconciliation)
5. Volatile props are preserved during the lifecycle of an instance. See also [reconciliation](#reconciliation)
4. Changes in volatile props won't show up in the patch or snapshot stream
4. It is currently not supported to define getters / setters in the object returned by `volatile`
Expand Down Expand Up @@ -903,7 +910,7 @@ See the [full API docs](API.md) for more details.
| [`applyAction(node, actionDescription)`](API.md#applyaction) | Replays an action on the targeted node |
| [`applyPatch(node, jsonPatch)`](API.md#applypatch) | Applies a JSON patch, or array of patches, to a node in the tree |
| [`applySnapshot(node, snapshot)`](API.md#applysnapshot) | Updates a node with the given snapshot |
| [`createActionTrackingMiddleware`](API.md#createactiontrackingmiddleware) | Utility to make writing middleware that track async actions less cumbersome |
| [`createActionTrackingMiddleware`](API.md#createactiontrackingmiddleware) | Utility to make writing middleware that tracks async actions less cumbersome |
| [`clone(node, keepEnvironment?: true \| false \| newEnvironment)`](API.md#clone) | Creates a full clone of the given node. By default preserves the same environment |
| [`decorate(middleware, function)`](API.md#decorate) | Attaches middleware to a specific action (or flow) |
| [`destroy(node)`](API.md#destroy) | Kills `node`, making it unusable. Removes it from any parent in the process |
Expand Down Expand Up @@ -1003,7 +1010,7 @@ const Square = types
}
}))

// create a new type, based of Square
// create a new type, based on Square
const Box = Square
.named("Box")
.views(self => {
Expand Down Expand Up @@ -1116,7 +1123,7 @@ const Todo = types.model({
type ITodo = typeof Todo.Type // => ITodo is now a valid TypeScript type with { title: string; setTitle: (v: string) => void }
```
Due the way typeof operator works, when working with big and deep models trees, it might make your IDE/ts server takes alot of CPU time and freeze vscode (or others)
Due to the way typeof operator works, when working with big and deep models trees, it might make your IDE/ts server takes a lot of CPU time and freeze vscode (or others)
A partial solution for this is to turn the `.Type` into an interface.
```ts
type ITodoType = typeof Todo.Type;
Expand Down Expand Up @@ -1228,7 +1235,7 @@ export const Todo = types.model({
export type ITodo = typeof Todo.Type
```
It aint pretty, but it works.
It ain't pretty, but it works.
### How does MST compare to Redux
Expand Down
8 changes: 7 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# next
# 1.3.1

* Fixed bug where `flows` didn't properly batch there next ticks properly in actions, significantly slowing processes down. Fixes [#563](https://github.com/mobxjs/mobx-state-tree/issues/563)

# 1.3.0

* Significantly improved the undo/redo manager. The undo manager now supports groups. See [#504](https://github.com/mobxjs/mobx-state-tree/pull/504) by @robinfehr! See the [updated docs](https://github.com/mobxjs/mobx-state-tree/blob/master/packages/mst-middlewares/README.md#undomanager) for more details.
* Significantly improved performance, improvements of 20% could be expected, but changes of course per case. See [#553](https://github.com/mobxjs/mobx-state-tree/pull/553)
* Implemented `actionLogger` middleware, which logs most events for async actions
* Slightly changed the order in which life cycle hooks are fired. `afterAttach` will no fire first on the parent, then on the children. So, unlike `afterCreate`, in `afterAttach` one can assume in `afterAttach that the parent has completely initialized.

Expand Down
4 changes: 2 additions & 2 deletions docs/async-actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ This approach works fine and has great type inference, but comes with a few down

1. For complex flows, which update data in the middle of the flow, a lot of "utility" actions need to be created.
2. Each step of the flow is exposed as action to the outside world. In the above example, one could (but shouldn't) directly invoke `store.fetchProjectsSuccess([])`
2. Middleware cannot distinguish the flow initiating action from the handler actions. This means that actions like `fetchProjectsSuccess` will become part of the recorded action list, although you probably never want to replay it (as replaying `fetchProjects` itself will cause the handler actions to be fired in the end).
3. Middleware cannot distinguish the flow initiating action from the handler actions. This means that actions like `fetchProjectsSuccess` will become part of the recorded action list, although you probably never want to replay it (as replaying `fetchProjects` itself will cause the handler actions to be fired in the end).

## Using generators

Expand Down Expand Up @@ -99,7 +99,7 @@ For example, the `onAction` middleware will only record starting asynchronous fl
After all, when replaying the invocation will lead to the other steps being executed automatically.
Besides that, each step in the generator is allowed to modify it's own instance, and there is no need to expose the individual flow steps as actions.

See the [bookshop example sources](https://github.com/mobxjs/mobx-state-tree/blob/adba1943af263898678fe148a80d3d2b9f8dbe63/examples/bookshop/src/stores/BookStore.js#L25) for a more extensive example.
See the [bookshop example sources](https://github.com/mobxjs/mobx-state-tree/blob/5a4bd43ac874cddbf91b40eeef20043198477084/packages/mst-example-bookshop/src/stores/BookStore.js#L25) for a more extensive example.

Using generators requires Promises and generators to be available. Promises can easily be polyfilled although they tend to be available on every modern JS environment. Generators are well supported as well, and both TypeScript and Babel can compile generators to ES5.

Expand Down
155 changes: 155 additions & 0 deletions docs/mobx-state-tree-logo-gradient.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"lerna": "2.4.0",
"npmClient": "yarn",
"useWorkspaces": true,
"version": "1.3.0"
"version": "1.3.1"
}
2 changes: 1 addition & 1 deletion packages/mobx-state-tree/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mobx-state-tree",
"version": "1.3.0",
"version": "1.3.1",
"description": "Opinionated, transactional, MobX powered state container",
"main": "dist/mobx-state-tree.js",
"umd:main": "dist/mobx-state-tree.umd.js",
Expand Down
Loading

0 comments on commit bbc6550

Please sign in to comment.