Skip to content
This repository was archived by the owner on Nov 18, 2021. It is now read-only.

Commit 10e1f23

Browse files
committed
添加说明
1 parent 97d87f7 commit 10e1f23

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

README.md

+21-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88

99
A really simple way to call the original chrome javascript API and return a Promise.
1010

11+
## Install
12+
13+
```
14+
npm i -S chrome-call
15+
```
16+
1117
## Usage
1218

1319
When you do:
@@ -24,17 +30,30 @@ var promise = new Promise(function(resolve,reject) {
2430
});
2531
```
2632

27-
Then with "chrome call":
33+
It's equal to:
2834

2935
```js
3036
var promise = chromeCall('storage.local.get','key');
3137
```
3238

3339
That's really simple, right?
3440

41+
### Multiple arguments in callback
42+
43+
Most of chrome API only have one argument in callback, but someone not, such as [chrome.hid.receive](https://developer.chrome.com/apps/hid#method-receive). In this situation, the value of promise will be an (real) Array:
44+
45+
```js
46+
chromeCall('hid.receive',connectionId)
47+
.then(function(args){
48+
Array.isArray(args); // true
49+
var reportId = args[0];
50+
var data = args[1];
51+
});
52+
```
53+
3554
### Scope
3655

37-
The default function `chromeCall` search function on `window.chrome`, but you can use different scope:
56+
The global `chromeCall` search function on `window.chrome`, but you can use different scope:
3857

3958
```js
4059
var local = chromeCall.scope('storage.local'); // or chromeCall.scope(chrome.storage.local)

test/test.js

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ describe( 'chromeCall' , function () {
8585
} );
8686
chromeCall( 'storage.local.remove' )
8787
.then( function ( value ) {
88+
expect( Array.isArray( value ) ).toBe( true );
8889
expect( value ).toEqual( [ 'x' , 'y' , 'z' ] );
8990
done();
9091
} , function () {

0 commit comments

Comments
 (0)