Open kettanaito opened 6 years ago
enhancers
option of the createField()
HOC.
export default createField({
enhancers: [enhancer1, enhancer2, ...]
})(FieldComponent);
applyEnhancer
function:
import { applyEnhancer } from 'react-advanced-form';
import enhancer1 from 'react-advanced-form/enhancers/enhancer1';
import enhancer2 from 'react-advanced-form/enhancers/enhancer2';
import { Input } from '...';
const CreditCardInput = applyEnhancer(enhancer1, enhancer2, ...)(Input);
Performed a very basic PoC to see how this would behave.
So far settled with the interceptors approach, where each essential field even could be intercepted and changed by enhancers. This means the introduction of an abstraction layer above the field updates on the form level, to prevent the event payload mutations within custom callback methods (enhancers apply transformations at the very end of the field update cycle, which is form update handlers).
I need to think more about this approach, there may be more efficient solution to this.
Considering #216 in the future scope, enhancers must be implemented in a way to work for both formful and formless fields. That means, that the interception of certain field events may be moved to the Field
level.
I am not sure how I see this change. Interception on a Field
level means alteration of the input data. I would prefer for enhancers to alter only the end-point behavior (up to Form.updateField()
), preserving the original input data.
Another solution is to handle interception point at a different place depending on the formless status of a field. This way enhacers of formful fields would intercept events on a form level, which is proper, and formless fields would have the interception logic on a Field
level, which is proper for that kind of fields.
Interception of dispatched events' data was made possible via Observable.map()
:
Observable.fromEvent(...)
.map(eventData => this.interceptEventData(eventName, eventData))
.subscribe(func);
Technically speaking, there is no interception as such, but a mapping of incoming events to the listener passed through the array of interceptors (remapers). This works great on a form-centric interception concept, but is questionable whether this is going to be a solution for formless fields.
Since field enhancers are most likely to land in 2.0
, I would consider to finish first the createField
API change suggested in #281.
This proposal is obsolete and must not be implemented.
Please use createField
API to achieve custom field behavior. Thanks.
What
I suggest to add the possibility to extend the form or field components using enhancers.
Why
There are a lot of great features planned for the next release of RAF. However, I don't want to ship even great things in a mandatory manner. The end developer may not need those features like formatting or masks, but will be forced to download them within the source files.
How
Instead, I suggest to add the middleware support. I imagine it working in two scenarios.
Create field with enhancers
Apply enhancers to the existing field
Keynotes
createField
high-order component