Skip to content

Standardization of Callback Signatures #2957

Description

@alitaheri

We need to discuss how will we standardize the callbacks that some component take in order to behave in a controllable fashion. But since the signature of the callback function they accept is different across components, many new comers get confused.

Therefore, we have to come to a solution on this.

My proposal:

  1. Every controllable component should only be controlled via value and onChange props. No more onRequestXxx.
  2. the value must be as versatile as possible, if it make sense for it to be anything equatable with === then it should be marked as any.
  3. The value should NOT be treated as falsy EVER! Implicit coercion leads to many many bugs.
  4. The signature of the callback must follow this pattern: (e: Event, v: value, ...rest: any[]) => void
  5. If access to the event is granted, there really shouldn't be any reason to provide a reason argument to indicate what triggered the change. The event can be checked against it's type or it's properties. I think this could be more accurate. (debatable 😁 )

@oliviertassinari @newoga @mbrookes Tell me what you guys think 😁

The Roadmap:

1. Standardize The Following Components:

2. Purge State:

  • Create a stateful StateWrapper components that can be used to make components stateful, useful for forms. It must implement: getValue(), setValue(value), clearValue(), defaultValue prop, onChange prop: (event, value, ...rest) => void
  • Clear state from all components that can be stateless. As much as possible.

3. Documentation and deployment:

  • Figure out a way to make usage less pain full, something like:
import SelectField from 'material-ui/lib/SelectField'; // For the actual component
// As opposed to:
import SelectField from 'material-ui/lib/SelectField/stateful'; // For the stateful version component

This is easy to implement, but I don't know if we want this, we should discuss this too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionscope: selectChanges related to the select.umbrellaFor grouping multiple issues to provide a holistic view

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions