Skip to content
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

Add value pipes #2

Open
evanrs opened this issue Feb 8, 2016 · 2 comments
Open

Add value pipes #2

evanrs opened this issue Feb 8, 2016 · 2 comments

Comments

@evanrs
Copy link
Owner

evanrs commented Feb 8, 2016

The primary use case of redux-namespace is transient data in forms. Validation of those values could done by defining a pipeline on that value or namespace.

@evanrs
Copy link
Owner Author

evanrs commented Feb 8, 2016

A primitive version could be a simple as:

function touched(value, key) {
  return { touched: true }
}

function isNumber(value, key, meta) {
  return {
    isNumber: meta.touched ? /\d+/.test(value) : null
  }
}

let result = pipe('someValue', touched, isNumber)
<input
  className={pipe.touched ? pipe.isNumber ? "good" : "bad" : ""}
  value={select('someValue')}
  onChange={flow(property('e.value.assign'), assign('someValue'))}/>

But there's no advantage here, as pipe reduces a set of object properties, which can already be done without great effort.

@evanrs
Copy link
Owner Author

evanrs commented Feb 8, 2016

Touched is not specific to forms, it would be useful to the purpose of the library #3

An alternative api could provide methods to extend the namespace and how values are set.

import { connect, parameter, meta, pipe } form "redux-namespace";

@connect(
  'someForm',
  meta('someValue', 'isValid', isEmail)
  // or perhaps
  meta('someValue', { isValid: isEmail } ),
  // or perhaps
  pipe('validateEmail', isEmail)
)
class SomeForm extends Component {
  render() {
    let { select } = this.props;
    select('someValue|validateEmail');
    select('someValue@isValid')
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant