Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add firstRunPromise #12824

Merged
merged 21 commits into from Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
4654adb
Allow for await-able autoruns by adding firstRunPromise to computatio…
DanielDornhardt Oct 4, 2023
1a7ad0d
Merge branch 'devel' into tracker-computation-firstRunPromise
StorytellerCZ Oct 11, 2023
3a8e09a
Apply @radekmie suggestions
harryadel Oct 12, 2023
262a6dc
Merge branch 'devel' of github.com:harryadel/meteor into HEAD
harryadel Oct 12, 2023
6106a2c
Merge branch 'devel' into tracker-firstRunPromise
Grubba27 Nov 6, 2023
ff615a5
[tracker] add then and catch
harryadel Nov 19, 2023
2eb32ba
Merge branch 'tracker-firstRunPromise' of github.com:harryadel/meteor…
harryadel Nov 19, 2023
4fc44cb
Merge branch 'devel' into tracker-firstRunPromise
StorytellerCZ Nov 21, 2023
f2c98ae
[tracker] await then & catch
harryadel Nov 22, 2023
8223aef
Merge branch 'tracker-firstRunPromise' of github.com:harryadel/meteor…
harryadel Nov 22, 2023
e41c8ec
Update packages/tracker/tracker.js
harryadel Nov 28, 2023
2e32f1c
[tracker] Add a test without firstRunPromise
harryadel Nov 29, 2023
a30c131
[tracker] attach methods without the use of 'this'
harryadel Nov 29, 2023
e91c5c2
Merge branch 'devel' into tracker-firstRunPromise
harryadel Nov 29, 2023
8888925
Fixed missing firstRunPromise.
radekmie Nov 29, 2023
cc07fe5
[tracker] Remove joke because Gabriel is no fun :sob:
harryadel Dec 4, 2023
8e90991
[tracker] Use of firstRunPromise is not necessary paragraph
harryadel Dec 4, 2023
01acda0
Merge branch 'release-2.14' into tracker-firstRunPromise
StorytellerCZ Dec 4, 2023
654f366
Merge branch 'release-2.14' into tracker-firstRunPromise
StorytellerCZ Dec 4, 2023
0afa7df
Solve error in jsdoc generation
Grubba27 Dec 4, 2023
c47c3a1
Adjusting typo
Grubba27 Dec 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions docs/generators/changelog/versions/2.14.md
Expand Up @@ -25,15 +25,15 @@ Hacktoberfest release! 🎉
#### Migration Steps

##### Android splash screen
If you have been using `splash-screen` for Cordova, you need to update your code as Android changed their splash screen API,
the `cordova-plugin-splashscreen` is now on `cordova-android` core, so we have removed the dependency from the `splash-screen`
If you have been using `splash-screen` for Cordova, you need to update your code as Android changed their splash screen API,
the `cordova-plugin-splashscreen` is now on `cordova-android` core, so we have removed the dependency from the `splash-screen`
package. As a result we are dropping the support for dark mode splash screen on Android.

To create this now you need to create two themes on your `config.xml` file.

> Note that it's still possible to have it by adding the according themes with App.appendToConfig and App.addResourceFile - but this is not something Meteor will do automagically right now.
> Note that it's still possible to have it by adding the according themes with App.appendToConfig and App.addResourceFile - but this is not something Meteor will do automatically right now.

TODO: @matheusccastroo sample on how the new config should look and link to relevant Cordova docs
TODO: @matheusccastroo sample on how the new config should look and link to relevant Cordova docs

## Breaking Changes

Expand All @@ -55,7 +55,7 @@ TODO: @matheusccastroo sample on how the new config should look and link to rele
- Updated `semver` to v7.5.4
- Updated `@meteorjs/babel` to v7.18.4
- Cordova has been updated to v12.0.1 for Android and v7.0.1 for iOS
- `meteor create` command was re-made to be more interactive
- `meteor create` command was re-made to be more interactive

## Meteor Version Release

Expand Down Expand Up @@ -113,7 +113,7 @@ TODO: @matheusccastroo sample on how the new config should look and link to rele
- Added `appleMail` user agent to allow modern bundle on iPads

* `mongo@get-version`
- Added deprecation messages into type definitions
- Added deprecation messages into type definitions
- Fix ObjectIDs handling in oplogV2V1Converter

* `modules@get-version`
Expand Down Expand Up @@ -166,7 +166,7 @@ TODO: @matheusccastroo sample on how the new config should look and link to rele
- Remove logging request/response in google_server

* NPM `@meteorjs/babel@7.18.4`
- Updated `@meteorjs/reify` to v0.24.1
- Updated `@meteorjs/reify` to v0.24.1

* NPM `@meteorjs/babel-preset-meteor@7.10.1`
- Add Facebook in-app browser
Expand Down
125 changes: 114 additions & 11 deletions docs/history.md
Expand Up @@ -20,21 +20,36 @@ Hacktoberfest release! 🎉

* You can now set `DISABLE_SOCKJS_CORS=1` if you want to prevent SockJS from setting CORS headers. Do not set this option if you will have DDP clients from other origins connecting to the DDP server. [PR](https://github.com/meteor/meteor/pull/12789)

* Added guide on (how to prepare for Meteor 3.0 migration)[https://guide.meteor.com/prepare-meteor-3.0].
* Added guide on [how to prepare for Meteor 3.0 migration](https://guide.meteor.com/prepare-meteor-3.0).

* New DDP merge strategy `NO_MERGE_MULTI`, which is similar to `NO_MERGE`, but it does track whether a document is used by multiple publications. [PR](https://github.com/meteor/meteor/pull/12742)

* Appcache has been further deprecated and moved to the deprecated packages folder.

* Added `Accounts.createUserAsync` into the client.

* Many packages had their underscore dependency removed.

* Cordova has been updated to v12.0.1 for Android and v7.0.1 for iOS

* `meteor create` command is now interactive!

#### Migration Steps

TODO
##### Android splash screen
If you have been using `splash-screen` for Cordova, you need to update your code as Android changed their splash screen API,
the `cordova-plugin-splashscreen` is now on `cordova-android` core, so we have removed the dependency from the `splash-screen`
package. As a result we are dropping the support for dark mode splash screen on Android.

To create this now you need to create two themes on your `config.xml` file.

> Note that it's still possible to have it by adding the according themes with App.appendToConfig and App.addResourceFile - but this is not something Meteor will do automagically right now.

TODO: @matheusccastroo sample on how the new config should look and link to relevant Cordova docs

## Breaking Changes

N/A
* `splash-screen` package has removed the `cordova-plugin-splashscreen` dependency. See migration steps for more info.

## Docs

Expand All @@ -49,19 +64,47 @@ N/A
- Fixed build issue in Vue skeleton
- Updated `source-map-support`
- Fixed bugs in negated “in” and “instanceof” expressions
- Updated `semver` to v7.5.4
- Updated `@meteorjs/babel` to v7.18.4
- Cordova has been updated to v12.0.1 for Android and v7.0.1 for iOS
- `meteor create` command was re-made to be more interactive

## Meteor Version Release

* `accounts-base@2.2.8`
* `accounts-base@2.2.9`
- Ensure that `onLogin` callback fires properly
- Indexes are now created asynchronously

* `accounts-oauth@1.4.3`
- Indexes are now created asynchronously

* `accounts-password@2.4.0`
- Add `Accounts.createUserAsync` to the client, a promise-based version of `Accounts.createUser`
- Indexes are now created asynchronously

* `accounts-passwordless@2.1.3`
* `accounts-passwordless@2.1.4`
- Fix #12401, ensure that user is found with ID
- Indexes are now created asynchronously

* `babel-compiler@7.10.5`
- Updated `@meteorjs/babel` to v7.18.4

* `ddp-server@2.6.2`:
* `boilerplate-generator@1.7.2`
- Removed Underscore dependency

* `browser-policy-content@1.1.3`
- Removed Underscore dependency

* `constraint-solver@1.2.1`
- Removed Underscore dependency

* `crosswalk@1.7.2`
- Updated `cordova-plugin-crosswalk-webview` to v2.4.0
- Deprecated the package

* `ddp-rate-limiter@1.2.1`
- Removed Underscore dependency
* `ddp-server@2.7.0`:
- Allow setting `DISABLE_SOCKJS_CORS` to prevent SockJS from setting CORS headers
- Added new publication strategy `NO_MERGE_MULTI`

Expand All @@ -72,30 +115,84 @@ N/A
- Update `node-fetch` to version 1.6.12
- Update `whatwg-fetch` to version 3.6.17

* `logging@1.3.2`:
* `logging@1.3.3`:
- Added TS types

* `meteor@1.11.3`:
* `meteor@1.11.4`:
- Improve TS types

* `modern-browsers@0.1.10`
- Added `appleMail` user agent to allow modern bundle on iPads

* `mongo@1.16.8`
- Added deprecation messages into type definitions
- Fix ObjectIDs handling in oplogV2V1Converter

* `modules@0.20.0`
- Updated `@meteorjs/babel` to v7.18.4

* `npm-mongo@4.17.0`:
- Bumped MongoDB driver to version 4.17

* `react-fast-refresh@0.2.7`:
* `oauth@2.2.1`
- Indexes are now created asynchronously
- `remove` DB calls migrated to `removeAsync

* `launch-screen@2.0.0`
- Removed `cordova-plugin-splashscreen` dependency

* `logic-solver@2.0.8`
- Removed Underscore dependency

* `package-version-parser@3.2.2`
- Updated `semver` to v7.5.4

* `react-fast-refresh@0.2.8`:
- Updated `semver` to version 7.5.4

* `service-configuration@1.3.2`
- Indexes are now created asynchronously
- Add types for ConfigError

* `socket-stream-client@0.5.2`
- Removed Underscore dependency

* `test-server-tests-in-console-once@1.0.12`
- Removed Underscore dependency

* `tinytest@1.2.3`
- Removed Underscore dependency

* `webapp@1.13.5`
- Updated `cordova-plugin-meteor-webapp` to v2.0.3
- Updated `cookie-parser` to v1.4.6
- Updated `send` to v0.18.0
- Updated `stream-to-string` to v1.2.1
- Updated `qs` to v6.11.2
- Updated `@types/connect` to v3.4.38


## Independent releases

* `google-oauth@1.4.4`:
- Remove logging request/response in google_server

* NPM `@meteorjs/babel@7.18.4`
- Updated `@meteorjs/reify` to v0.24.1

* NPM `@meteorjs/babel-preset-meteor@7.10.1`
- Add Facebook in-app browser

* NPM `cordova-plugin-meteor-webapp@2.0.2`
- Fixed Android hot code push failing

* NPM `cordova-plugin-meteor-webapp@2.0.3`
- Fix pull manifest from correct url if parameter are used in baseurl

* NPM `meteor-node-stubs@1.2.6`
- Update dependencies
- Deep update dependencies that were highlighted by `npm audit`

## Contributors

- [@StorytellerCZ](https://github.com/sponsors/StorytellerCZ)
Expand All @@ -110,6 +207,12 @@ N/A
- [@ebroder](https://github.com/ebroder)
- [@BANSAL-NISHU](https://github.com/BANSAL-NISHU)
- [@salmanhasni](https://github.com/salmanhasni)
- [@jdgjsag67251](https://github.com/jdgjsag67251)
- [@guncebektas](https://github.com/guncebektas)
- [@harryadel](https://github.com/harryadel)
- [@dd137](https://github.com/dd137)
- [@matheusccastroo](https://github.com/matheusccastroo)
- [@mr-loop-1](https://github.com/mr-loop-1)

For making this great framework even better!

Expand Down Expand Up @@ -225,10 +328,10 @@ for more information about the problems and issues you might find while migratin

#### Internal changes

* `ddp-server@2.6.2`:
* `ddp-server@2.7.0`:
- Updated livedata server test to be more easily debbuged.

* `mongo@1.16.7`:
* `mongo@1.16.8`:
- Updated deprecated reference in Mongo package.

#### Migration Steps
Expand Down
41 changes: 38 additions & 3 deletions docs/source/api/tracker.md
Expand Up @@ -80,7 +80,7 @@ If the initial run of an autorun throws an exception, the computation
is automatically stopped and won't be rerun.

### Tracker.autorun and async callbacks
`Tracker.autorun` can accept an `async` callback function.
`Tracker.autorun` can accept an `async` callback function.
To preserve reactivity for the reactive variables inside the async callback function, you must use a `Tracker.withComputation` call as described below:

{% apibox "Tracker.withComputation" %}
Expand All @@ -94,7 +94,7 @@ Tracker.autorun(async function example1(computation) {

// Code after the first await looses Tracker.currentComputation: no reactivity.
reactiveVar2.get(); // This won't trigger a rerun.

// You can bring back reactivity with the Tracker.withCompuation wrapper:
let users = await Tracker.withComputation(computation, () => Meteor.users.findAsync({}).fetch());

Expand All @@ -112,7 +112,7 @@ The `react-meteor-data` package uses `Tracker.withComputation` to make the `useT
More can be seen [here](https://github.com/meteor/react-packages/tree/master/packages/react-meteor-data#maintaining-the-reactive-context)

### Using async callbacks in versions of Meteor prior to 2.10
`Tracker.autorun` can accept an `async` callback function.
`Tracker.autorun` can accept an `async` callback function.
However, the async call back function will only be dependent on reactive functions called prior to any called functions that return a promise.

Example 1 - autorun `example1()` **is not** dependent on reactive changes to the `Meteor.users` collection. Because it is dependent on nothing reactive it will run only once:
Expand Down Expand Up @@ -302,6 +302,41 @@ recomputed at flush time.
This property is a convenience to support the common pattern where a
computation has logic specific to the first run.

{% apibox "Tracker.Computation#firstRunPromise" %}

`Computation.firstRunPromise` will be set to the result of the call of the autorun function after the initial computation has been completed. If the autorun function is an async function, it'll then contain its promise, thus making the completion of the execution await-able. That allows us to manually synchronize autoruns like this:

```js

await Tracker.autorun(async () => {
await Meteor.userAsync();
(...more async code...)
}).firstRunPromise;

await Tracker.autorun(async () => {
await asyncSomeOrOther();
(...more async code...)
}).firstRunPromise;

```

For a better developer experience `firstRunPromise` is automatically appended to your async `autorun` calls so you don't have to write them yourself. Meaning this also works:

```js

await Tracker.autorun(async () => {
await Meteor.userAsync();
(...more async code...)
});

await Tracker.autorun(async () => {
await asyncSomeOrOther();
(...more async code...)
});

```


<h2 id="tracker_dependency"><span>Tracker.Dependency</span></h2>

A Dependency represents an atomic unit of reactive data that a
Expand Down
4 changes: 4 additions & 0 deletions packages/tracker/tracker.d.ts
Expand Up @@ -16,6 +16,10 @@ export namespace Tracker {
* True during the initial run of the computation at the time `Tracker.autorun` is called, and false on subsequent reruns and at other times.
*/
firstRun: boolean;
/**
* Forces autorun blocks to be executed in synchronous-looking order by storing the value autorun promise thus making it awaitable.
*/
firstRunPromise: Promise<unknown>
/**
* Invalidates this computation so that it will be rerun.
*/
Expand Down