material-components / material-components-web

Modular and customizable Material Design UI components for the web
https://material.io/develop/web
MIT License
17.15k stars 2.15k forks source link

[Feature Request] Use classes instead of a bag of functions for Foundation Adapters #3614

Open dfreedm opened 6 years ago

dfreedm commented 6 years ago

As currently specified, Foundation Adapters must be a bag of bound functions.

This uses far more memory than necessary, as the functions must be created for each component instance, but all instances share essentially the same behavior.

Instead, an Adapter class could be provided for each component that could be extended and overridden as necessary, so that all component instances share the same Adapter class.

kfranqueiro commented 6 years ago

It is worth noting that in many cases, the current approach is utilized to bind the context of adapter methods to the component instance. So while all instances share the same behavior, they do not share the same this.

e.g. https://github.com/material-components/material-components-web/blob/v0.39.3/packages/mdc-switch/index.js#L105