Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Add a nativescript zone implementation #440

Merged
merged 2 commits into from
Sep 30, 2016

Conversation

hdeshev
Copy link
Contributor

@hdeshev hdeshev commented Sep 14, 2016

The nativescript-angular mobile renderer was using the zone-node.js bundle until 0.6.18+ added patching for the timers module and fetch promise-likes. Those are incompatible with NativeScript and cause runtime errors. The best solution to support zone.js in NativeScript in a way that minimizes future breakage seems to involve creating a separate bundle.

I based this bundle on the node one, just removing the unsupported patches. I also added a rudimentary test task that runs under node (to avoid spinning up device emulators and complicate build infrastructure).

nativescript-angular vendors the zone-nativescript.js bundle that this PR adds, but it would be great if we get rid of that in the future.

This PR takes care of #437 and the fetch() change is somewhat related to #439.

Avoid patching Promise twice by checking if the promise-like
returned by fetch() is already an instance of ZoneAwarePromise.
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@hdeshev
Copy link
Contributor Author

hdeshev commented Sep 14, 2016

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

1 similar comment
@googlebot
Copy link

CLAs look good, thanks!

@@ -0,0 +1,842 @@
var Zone$1 = (function (global) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please Remove the changes to the dist folder. We update the dist folder on releases only.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -169,3 +174,31 @@ gulp.task('test/node', ['compile'], function(cb) {
jrunner.addSpecFiles(specFiles);
jrunner.execute();
});

gulp.task('test/nativescript', ['compile'], function(cb) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also update the package.json file so that native scripts can be run using npm run test-nativescript command.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -1148,7 +1148,7 @@ const Zone: ZoneType = (function(global: any) {
const fetchPromise = global['fetch']();
// ignore output to prevent error;
fetchPromise.then(() => null, () => null);
if (fetchPromise.constructor != NativePromise) {
if (fetchPromise.constructor != NativePromise && fetchPromise.constructor != ZoneAwarePromise) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you break this change into a separate commit. I don't think it has anything to do with NativeScript

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already done. The PR contains both commits.


// List all tests here:
import './common_tests';
import './nativescript_tests';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nativescript_tests.ts seems to be an empty file. Was that intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it would look consistent with the node_tests.ts setup, but I can delete it. Your call.

Based on the zone-node entrypoint with the timers module patching
removed. Also add rudimentary support for running NativeScript
tests under node.js (to avoid setting up device emulators).
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants