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

Babel plugin #1052

Closed
alippai opened this issue Mar 19, 2018 · 6 comments
Closed

Babel plugin #1052

alippai opened this issue Mar 19, 2018 · 6 comments

Comments

@alippai
Copy link

alippai commented Mar 19, 2018

As you can't hook async+await now (like you can the Promise/statemachine transpilations) is there a babel plugin which doesn't transpile the async+await syntax, but adds the required zone.js calls at transpile time?

@JiaLiPassion
Copy link
Collaborator

@alippai , could you describe your requirement more clearly? now typescript can transpile the async/await to javascript Promise. I am not sure about the babel plugin.

@alippai
Copy link
Author

alippai commented Mar 19, 2018

I want to leave it as async+await, but append a zonejs "async_call_completed()" call after each await.

async function a() {
  await b();
}

decorated into:

async function a() {
  await b();
  zonejs.async_call_completed();
}

instead of:

function a() {
  return b().then(() => zonejs.async_call_completed());
}

@JiaLiPassion
Copy link
Collaborator

what do you mean async_call_completed()? could you check this one #795

@alippai
Copy link
Author

alippai commented Mar 19, 2018

async_call_completed() should be some callback which should be called after a change happened. I'm not familiar with zone.js task API/internals, sorry.
You monkey patch e.g. the setTimeout() now, so if the timer run, you invoke some zone.js internals resulting in angular change detection.
I'm looking for a way to transpile the:

async function a() {
  await b();
}

to trigger the Zone.js based Angular change detections, but without a complete ES8->ES5 transpilation.
Basically the same what you linked, but instead of a runtime async_hook a compile time one.

@JiaLiPassion
Copy link
Collaborator

@alippai , I see, without async_hooks, I don't think zone.js can do that, because even we can add such kind of aysnc_call_completed() with transpile, zone.js need to remember the Zone Context information when the async task was scheduled, but currently, without async_hooks, this is not possible.

@alippai
Copy link
Author

alippai commented Mar 20, 2018

I see, thank you!

@alippai alippai closed this as completed Mar 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants