Skip to content
This repository has been archived by the owner on Oct 9, 2020. It is now read-only.

Support for Bluebird coroutines #4

Closed
guybedford opened this issue Jan 7, 2016 · 7 comments
Closed

Support for Bluebird coroutines #4

guybedford opened this issue Jan 7, 2016 · 7 comments

Comments

@guybedford
Copy link
Member

If users want to use Bluebird promises for performance, we should provide an easy option to use this transformer without having to do more than setting the option and installing bluebird.

@kirly-af
Copy link

kirly-af commented May 3, 2016

Anything new concerning this issue ?

@guybedford
Copy link
Member Author

I'm not sure if output to Bluebird coroutines is still provided in Babel 6 actually? Do you know? If it is, we can certainly add an option here.

Otherwise it may be worth trying to install a third-party Babel plugin to try this out.

@guybedford
Copy link
Member Author

Ok it is still supported via the plugin at http://babeljs.io/docs/plugins/transform-async-to-module-method/.

It would be possible to integrate this manually by installing it and configuring the plugin, but we could integrate this as an option as well potentially.

@kirly-af
Copy link

kirly-af commented May 28, 2016

Here is what I did:

jspm install npm:babel-plugin-transform-async-to-module-method
jspm install npm:bluebird

And below is a part of jspm.config.js file:

SystemJS.config({
  transpiler: "plugin-babel",
  packages: {
    "mypackage": {
      "format": "esm",
      "main": "main.js",
      "meta": {
        "*.js": {
          "loader": "plugin-babel",
          "babelOptions": {
            "plugins": [
              ["transform-async-to-module-method", {
                "module": "bluebird",
                "method": "coroutine"
              }]
            ]
          }
        }
      }
    }
  }
});

However, Bluebird library does not seem to be loaded

typeof Promise.setScheduler // undefined

Furthermore, my async functions are still transpiled with async-to-regenerator plugin.

Source:

let foo = async () => {
  let ret = await bar()
}

Transpiled:

foo = function () {
        var ref = _asyncToGenerator(_regeneratorRuntime.mark(function _callee() {
// ...

This happens even when I do not specify any options to the plugin (ie. when I do not try to use bluebird coroutines).

      "meta": {
        "*.js": {
          "loader": "plugin-babel",
          "babelOptions": {
            "plugins": [
              ["transform-async-to-module-method"]
            ]
          }
        }
      }

Being able to set this behavior by passing a simple option sounds good to me. I guess most Angular (< 2) developers who start working with ES6+ will need to use Bluebird coroutines to work with async/await.

@guybedford
Copy link
Member Author

Are you sure the configuration is applying? Because the plugin name should be babel-plugin-transform-async-to-module-method I think?

@kirly-af
Copy link

kirly-af commented May 29, 2016

Well, from the plugin documentation that you can find here or here, the usage in .babelrc is the following:

// without options
{
  "plugins": ["transform-async-to-module-method"]
}

// with options
{
  "plugins": [
    ["transform-async-to-module-method", {
      "module": "bluebird",
      "method": "coroutine"
    }]
  ]
}

I tried to replace it with babel-plugin-transform-async-to-module-method and it did not help (same output). I am a bit confused actually. What name should I use ? The one of babel docs, the package name, or the name specified in the map section of the jspm.config.js file ?

This is not clearly explained in JSPM docs:

plugin-babel README:

babelOptions: {
  plugins: [
    [ "react-transform", {
      "transforms": [{"transform": "react-transform-jspm-hmr"}]
    }]
  ]
}

jspm beta docs:

"babelOptions": {
  "plugins": ["babel-plugin-transform-react-jsx"]
}

Btw, would it help if I provide my full jspm.config.js ?

@guybedford
Copy link
Member Author

I've updated the options example at https://github.com/systemjs/plugin-babel#custom-presets-and-transforms to show using bluebird coroutines.

In terms of loading bluebird, it's probably best to have a script tag in the head, but you could also import it via System.import. Then to use the same version of bluebird in SystemJS you could try something like System.set('bluebird', System.newModule({ default: window.bluebird })).

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