Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 3 additions & 30 deletions build/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument

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 _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; }; /* eslint react/prop-types: 0 */


var _react = require('react');

var _react2 = _interopRequireDefault(_react);
Expand All @@ -23,7 +20,8 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /* eslint react/prop-types: 0 */


var getTypeOf = function getTypeOf(something) {
var getType = {};
Expand All @@ -41,11 +39,6 @@ var isString = function isString(stringToCheck) {
return type && type === '[object String]';
};

// https://github.com/then/is-promise/blob/master/index.js
var isPromise = function isPromise(promise) {
return !!promise && ((typeof promise === 'undefined' ? 'undefined' : _typeof(promise)) === 'object' || typeof promise === 'function') && typeof promise.then === 'function';
};

var getDisplayName = function getDisplayName(c) {
return c.displayName || c.name || 'Component';
};
Expand All @@ -59,7 +52,6 @@ exports.default = function () {
var loadFunctionName = isString(load) ? load : 'load';
var isPrintArray = Array.isArray(print);
var isPrintFunction = isFunction(print);
var isPrintPromise = isPromise(print);
var isLoadFunction = isFunction(load);

var isLoaded = function isLoaded(props, state, context) {
Expand Down Expand Up @@ -87,10 +79,6 @@ exports.default = function () {
return !!print(props, context);
}

if (isPrintPromise) {
return state.promiseLoaded;
}

// Anything else
return !!print;
};
Expand All @@ -115,10 +103,7 @@ exports.default = function () {
}

return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref2 = _class.__proto__ || Object.getPrototypeOf(_class)).call.apply(_ref2, [this].concat(args))), _this), _this.state = {
props: {},
promiseLoaded: false
}, _this.promiseResolved = function () {
_this.setState({ promiseLoaded: true });
props: {}
}, _this.omitLoadInProps = function (props) {
var isLoadAFunction = isFunction(props[loadFunctionName]);

Expand All @@ -139,23 +124,11 @@ exports.default = function () {
_createClass(_class, [{
key: 'componentWillMount',
value: function componentWillMount() {
var _this2 = this;

// Load from hoc argument
if (isLoadFunction) {
load(this.props, this.context);
}

if (isPrintPromise) {
print.then(function (value) {
_this2.promiseResolved();
return value;
}).catch(function (error) {
_this2.promiseResolved();
throw error;
});
}

// Load from props
if (this.omitLoadInProps(this.props)) {
this.props[loadFunctionName](this.props, this.context);
Expand Down
9 changes: 0 additions & 9 deletions misc/rebuild_refs.sh

This file was deleted.

3 changes: 3 additions & 0 deletions misc/requestAnimationFrame.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
global.requestAnimationFrame = (cb) => {
setTimeout(cb, 0)
}
21 changes: 4 additions & 17 deletions misc/testSetup.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
import { jsdom } from 'jsdom'
import chai from 'chai'
import spies from 'chai-spies'
import './requestAnimationFrame'
import Enzyme from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'

global.document = jsdom('<!doctype html><html><body></body></html>')
global.window = document.defaultView
global.navigator = global.window.navigator

/** Configuring chai. */
chai.should()
chai.config.includeStack = true
chai.config.truncateThreshold = 0
chai.use(spies)

// Make console.error a real failure
console.error = (message) => { // eslint-disable-line no-console
throw new Error(message)
}
Enzyme.configure({ adapter: new Adapter() })
43 changes: 25 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
{
"name": "hoc-react-loader",
"version": "6.1.0",
"version": "6.1.1",
"description": "Higher order component to call a load function from props at mount.",
"main": "build/index.js",
"peerDependencies": {
"prop-types": "^15.5.8",
"react": "^15.3.0",
"tinycolor2": "^1.4.1"
"prop-types": "^15.x",
"react": "^15.x || ^16.x",
"tinycolor2": "^1.x"
},
"scripts": {
"lint": "find src -iname \"*.jsx\" -exec eslint {} +; find src -iname \"*.js\" -exec eslint {} +;",
"build": "cross-env BABEL_ENV=cjs babel --ignore \"*.spec.js\" ./src/ --out-dir build",
"test": "jest --collectCoverageFrom=src/**/*.js --collectCoverageFrom=src/**/*.jsx",
"coveralls": "jest --coverage && cat ./coverage/lcov.info | coveralls",
"ci": "npm-run-all --parallel lint coveralls"

},
"devDependencies": {
"babel-cli": "^6.24.0",
"babel-core": "^6.24.0",
"babel-eslint": "^7.2.1",
"babel-jest": "^21.2.0",
"babel-preset-es2015": "^6.24.0",
"babel-preset-es2017": "^6.22.0",
"babel-preset-react": "^6.23.0",
Expand All @@ -21,32 +30,25 @@
"chai-spies": "^0.7.1",
"coveralls": "^2.12.0",
"cross-env": "^3.2.4",
"enzyme": "^2.8.0",
"enzyme": "^3.1.0",
"enzyme-adapter-react-16": "^1.0.2",
"eslint": "^3.18.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": "^21.2.1",
"jsdom": "^9.12.0",
"lodash": "^4.17.4",
"mocha": "^3.2.0",
"npm-run-all": "^4.1.1",
"nyc": "^10.2.0",
"prop-types": "^15.5.8",
"react": "^15.3.0",
"react-addons-test-utils": "^15.4.2",
"react-dom": "^15.3.0",
"react-test-renderer": "^15.5.4",
"prop-types": "^15.6.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not the same version in the peerDependency : 15.5.8

"react": "^16.0.0",
"react-dom": "^16.0.0",
"react-test-renderer": "^16.0.0",
"tinycolor2": "^1.4.1"
},
"scripts": {
"lint": "find src -iname \"*.jsx\" -exec eslint {} +; find src -iname \"*.js\" -exec eslint {} +;",
"build": "cross-env BABEL_ENV=cjs babel --ignore \"*.spec.js\" ./src/ --out-dir build",
"test": "mocha --recursive --compilers js:babel-register --require ./misc/testSetup.js \"src/**/*.spec.js\" ",
"coverage": "nyc --extension .jsx npm test",
"coveralls": "nyc --extension .jsx npm test && nyc report --reporter=text-lcov | coveralls",
"ci": "npm-run-all --parallel lint coveralls"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Zenika/hoc-react-loader.git"
Expand Down Expand Up @@ -92,5 +94,10 @@
"import/no-unresolved": 0,
"react/forbid-prop-types": 0
}
},
"jest": {
"setupFiles": [
"./misc/testSetup.js"
]
}
}
14 changes: 5 additions & 9 deletions src/TailSpin/TailSpin.spec.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
/* eslint-env mocha */
/* eslint-env jest */

/* eslint-disable
no-unused-expressions,
react/jsx-filename-extension,
import/no-extraneous-dependencies
react/jsx-filename-extension
*/

import React from 'react'
import { mount } from 'enzyme'
import blanket from 'blanket' // eslint-disable-line
import TailSpin from './TailSpin'
import TailSpin from './index'

const testColor = (component, color) => {
component.find('circle').props().fill.should.be.deep.equals(color)
expect(component.find('circle').props().fill).toEqual(color)
}

describe('TailSpin', () => {
Expand Down Expand Up @@ -60,5 +58,3 @@ describe('TailSpin', () => {
)
})
})

/* eslint-enable no-unused-expressions */
51 changes: 51 additions & 0 deletions src/__snapshots__/index.spec.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`hoc-react-loader print parameter should not print Component -loaded props- 1`] = `"<div class=\\"tailspin\\">TailSpin</div>"`;

exports[`hoc-react-loader print parameter should not print Component -loaded props- 2`] = `"<div class=\\"tailspin\\">TailSpin</div>"`;

exports[`hoc-react-loader print parameter should not print Component -print as a value- 1`] = `"<div class=\\"tailspin\\">TailSpin</div>"`;

exports[`hoc-react-loader print parameter should not print Component -print as function- 1`] = `"<div class=\\"tailspin\\">TailSpin</div>"`;

exports[`hoc-react-loader print parameter should not print Component -print as function- 2`] = `
Array [
Array [
Object {
"some": "props",
},
Object {},
],
]
`;

exports[`hoc-react-loader print parameter should print Component -empty parameters- 1`] = `"<div class=\\"component\\">Component</div>"`;

exports[`hoc-react-loader print parameter should print Component -loaded props- 1`] = `"<div class=\\"component\\">Component</div>"`;

exports[`hoc-react-loader print parameter should print Component -loaded props- 2`] = `"<div class=\\"component\\">Component</div>"`;

exports[`hoc-react-loader print parameter should print Component -print as a value- 1`] = `"<div class=\\"component\\">Component</div>"`;

exports[`hoc-react-loader print parameter should print Component -print as an array- 1`] = `"<div class=\\"tailspin\\">TailSpin</div>"`;

exports[`hoc-react-loader print parameter should print Component -print as an array- 2`] = `"<div class=\\"tailspin\\">TailSpin</div>"`;

exports[`hoc-react-loader print parameter should print Component -print as an array- 3`] = `"<div class=\\"tailspin\\">TailSpin</div>"`;

exports[`hoc-react-loader print parameter should print Component -print as an array- 4`] = `"<div class=\\"component\\">Component</div>"`;

exports[`hoc-react-loader print parameter should print Component -print as function- 1`] = `"<div class=\\"component\\">Component</div>"`;

exports[`hoc-react-loader print parameter should print Component -print as function- 2`] = `
Array [
Array [
Object {
"some": "props",
},
Object {},
],
]
`;

exports[`hoc-react-loader print parameter should print Component -undefined parameters- 1`] = `"<div class=\\"component\\">Component</div>"`;
25 changes: 0 additions & 25 deletions src/core.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ const isString = (stringToCheck) => {
return type && type === '[object String]'
}

// https://github.com/then/is-promise/blob/master/index.js
const isPromise = (promise) => {
return !!promise && (typeof promise === 'object' || typeof promise === 'function') && typeof promise.then === 'function'
}

const getDisplayName = c => c.displayName || c.name || 'Component'

export default (
Expand All @@ -34,7 +29,6 @@ export default (
const loadFunctionName = isString(load) ? load : 'load'
const isPrintArray = Array.isArray(print)
const isPrintFunction = isFunction(print)
const isPrintPromise = isPromise(print)
const isLoadFunction = isFunction(load)

const isLoaded = (props, state, context) => {
Expand All @@ -59,10 +53,6 @@ export default (
return !!print(props, context)
}

if (isPrintPromise) {
return state.promiseLoaded
}

// Anything else
return !!print
}
Expand All @@ -75,11 +65,8 @@ export default (

state = {
props: {},
promiseLoaded: false,
}

promiseResolved = () => { this.setState({ promiseLoaded: true }) }

omitLoadInProps = (props) => {
const isLoadAFunction = isFunction(props[loadFunctionName])

Expand All @@ -103,18 +90,6 @@ export default (
load(this.props, this.context)
}

if (isPrintPromise) {
print
.then((value) => {
this.promiseResolved()
return value
})
.catch((error) => {
this.promiseResolved()
throw error
})
}

// Load from props
if (this.omitLoadInProps(this.props)) {
this.props[loadFunctionName](this.props, this.context)
Expand Down
Loading