composer.js 907 B

123456789101112131415161718192021222324252627282930313233
  1. /**
  2. * Provide a function for composing components.
  3. *
  4. * @author Naotoshi Fujita
  5. * @copyright Naotoshi Fujita. All rights reserved.
  6. */
  7. import { each } from '../utils/object';
  8. import { Slide, Fade } from '../transitions';
  9. import { FADE } from '../constants/types';
  10. /**
  11. * Compose components.
  12. *
  13. * @param {Splide} Splide - Splide instance.
  14. * @param {Object} Components - Additional components.
  15. * @param {function} Transition - Change component for transition.
  16. *
  17. * @return {Object} - An object containing all components.
  18. */
  19. export default function compose( Splide, Components, Transition ) {
  20. const components = {};
  21. each( Components, ( Component, name ) => {
  22. components[ name ] = Component( Splide, components, name.toLowerCase() );
  23. } );
  24. Transition = Transition || Splide.is( FADE ) ? Fade : Slide;
  25. components.Transition = Transition( Splide, components );
  26. return components;
  27. }