Skip to content

Commit 08f8378

Browse files
authored
Merge pull request dozoisch#31 from dozoisch/readme-dl-badge
Update readme, add dl badge
2 parents bf3af36 + 630e9b2 commit 08f8378

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

README.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,21 @@
11
# React Async Script Loader
22

3-
[![Build Status][travis.img]][travis.url]
4-
[![npm version][npm.img]][npm.url]
5-
[![Dependencies][deps.img]][deps.url]
6-
[![Dev Dependencies][devdeps.img]][devdeps.url]
3+
[![Build Status][travis.img]][travis.url] [![npm version][npm.img]][npm.url] [![npm downloads][npm.dl.img]][npm.dl.url] [![Dependencies][deps.img]][deps.url]
74

85
A React composition mixin for loading 3rd party scripts asynchronously. This component allows you to wrap component
96
that needs 3rd party resources, like reCAPTCHA or Google Maps, and have them load the script asynchronously.
107

11-
With React 0.13, mixins are getting deprecated in favor of composition.
12-
13-
After reading this article, [Mixins Are Dead. Long Live Composition][dan_abramov],
14-
I decided push react-script-loader a bit further and make a composition function that wraps component.
15-
16-
## Version to use
17-
18-
- __React < 15.5__: v0.8.0
19-
- __React >= 15.5__: >= v0.9.0
20-
218
## Usage
229

2310
The api is very simple `makeAsyncScriptLoader(Component, getScriptUrl, options)`. Where options can contain exposeFuncs, callbackName and globalName.
2411

25-
- Component: The component to wrap.
26-
- getScriptUrl: a string or function that returns the full URL of the script tag.
12+
- `Component`: The component to wrap.
13+
- `getScriptUrl`: a string or function that returns the full URL of the script tag.
2714
- options *(optional)*:
28-
- exposeFuncs: Array of String. It'll create a function that will call the child component with the same name. It passes arguments and return value.
29-
- callbackName: If the scripts calls a global function when loaded, provide the callback name here. It'll be autoregistered on the window.
30-
- globalName: If wanted, provide the globalName of the loaded script. It'll be injected on the component with the same name *(ex: "grecaptcha")*
31-
- removeOnUnmount: Boolean **default=false**: If set to true removes the script tag on the component unmount
15+
- `exposeFuncs`: Array of Strings. It'll create a function that will call the child component with the same name. It passes arguments and return value.
16+
- `callbackName`: If the scripts calls a global function when loaded, provide the callback name here. It'll be autoregistered on the window.
17+
- `globalName`: If wanted, provide the globalName of the loaded script. It'll be injected on the component with the same name *(ex: "grecaptcha")*
18+
- `removeOnUnmount`: Boolean **default=false**: If set to true removes the script tag on the component unmount
3219

3320
You can retrieve the child component using the function called `getComponent()`.
3421

@@ -39,7 +26,6 @@ See https://github.com/dozoisch/react-google-recaptcha
3926
```js
4027

4128
// recaptcha-wrapper.js
42-
"use strict";
4329
import React from "react";
4430

4531
import ReCAPTCHA from "./recaptcha";
@@ -54,8 +40,8 @@ export default makeAsyncScriptLoader(ReCAPTCHA, URL, {
5440
globalName: globalName,
5541
});
5642

43+
5744
// main.js
58-
"use strict";
5945
import React from "react";
6046
import ReCAPTCHAWrapper from "./recaptcha-wrapper.js"
6147

@@ -104,6 +90,20 @@ let instance = ReactTestUtils.renderIntoDocument(
10490
instance.callsACallback(function () { console.log("Called from child", this.constructor.displayName); });
10591
```
10692

93+
## Notes
94+
95+
### History
96+
97+
With React 0.13, mixins are getting deprecated in favor of composition.
98+
99+
After reading this article, [Mixins Are Dead. Long Live Composition][dan_abramov],
100+
I decided push react-script-loader a bit further and make a composition function that wraps component.
101+
102+
### Version to use
103+
104+
- __React < 15.5__: v0.8.0
105+
- __React >= 15.5__: >= v0.9.0
106+
107107
---
108108

109109
*Inspired by [react-script-loader][sl]*
@@ -114,10 +114,10 @@ instance.callsACallback(function () { console.log("Called from child", this.cons
114114
[travis.url]: https://travis-ci.org/dozoisch/react-async-script
115115
[npm.img]: https://badge.fury.io/js/react-async-script.svg
116116
[npm.url]: http://badge.fury.io/js/react-async-script
117+
[npm.dl.img]: https://img.shields.io/npm/dm/react-async-script.svg
118+
[npm.dl.url]: https://www.npmjs.com/package/react-async-script
117119
[deps.img]: https://david-dm.org/dozoisch/react-async-script.svg
118120
[deps.url]: https://david-dm.org/dozoisch/react-async-script
119-
[devdeps.img]: https://david-dm.org/dozoisch/react-async-script/dev-status.svg
120-
[devdeps.url]: https://david-dm.org/dozoisch/react-async-script#info=devDependencies
121121

122122
[dan_abramov]: https://medium.com/@dan_abramov/mixins-are-dead-long-live-higher-order-components-94a0d2f9e750
123123
[sl]: https://github.com/yariv/ReactScriptLoader

0 commit comments

Comments
 (0)