Skip to content

Refactor for react 16 #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"stage": 0,
"loose": "all"
"presets": [
["es2015"],
["react"],
["stage-0"]
],
"plugins": ["transform-decorators-legacy"]
}
4 changes: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"extends": "eslint-config-airbnb",
"extends": ["eslint-config-airbnb", "prettier"],
"env": {
"browser": true,
"mocha": true,
"node": true
},
"rules": {
"prettier/prettier": ["error", { "trailingComma": "es5", "singleQuote": true }],
"react/jsx-uses-react": 2,
"react/jsx-uses-vars": 2,
"react/react-in-jsx-scope": 2,
Expand All @@ -16,6 +17,7 @@
"padded-blocks": 0
},
"plugins": [
"prettier",
"react"
]
}
34 changes: 22 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"description": "React component and decorator for prop providing and prop injection",
"main": "./lib/index.js",
"scripts": {
"build:lib": "babel src --out-dir lib",
"build:lib": "babel src --source-maps --out-dir lib",
"build:umd": "webpack src/index.js dist/react-tunnel.js --config webpack.config.development.js",
"build:umd:min": "webpack src/index.js dist/react-tunnel.min.js --config webpack.config.production.js",
"build": "npm run build:lib && npm run build:umd && npm run build:umd:min",
"clean": "rimraf lib dist coverage",
"lint": "eslint src test",
"lint": "eslint src test --fix",
"prepublish": "npm run clean && npm run build",
"test": "mocha --compilers js:babel/register --recursive",
"test": "mocha --compilers js:babel-core/register --recursive",
"test:watch": "npm test -- --watch",
"test:cov": "babel-node ./node_modules/isparta/bin/isparta cover ./node_modules/mocha/bin/_mocha -- --recursive"
},
Expand All @@ -35,21 +35,31 @@
},
"homepage": "https://github.com/gnoff/react-tunnel",
"devDependencies": {
"babel": "5.x.x",
"babel-core": "5.x.x",
"babel-eslint": "4.x.x",
"babel-loader": "5.x.x",
"eslint": "1.x.x",
"eslint-config-airbnb": "0.0.7",
"eslint-plugin-react": "3.x.x",
"expect": "1.x.x",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-eslint": "^4.1.8",
"babel-loader": "7.1.1",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"eslint": "^4.12.1",
"eslint-config-airbnb": "^16.1.0",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jsx-a11y": "^6.0.2",
"eslint-plugin-prettier": "^2.3.1",
"eslint-plugin-react": "^7.5.1",
"exenv": "1.x.x",
"expect": "1.x.x",
"isparta": "3.x.x",
"istanbul": "0.3.x",
"jsdom": "6.x.x",
"mocha": "2.x.x",
"mocha-jsdom": "1.x.x",
"react": "0.14.x",
"prettier": "^1.8.2",
"react": "16.2.0",
"react-dom": "16.2.0",
"rimraf": "2.x.x",
"webpack": "1.x.x",
"webpack-dev-server": "1.x.x"
Expand Down
2 changes: 1 addition & 1 deletion src/components/createAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export default function createAll(React) {
const inject = createInject(React);

return { Provider, inject };
}
}
4 changes: 2 additions & 2 deletions src/utils/hasEmptyIntersection.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ export default function hasEmptyIntersection(objA, objB) {
return false;
}

const objCombined = {...objA, ...objB};
const objCombined = { ...objA, ...objB };
const keysCombined = Object.keys(objCombined);

if (keysA.length + keysB.length === keysCombined.length) {
return true;
}

return false;
}
}
19 changes: 11 additions & 8 deletions src/utils/isPlainObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* copied from https://github.com/gaearon/react-redux/blob/master/src/utils/isPlainObject.js authored by @gaearon
*/

const fnToString = (fn) => Function.prototype.toString.call(fn);
const fnToString = fn => Function.prototype.toString.call(fn);

/**
* @param {any} obj The object to inspect.
Expand All @@ -13,17 +13,20 @@ export default function isPlainObject(obj) {
return false;
}

const proto = typeof obj.constructor === 'function' ?
Object.getPrototypeOf(obj) :
Object.prototype;
const proto =
typeof obj.constructor === 'function'
? Object.getPrototypeOf(obj)
: Object.prototype;

if (proto === null) {
return true;
}

const constructor = proto.constructor;

return typeof constructor === 'function'
&& constructor instanceof constructor
&& fnToString(constructor) === fnToString(Object);
}
return (
typeof constructor === 'function' &&
constructor instanceof constructor &&
fnToString(constructor) === fnToString(Object)
);
}
3 changes: 1 addition & 2 deletions src/utils/shallowEqual.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ export default function shallowEqual(objA, objB) {
// Test for A's keys different from B.
const hasOwn = Object.prototype.hasOwnProperty;
for (let i = 0; i < keysA.length; i++) {
if (!hasOwn.call(objB, keysA[i]) ||
objA[keysA[i]] !== objB[keysA[i]]) {
if (!hasOwn.call(objB, keysA[i]) || objA[keysA[i]] !== objB[keysA[i]]) {
return false;
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/utils/sharedKeys.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export default function sharedKeys(objA, objB) {

if (!objA || !objB) {
return [];
}
Expand All @@ -15,10 +14,10 @@ export default function sharedKeys(objA, objB) {
return keysA;
}

let sharedKeys = [];
const sharedKeys = [];

const hasOwn = Object.prototype.hasOwnProperty;
for (let keyA of keysA) {
for (const keyA of keysA) {
if (hasOwn.call(objB, keyA)) {
sharedKeys.push(keyA);
}
Expand Down
5 changes: 3 additions & 2 deletions test/components/Provider.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import expect from 'expect';
import jsdomReact from './jsdomReact';
import React, { PropTypes, Component } from 'react/addons';
import React, { Component } from 'react';
import { Provider } from '../../src/index';
import PropTypes from 'prop-types';

const { TestUtils } = React.addons;
import TestUtils from 'react-dom/test-utils';

describe('React', () => {
describe('Provider', () => {
Expand Down
5 changes: 3 additions & 2 deletions test/components/inject.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import expect from 'expect';
import jsdomReact from './jsdomReact';
import React, { PropTypes, Component, Children} from 'react/addons';
import React, { Component, Children} from 'react';
import PropTypes from 'prop-types';
import { inject } from '../../src/index';

const { TestUtils } = React.addons;
import TestUtils from 'react-dom/test-utils';

describe('React', () => {
describe('inject', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/components/jsdomReact.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import jsdom from 'mocha-jsdom';
export default function jsdomReact() {
jsdom();
ExecutionEnvironment.canUseDOM = true;
}
}
56 changes: 11 additions & 45 deletions test/utils/hasEmptyIntersection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,81 +5,47 @@ describe('Utils', () => {
describe('hasEmptyIntersection', () => {
it('should return true if one or the other object is empty, null, or undefined', () => {
expect(
hasEmptyIntersection(
{},
{ a: 1, b: undefined, c: {}, d: 'd' }
)
hasEmptyIntersection({}, { a: 1, b: undefined, c: {}, d: 'd' })
).toBe(true);

expect(
hasEmptyIntersection(
{ a: 1, b: undefined, c: {}, d: 'd' },
{}
)
hasEmptyIntersection({ a: 1, b: undefined, c: {}, d: 'd' }, {})
).toBe(true);

expect(
hasEmptyIntersection(
null,
{ a: 1, b: undefined, c: {}, d: 'd' }
)
hasEmptyIntersection(null, { a: 1, b: undefined, c: {}, d: 'd' })
).toBe(true);

expect(
hasEmptyIntersection(
{ a: 1, b: undefined, c: {}, d: 'd' },
null
)
hasEmptyIntersection({ a: 1, b: undefined, c: {}, d: 'd' }, null)
).toBe(true);

expect(
hasEmptyIntersection(
undefined,
{ a: 1, b: undefined, c: {}, d: 'd' }
)
hasEmptyIntersection(undefined, { a: 1, b: undefined, c: {}, d: 'd' })
).toBe(true);

expect(
hasEmptyIntersection(
{ a: 1, b: undefined, c: {}, d: 'd' },
undefined
)
hasEmptyIntersection({ a: 1, b: undefined, c: {}, d: 'd' }, undefined)
).toBe(true);
});

it('should return false if the arguments are the same non-empty object', () => {
const emptyObj = {};
const fullObj = { a: 1 };
expect(
hasEmptyIntersection(
emptyObj,
emptyObj
)
).toBe(true);
expect(hasEmptyIntersection(emptyObj, emptyObj)).toBe(true);

expect(
hasEmptyIntersection(
fullObj,
fullObj
)
).toBe(false);
expect(hasEmptyIntersection(fullObj, fullObj)).toBe(false);
});

it('should return false if objects are different but have the same keys', () => {
expect(
hasEmptyIntersection(
{ a: 1, b: 2, c: 3 },
{ a: 'a', b: 'b', c: 'c' }
)
hasEmptyIntersection({ a: 1, b: 2, c: 3 }, { a: 'a', b: 'b', c: 'c' })
).toBe(false);
});

it('should return false if objects share a single key', () => {
expect(
hasEmptyIntersection(
{ x: 1, y: 2, z: 3 },
{ a: 1, b: 2, c: 3 }
)
hasEmptyIntersection({ x: 1, y: 2, z: 3 }, { a: 1, b: 2, c: 3 })
).toBe(true);

expect(
Expand All @@ -90,4 +56,4 @@ describe('Utils', () => {
).toBe(false);
});
});
});
});
4 changes: 2 additions & 2 deletions test/utils/isPlainObject.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('Utils', () => {
expect(isPlainObject([1, 2, 3])).toBe(false);
expect(isPlainObject(null)).toBe(false);
expect(isPlainObject()).toBe(false);
expect(isPlainObject({ 'x': 1, 'y': 2 })).toBe(true);
expect(isPlainObject({ x: 1, y: 2 })).toBe(true);
});
});
});
});
39 changes: 10 additions & 29 deletions test/utils/shallowEqual.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,25 @@ describe('Utils', () => {
describe('shallowEqual', () => {
it('should return true if arguments fields are equal', () => {
expect(
shallowEqual(
{ a: 1, b: 2, c: undefined },
{ a: 1, b: 2, c: undefined }
)
shallowEqual({ a: 1, b: 2, c: undefined }, { a: 1, b: 2, c: undefined })
).toBe(true);

expect(
shallowEqual(
{ a: 1, b: 2, c: 3 },
{ a: 1, b: 2, c: 3 }
)
).toBe(true);
expect(shallowEqual({ a: 1, b: 2, c: 3 }, { a: 1, b: 2, c: 3 })).toBe(
true
);

const o = {};
expect(
shallowEqual(
{ a: 1, b: 2, c: o },
{ a: 1, b: 2, c: o }
)
).toBe(true);
expect(shallowEqual({ a: 1, b: 2, c: o }, { a: 1, b: 2, c: o })).toBe(
true
);
});

it('should return false if first argument has too many keys', () => {
expect(
shallowEqual(
{ a: 1, b: 2, c: 3 },
{ a: 1, b: 2 }
)
).toBe(false);
expect(shallowEqual({ a: 1, b: 2, c: 3 }, { a: 1, b: 2 })).toBe(false);
});

it('should return false if second argument has too many keys', () => {
expect(
shallowEqual(
{ a: 1, b: 2 },
{ a: 1, b: 2, c: 3 }
)
).toBe(false);
expect(shallowEqual({ a: 1, b: 2 }, { a: 1, b: 2, c: 3 })).toBe(false);
});

it('should return false if arguments have different keys', () => {
Expand All @@ -58,4 +39,4 @@ describe('Utils', () => {
).toBe(false);
});
});
});
});
Loading