You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.1 KiB

4 years ago
  1. import * as riot from 'riot';
  2. import TinyFade from './src/tiny-fade.riot';
  3. riot.install((component) => {
  4. const {
  5. onBeforeMount,
  6. onMounted
  7. } = component
  8. // patch the onBeforeMount to create slots in runtime
  9. component.onBeforeMount = (...args) => {
  10. const html = component.root.innerHTML
  11. if (html) {
  12. // empty the component html
  13. component.root.innerHTML = ''
  14. // define slot-html to runtime
  15. Object.defineProperty(component, 'slot-html', {
  16. value: html,
  17. enumerable: false,
  18. writable: false,
  19. configurable: true,
  20. })
  21. }
  22. // call the original onBeforeMount
  23. onBeforeMount.apply(component, ...args)
  24. }
  25. component.onMounted = (...args) => {
  26. component.$('slot-html').outerHTML = component['slot-html']
  27. // call the original onMounted
  28. onMounted.apply(component, ...args)
  29. }
  30. return component
  31. })
  32. riot.register('tiny-fade', TinyFade);
  33. riot.mount('tiny-fade');