Skip to content

Commit

Permalink
Update: Polyfill Proxy on Node 4
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Kennedy committed Oct 16, 2017
1 parent 9717114 commit d328cac
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 30 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ node_js:
- '8'
- '7'
- '6'
- '4'
before_script:
- npm prune
script:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('Example test suite', function () {

`anticipated-call` intercepts function calls with [Proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy), and returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). To do this, the `Proxy` and `Promise` constructors must be available as globals.

If you're running Node 8, these are included in core, so you don't have to do anything. Similarly, if you're using `babel-polyfill` or similar, this is handled for you.
The `Promise` constructor is assumed to be available, since it was implemented in Node 4. If `Proxy` is not available, it will be polyfilled.

## API

Expand Down
61 changes: 33 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"test": "jest",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
"files": ["lib"],
"files": [
"lib"
],
"author": "Ryan Kennedy <[email protected]>",
"license": "MIT",
"release": {
Expand All @@ -34,5 +36,8 @@
"eslint-config-react-app": "^2.0.1",
"jest": "^21.2.1",
"semantic-release": "^8.0.3"
},
"dependencies": {
"harmony-reflect": "^1.5.1"
}
}
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const EventEmitter = require('events');

if (typeof Proxy === 'undefined') {
require('harmony-reflect');
}

class Anticipated extends EventEmitter {
nthNextCall(n) {
let counter = 0;
Expand Down

0 comments on commit d328cac

Please sign in to comment.