Javey/Intact

support property validate and correct

Javey opened this issue · 2 comments

Javey commented

Support validate and correct property like bellow:

class A extends Intact {
    static propTypes = {
        show: Boolean,
        name: {
            type: Number,
            fix: (value) => {
                return Number(value);
            }
        }
}
Javey commented

The fix method is complex. Because it has changed the original property, when the component has received a invalid value again, it may lead to infinite loop. On the other hand, we maybe not only change one property but also set some other states.

Let the $receive event trigger on init is good a choice.

Javey commented

Support validate enumerated type like bellow:

static propTypes = {
    type: ['default', 'primary', 'danger']
}