react-load-script
Advanced tools
Comparing version 0.0.3 to 0.0.4-alpha
@@ -7,10 +7,4 @@ 'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _invariant = require('invariant'); | ||
var _invariant2 = _interopRequireDefault(_invariant); | ||
var _react = require('react'); | ||
@@ -47,3 +41,3 @@ | ||
_this.scriptLoaderId = 'id' + _this.constructor.idCount++; // eslint-disable-line space-unary-ops | ||
_this.scriptLoaderId = 'id' + _this.constructor.idCount++; // eslint-disable-line space-unary-ops, no-plusplus | ||
return _this; | ||
@@ -63,7 +57,10 @@ } | ||
value: function componentDidMount() { | ||
var url = this.props.url; | ||
var _props = this.props, | ||
onError = _props.onError, | ||
onLoad = _props.onLoad, | ||
url = _props.url; | ||
if (this.constructor.loadedScripts[url]) { | ||
this.runCallback('onLoad'); | ||
onLoad(); | ||
return; | ||
@@ -73,3 +70,3 @@ } | ||
if (this.constructor.erroredScripts[url]) { | ||
this.runCallback('onError'); | ||
onError(); | ||
return; | ||
@@ -82,7 +79,7 @@ } | ||
if (this.constructor.scriptObservers[url]) { | ||
this.constructor.scriptObservers[url][this.scriptLoaderId] = this.runCallback.bind(this); | ||
this.constructor.scriptObservers[url][this.scriptLoaderId] = this.props; | ||
return; | ||
} | ||
this.constructor.scriptObservers[url] = _defineProperty({}, this.scriptLoaderId, this.runCallback.bind(this)); | ||
this.constructor.scriptObservers[url] = _defineProperty({}, this.scriptLoaderId, this.props); | ||
@@ -100,3 +97,5 @@ this.createScript(); | ||
// component from the script's observers before unmounting the component. | ||
if (observers) delete observers[this.scriptLoaderId]; | ||
if (observers) { | ||
delete observers[this.scriptLoaderId]; | ||
} | ||
} | ||
@@ -108,7 +107,9 @@ }, { | ||
var url = this.props.url; | ||
var _props2 = this.props, | ||
onCreate = _props2.onCreate, | ||
url = _props2.url; | ||
var script = document.createElement('script'); | ||
this.runCallback('onCreate', false); | ||
onCreate(); | ||
@@ -121,3 +122,5 @@ script.src = url; | ||
Object.keys(observers).forEach(function (key) { | ||
if (shouldRemoveObserver(observers[key])) delete _this2.constructor.scriptObservers[url][_this2.scriptLoaderId]; | ||
if (shouldRemoveObserver(observers[key])) { | ||
delete _this2.constructor.scriptObservers[url][_this2.scriptLoaderId]; | ||
} | ||
}); | ||
@@ -128,3 +131,3 @@ }; | ||
callObserverFuncAndRemoveObserver(function (observer) { | ||
observer('onLoad'); | ||
observer.onLoad(); | ||
return true; | ||
@@ -137,3 +140,3 @@ }); | ||
callObserverFuncAndRemoveObserver(function (observer) { | ||
observer('onError'); | ||
observer.onError(); | ||
return true; | ||
@@ -146,13 +149,2 @@ }); | ||
}, { | ||
key: 'runCallback', | ||
value: function runCallback(type) { | ||
var required = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; | ||
var callback = this.props[type]; | ||
(0, _invariant2.default)(!required || typeof callback === 'function', 'Callback ' + type + ' must be function, got "' + (typeof callback === 'undefined' ? 'undefined' : _typeof(callback)) + '" instead'); | ||
return callback && callback(); | ||
} | ||
}, { | ||
key: 'render', | ||
@@ -173,2 +165,7 @@ value: function render() { | ||
}; | ||
Script.defaultProps = { | ||
onCreate: function onCreate() {}, | ||
onError: function onError() {}, | ||
onLoad: function onLoad() {} | ||
}; | ||
Script.scriptObservers = {}; | ||
@@ -175,0 +172,0 @@ Script.loadedScripts = {}; |
{ | ||
"name": "react-load-script", | ||
"version": "0.0.3", | ||
"version": "0.0.4-alpha", | ||
"description": "react-load-script enables you to easily create components which depend on third party JS scripts", | ||
@@ -14,3 +14,6 @@ "main": "lib/index.js", | ||
"build:lib": "babel src --out-dir lib", | ||
"clean": "rimraf lib" | ||
"clean": "rimraf lib", | ||
"lint": "eslint ./src/*", | ||
"test": "jest", | ||
"prepublish": "npm run lint && npm run test && npm run build" | ||
}, | ||
@@ -21,23 +24,34 @@ "keywords": [ | ||
], | ||
"jest": { | ||
"rootDir": "src" | ||
}, | ||
"license": "MIT", | ||
"devDependencies": { | ||
"babel-cli": "^6.7.0", | ||
"babel-core": "^6.7.0", | ||
"babel-eslint": "^6.0.0", | ||
"babel-plugin-add-module-exports": "^0.1.2", | ||
"babel-plugin-transform-runtime": "^6.6.0", | ||
"babel-preset-es2015": "^6.6.0", | ||
"babel-preset-react": "^6.5.0", | ||
"babel-preset-stage-0": "^6.5.0", | ||
"eslint": "^2.9.0", | ||
"eslint-config-airbnb": "^8.0.0", | ||
"eslint-plugin-import": "^1.0.3", | ||
"eslint-plugin-jsx-a11y": "^1.0.4", | ||
"eslint-plugin-react": "^5.0.1", | ||
"rimraf": "^2.4.3" | ||
"babel-cli": "6.24.1", | ||
"babel-core": "6.24.1", | ||
"babel-eslint": "7.2.3", | ||
"babel-plugin-add-module-exports": "0.1.2", | ||
"babel-plugin-transform-runtime": "6.6.0", | ||
"babel-preset-es2015": "6.6.0", | ||
"babel-preset-react": "6.5.0", | ||
"babel-preset-stage-1": "6.24.1", | ||
"enzyme": "2.8.2", | ||
"eslint": "3.19.0", | ||
"eslint-config-airbnb": "14.1.0", | ||
"eslint-plugin-import": "2.2.0", | ||
"eslint-plugin-jsx-a11y": "4.0.0", | ||
"eslint-plugin-react": "6.10.3", | ||
"jest": "19.0.2", | ||
"prop-types": "15.5.8", | ||
"react": "15.5.4", | ||
"react-addons-test-utils": "15.5.1", | ||
"react-dom": "15.5.4", | ||
"rimraf": "2.4.3" | ||
}, | ||
"dependencies": { | ||
"prop-types": "^15.5.8", | ||
"react": ">=0.14.2" | ||
}, | ||
"peerDependencies": { | ||
"react": ">=0.14.9", | ||
"prop-types": ">=15" | ||
} | ||
} |
@@ -9,3 +9,6 @@ # react-load-script | ||
##API | ||
## Support React versions | ||
This package requires React 0.14.9 and higher. | ||
## API | ||
The package exports a single component with the following props: | ||
@@ -12,0 +15,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
150331
195
0
67
20
- Removedprop-types@^15.5.8
- Removedreact@>=0.14.2