babel-plugin-transform-promise-to-rsvp
v2.0.4
Published
Transforms *Promise* to *rsvp*
Downloads
16
Readme
babel-plugin-transform-promise-to-rsvp
This plugin transforms Promise
to rvsp
.
Example
export default function main() {
const taskA = getResultAsync(1337);
const taskB = new Promise((resolve, reject) =>
nodeCallbackFunc(42, (err, res) => err ? reject(err) : resolve(res))
);
return Promise.all([taskA, taskB]).then(([resA, resB]) => resA + resB);
}
Gets converted to:
import {all, default as Promise} from 'rsvp';
export default function main() {
const taskA = getResultAsync(1337);
const taskB = new Promise((resolve, reject) =>
nodeCallbackFunc(42, (err, res) => err ? reject(err) : resolve(res))
);
return all([taskA, taskB]).then(([resA, resB]) => resA + resB);
}
Usage
- Install rsvp:
npm install --save rsvp
- Install the promise-to-rsvp plugin:
npm install --save-dev babel-plugin-transform-promise-to-rsvp
- Add transform-promise-to-rsvp to your .babelrc file:
{
"plugins": ["transform-promise-to-rsvp"]
}
If you'r using the transform-runtime plugin add transform-promise-to-rsvp before transform-runtime:
{
"plugins": [
"transform-promise-to-rsvp",
"transform-runtime"
]
}