Skip to content

Commit

Permalink
feat(xod-client): util to check React props with sanctuary def
Browse files Browse the repository at this point in the history
without `env`(see sanctuary-js/sanctuary-def#123), but good enough for now.
  • Loading branch information
evgenykochetkov committed Mar 31, 2017
1 parent e4635e9 commit 58ee35e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/xod-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"redux-thunk": "^2.1.0",
"redux-undo": "^0.6.1",
"reselect": "^2.5.1",
"sanctuary-def": "^0.9.0",
"xod-arduino": "^0.0.1",
"xod-func-tools": "^0.0.1",
"xod-project": "^0.0.1",
Expand Down
3 changes: 3 additions & 0 deletions packages/xod-client/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import * as EditorConstants from './editor/constants';
import * as UtilsConstants from './utils/constants';
import * as BrowserUtils from './utils/browser';
import * as MenuUtils from './utils/menu';
import sanctuaryPropType from './utils/sanctuaryPropType';

import App from './core/containers/App';
import Root from './core/containers/Root';
Expand Down Expand Up @@ -40,6 +41,7 @@ export { getUpload } from './processes/selectors';

export * from './utils/browser';
export * from './utils/constants';
export { default as sanctuaryPropType } from './utils/sanctuaryPropType';

export { default as PopupShowCode } from './utils/components/PopupShowCode';
export { default as PopupAlert } from './utils/components/PopupAlert';
Expand Down Expand Up @@ -71,6 +73,7 @@ export default Object.assign({
DevTools,
Toolbar,
menu: MenuUtils,
sanctuaryPropType,
},
UtilsSelectors,
EditorSelectors,
Expand Down
11 changes: 11 additions & 0 deletions packages/xod-client/src/utils/sanctuaryPropType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import $ from 'sanctuary-def';

// only returning if the validation fails is an accepted pattern
// eslint-disable-next-line consistent-return
export default Type => (props, propName, componentName) => {
const env = []; // TODO

if (!$.test(env, Type, props[propName])) {
return new Error(`Invalid prop '${propName}' supplied to '${componentName}'`);
}
};

0 comments on commit 58ee35e

Please sign in to comment.