A brand new Meteor.js has landed with nice updates concerning the React Skeletons, MongoDB sort definitions, and the chance to run async reactive code inside a Tracker.autorun
.
As for our typical replace on our street to a fibers-free MeteorJS, for this launch, the one new function that we’ve is now the chance to run async code in a Tracker.autorun
.
Earlier than discussing what has modified, it’s crucial to provide context about how we did previously. This got here from our docs earlier than 2.10:
Tracker.autorun
can settle for anasync
callback operate. Nevertheless, the async callback operate will solely be depending on reactive capabilities known as previous to any known as capabilities that return a promise.
That might translate into:
The instance under just isn’t depending on reactive adjustments to the
Meteor.customers
assortment. As a result of it’s depending on nothing reactive, it would run solely as soon as:
Tracker.autorun(async operate example1() {
let asyncData = await asyncDataFunction();
let customers = Meteor.customers.discover({}).fetch();
});
Earlier than, we would wish to do some workaround to make this reactive, putting all reactive calls first after which getting async capabilities. This was not as ergonomic as we needed it to be and would translate to code wanting like this:
Tracker.autorun(async operate example2() {
let customers = Meteor.customers.discover({}).fetch();
let asyncData = await asyncDataFunction();
});
Now that you could be use strategies like fetchAsync()
That would make reactive knowledge exhausting to make use of. @radekmie has achieved this superior PR introducing a solution to take care of async code. The primary instance that we needed to change on this new API would appear like this:
Tracker.autorun(async operate example1(computation) {
let asyncData = await Tracker.withComputation(computation, () => asyncDataFunction());
let customers = Meteor.customers.discover({}).fetch();
});
One other instance will be seen under utilizing the brand new
fetchAsync
API
Tracker.autorun(async operate example2(computation) {
let asyncData = await Tracker.withComputation(computation, () => asyncDataFunction());
let customers = await Tracker.withComputation(computation, () => Meteor.customers.discover({}).fetchAsync());
});
If any doubts on find out how to use this new function, come up, please attain out to us within the boards or on GitHub.
Since v2.8.1, we’ve had direct TypeScript help within the Meteor.js core. On this new launch, we’re bringing the Core MongoDB Driver sort definitions and exposing them as a substitute of utilizing a home made model of these typings.
You may examine it higher on this PR made by @perbergland.
Notable mentions are:
You may examine different updates on the discharge PR or within the changelog.
For making this nice framework even higher!