react-entity - Create entities base on React propTypes

Getting started
$ npm install react-entity
Features
- This package let you create entities with schema validator like React PropTypes.
Examples
import { PropTypes } from 'react';
class MyEntity extends ReactEntity {
static SCHEMA = {
field: PropTypes.string,
otherField: {
type: PropTypes.number,
defaultValue: 10
}
}
}
Get default values
const niceInstance = new MyEntity();
console.log(niceInstance.fetch());
console.log(niceInstance.errors);
Validations
const buggedInstance = new MyEntity({ field: 10, otherField: 'value' });
console.log(buggedInstance.fetch());
console.log(buggedInstance.errors);
Validate on change value
const otherInstance = new MyEntity({ field: 'myString' });
console.log(otherInstance.errors);
console.log(otherInstance.valid);
otherInstance.field = 1;
console.log(otherInstance.errors);
console.log(otherInstance.valid);
Clean unexpected values
const anotherInstance = new MyEntity({ field: 'myString', fake: 'fake' });
console.log(anotherInstance.fetch());
See React PropTypes
Well known issues
- Automatically build instance based on data
- Create helpers for relationship
- Create validation for relationship
- Create identifier and equal comparison