Skip to content

Commit

Permalink
[New] add sloppy import, for removing the "exact"ness on a propType…
Browse files Browse the repository at this point in the history
…s object
  • Loading branch information
ljharb committed Jun 15, 2018
1 parent cefd371 commit e394a63
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -60,13 +60,13 @@
"nyc": "^10.3.2",
"prop-types": "^15.6.1",
"react": "^0.13 || ^0.14 || ^15 || ^16.0.0-alpha.12",
"reflect.ownkeys": "^0.2.0",
"rimraf": "^2.6.2",
"safe-publish-latest": "^1.1.1",
"tape": "^4.9.1"
},
"dependencies": {
"has": "^1.0.3",
"object.assign": "^4.1.0"
"object.assign": "^4.1.0",
"reflect.ownkeys": "^0.2.0"
}
}
8 changes: 8 additions & 0 deletions src/sloppy.js
@@ -0,0 +1,8 @@
import ownKeys from 'reflect.ownkeys';
import exact from './';

const [semaphore] = ownKeys(exact({}));

export default function sloppy({ [semaphore]: _, ...propTypes }) {
return propTypes;
}
20 changes: 20 additions & 0 deletions test/sloppy.jsx
@@ -0,0 +1,20 @@
import test from 'tape';
import React from 'react';
import sloppy from '../build/sloppy';
import exact from '../';

test('sloppy', (t) => {
t.equal(typeof sloppy, 'function', 'export is a function');

class Component extends React.Component {
render() { return null; }
}
Component.propTypes = exact({});

t['throws'](() => <Component a />, EvalError, 'works with exact');

Component.propTypes = sloppy(Component.propTypes);
t.doesNotThrow(() => <Component a />, 'sloppy un-exacts it');

t.end();
});

0 comments on commit e394a63

Please sign in to comment.