From 51fd97ec7c6311d0ea311ea116ea1e19b4edd45c Mon Sep 17 00:00:00 2001 From: JUDIT GRESKOVITS Date: Fri, 6 Jan 2017 15:17:08 +0000 Subject: [PATCH] Update redux form proxy and Input to include Proxy functionality in Input component --- .../form/redux-form/client/form/form-two.js | 9 +----- spikes/form/redux-form/client/form/form.js | 8 +---- spikes/form/redux-form/client/form/input.js | 3 +- spikes/form/redux-form/client/form/proxy.js | 19 ------------ .../client/form/redux-form-proxy.js | 30 +++++++++++++++++++ 5 files changed, 34 insertions(+), 35 deletions(-) delete mode 100644 spikes/form/redux-form/client/form/proxy.js create mode 100644 spikes/form/redux-form/client/form/redux-form-proxy.js diff --git a/spikes/form/redux-form/client/form/form-two.js b/spikes/form/redux-form/client/form/form-two.js index 8a02e06f..1ef3fb03 100644 --- a/spikes/form/redux-form/client/form/form-two.js +++ b/spikes/form/redux-form/client/form/form-two.js @@ -2,17 +2,10 @@ const React = require('react'); const ReactRouter = require('react-router'); const ReduxForm = require('redux-form'); const Styled = require('styled-components'); -// const Input = require('./input'); -// const InputRfProps = require('./inputRfProps'); +const Input = require('./input'); const validate = require('./validate'); const Form = require('./shared').form; -const proxy = require('./proxy'); - -const { - Input -} = proxy; - const { browserHistory } = ReactRouter; diff --git a/spikes/form/redux-form/client/form/form.js b/spikes/form/redux-form/client/form/form.js index 3064c45b..c285c42c 100644 --- a/spikes/form/redux-form/client/form/form.js +++ b/spikes/form/redux-form/client/form/form.js @@ -1,17 +1,11 @@ const React = require('react'); const ReduxForm = require('redux-form'); const Styled = require('styled-components'); -// const Input = require('./input'); +const Input = require('./input'); const InputRfProps = require('./inputRfProps'); const validate = require('./validate'); const Form = require('./shared').form; -const proxy = require('./proxy'); - -const { - Input -} = proxy; - const { Field, reduxForm diff --git a/spikes/form/redux-form/client/form/input.js b/spikes/form/redux-form/client/form/input.js index c4089b5c..6e49224c 100644 --- a/spikes/form/redux-form/client/form/input.js +++ b/spikes/form/redux-form/client/form/input.js @@ -1,5 +1,6 @@ const React = require('react'); const Styled = require('styled-components'); +const Proxy = require('./redux-form-proxy'); const { default: styled @@ -130,4 +131,4 @@ Input.propTypes = { value: React.PropTypes.string }; -module.exports = Input; +module.exports = Proxy(Input); diff --git a/spikes/form/redux-form/client/form/proxy.js b/spikes/form/redux-form/client/form/proxy.js deleted file mode 100644 index 7ab46b27..00000000 --- a/spikes/form/redux-form/client/form/proxy.js +++ /dev/null @@ -1,19 +0,0 @@ -const transformPropsWith = require('transform-props-with'); -const Input = require('./input'); - -const { - default: tx -} = transformPropsWith; - -const flattenProps = props => { - const { input, meta, ...rest } = props; - return { - ...input, - ...meta, - ...rest - }; -} - -module.exports = { - Input: tx(flattenProps)(Input) -}; diff --git a/spikes/form/redux-form/client/form/redux-form-proxy.js b/spikes/form/redux-form/client/form/redux-form-proxy.js new file mode 100644 index 00000000..39ba7ddd --- /dev/null +++ b/spikes/form/redux-form/client/form/redux-form-proxy.js @@ -0,0 +1,30 @@ +const React = require('react'); +const transformPropsWith = require('transform-props-with'); + +const { + default: tx +} = transformPropsWith; + +const Proxy = tx(props => { + const { input, meta, ...rest } = props; + return { + ...input, + ...meta, + ...rest + }; +}); + +const isReduxForm = (props) => + props.hasOwnProperty('input') || props.hasOwnProperty('meta'); + +module.exports = (Component) => { + const ProxiedComponent = Proxy(Component); + + return (props) => { + return isReduxForm(props) ? ( + + ) : ( + + ) + } +};