Skip to content

Commit

Permalink
Merge branch '6.1.0.reversion'
Browse files Browse the repository at this point in the history
  • Loading branch information
danielearwicker committed Dec 14, 2020
2 parents ed21788 + 07704c3 commit 120fbf5
Show file tree
Hide file tree
Showing 42 changed files with 4,628 additions and 10,808 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ node_modules
coverage
built
.DS_Store
interactive-tests/.cache
interactive-tests/dist
Empty file removed .nojekyll
Empty file.
48 changes: 19 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ _Define a computed by returning a Promise_

*"People starting with MobX tend to use reactions [*autorun*] too often. The golden rule is: if you want to create a value based on the current state, use computed."* - [MobX - Concepts & Principles](http://mobxjs.github.io/mobx/intro/concepts.html)

# About MobX 6

An attempt was made, then abandoned, to quick-fix this library to work with MobX 6, but it didn't work out (to put it mildly). Any suggestions for how to fix it are welcome! For now it only works with MobX versions 3.0 to 5.x.

It's possible the API may need to be cut down to something a bit simpler with fewer guarantees but still achieving the basic goal.

# What is this for?

A `computed` in MobX is defined by a function, which consumes other observable values and is automatically re-evaluated, like a spreadsheet cell containing a calculation.
Expand All @@ -27,10 +33,11 @@ creditScore = promisedComputed(0, async () => {

[Further explanation, rationale, etc.](../../wiki)

# New in Version 6.0.0...
# New in Version 3.0.0...

* Breaking change: the old API (deprecated for over three years, seems fair!) has been removed. Stay tuned for a migration guide below.
* Support for MobX 6
There is a completely new API, much more modular and made of simple, testable pieces. The
old API is deprecated, though is still available for now. First here's how the current
features work. Stay tuned for a migration guide below.

----

Expand All @@ -55,11 +62,9 @@ The returned object also has a `busy` property that is true while a promise is s
It also has a `refresh` method that can be called to force a new promise to be requested
immediately (bypassing the delay time).

There is also a method `getNonReactive()` which can be used outside reactive contexts. It is
a convenience for writing unit tests. Note that it will return the most recent value that was
computed while the `asyncComputed` was being observed.

[Generated references docs](http://earwicker.com/computed-async-mobx/typedoc/modules/_asynccomputed_.html)
**New in 4.2.0:** there is also a method `getNonReactive()` which can be used outside reactive
contexts. It is a convenience for writing unit tests. Note that it will return the most recent
value that was computed while the `asyncComputed` was being observed.

### Example

Expand Down Expand Up @@ -93,8 +98,6 @@ of being fully synchronous if the `compute` function returns a plain value.

Exactly as `asyncComputed`.

[Generated references docs](http://earwicker.com/computed-async-mobx/typedoc/modules/_promisedcomputed_.html)

### Example

```ts
Expand All @@ -115,7 +118,8 @@ If the `this.userName` property is an observable and is modified, the
## throttledComputed

Like the standard `computed` but with support for delaying for a specified number of
milliseconds before re-evaluation.
milliseconds before re-evaluation. It is like a computed version of the standard
`autorunAsync`; the advantage is that you don't have to manually dispose it.

(Note that `throttledComputed` has no special functionality for handling promises.)

Expand All @@ -133,11 +137,6 @@ every time you request the value.

It also has a `refresh` method that *immediately* (synchronously) re-evaluates the function.

The value returned from `get` is always a value obtained from the provided `compute` function,
never silently substituted.

[Generated references docs](http://earwicker.com/computed-async-mobx/typedoc/modules/_throttledcomputed_.html)

### Example

```ts
Expand All @@ -156,8 +155,8 @@ least 500 milliseconds.

## autorunThrottled

Much like the standard `autorun` with the `delay` option, except that the initial run of
the function happens synchronously.
Much like the standard `autorunAsync`, except that the initial run of the function happens
synchronously.

(This is used by `throttledComputed` to allow it to be synchronously initialized.)

Expand All @@ -176,8 +175,6 @@ is an observable, so it can be used from other MobX contexts. It can also be use
MobX reactive contexts but (like standard `computed`) it reverts to simply re-evaluating
every time you request the value.

[Generated references docs](http://earwicker.com/computed-async-mobx/typedoc/modules/_autorunthrottled_.html)

----

# Installation
Expand Down Expand Up @@ -224,11 +221,6 @@ class Person {
get percentage() {
return Math.round(this.creditScore.get() / 10);
}

// For MobX 6
constructor() {
makeObservable(this);
}
}
```

Expand All @@ -246,13 +238,11 @@ For example, here we fetch two pieces of data to combine them together:

```ts
answer = asyncComputed(0, 1000, async () => {

// Don't do this!!
const part1 = await fetch(this.part1Uri),
part2 = await fetch(this.part2Uri);

// combine part1 and part2 into a result somehow...
return part1 + part2;
return result;
});
```

Expand All @@ -279,7 +269,7 @@ When in doubt, move all your gathering of observable values to the start of the

# Migration

Versions prior to 3.0.0 had a different API. It was a single `computedAsync` function that had all the
The API of previous versions is still available. It was a single `computedAsync` function that had all the
capabilities, like a Swiss-Army Knife, making it difficult to test, maintain and use. It also had some
built-in functionality that could just as easily be provided by user code, which is pointless and only
creates obscurity.
Expand Down
Empty file removed docs/.nojekyll
Empty file.
1 change: 0 additions & 1 deletion docs/typedoc/assets/css/main.css

This file was deleted.

Binary file removed docs/typedoc/assets/images/icons.png
Binary file not shown.
Binary file removed docs/typedoc/assets/images/icons@2x.png
Binary file not shown.
Binary file removed docs/typedoc/assets/images/widgets.png
Binary file not shown.
Binary file removed docs/typedoc/assets/images/widgets@2x.png
Binary file not shown.
Loading

0 comments on commit 120fbf5

Please sign in to comment.