mobx-utils
Advanced tools
Changelog
3.1.1
whenAsync
, which is like normal when
, except that this when
will return a promise that resolves when the expression becomes truthy. See #66 and #68, by @daedalus28Changelog
3.0.0
fromPromise
:(resolve, reject) => {}
function to fromPromise
, instead of a promise objectfromPromise
no longer creates a wrapping object, but rather extends the given promise, #45fromPromise().reason
fromPromise
. For example, the value
property is now only available if .state === "resolved"
(#41)initialvalue
param from fromPromise
. use fromPromise.fulfilled(value)
instead to create a promise in some ready statefromPromise.reject(reason)
and fromPromise.resolve(value?)
to create a promise based observable in a certain state, see #39state
and value
are now explicit observablesasyncAction
See the docs for details, but the gist of it:
import {asyncAction} from "mobx-utils"
mobx.configure({ enforceActions: "observed" }) // don't allow state modifications outside actions
class Store {
@observable githubProjects = []
@state = "pending" // "pending" / "done" / "error"
@asyncAction
*fetchProjects() { // <- note the star, this a generator function!
this.githubProjects = []
this.state = "pending"
try {
const projects = yield fetchGithubProjectsSomehow() // yield instead of await
const filteredProjects = somePreprocessing(projects)
// the asynchronous blocks will automatically be wrapped actions
this.state = "done"
this.githubProjects = filteredProjects
} catch (error) {
this.state = "error"
}
}
}
now()
now returns current date time if invoked from outside a reactive contextChangelog
2.0.2
Changelog
2.0.1
Changelog
1.1.6
reset()
on lazyObservable, see #28 by @daitr92Changelog
1.1.5
Changelog
1.1.4
now(interval?)
, to get an observable that returns the current time at a specified interval