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.

1234567891011121314151617181920212223242526272829303132
  1. /**
  2. * @Author: Caven
  3. * @Date: 2020-05-09 23:01:21
  4. */
  5. /**
  6. * Using other custom plug-ins in DC
  7. * @param DC
  8. * @returns this
  9. */
  10. export function initUse(DC) {
  11. DC.use = function(plugin, lib) {
  12. const installedPlugins =
  13. this._installedPlugins || (this._installedPlugins = {})
  14. if (this._installedPlugins[plugin.name]) {
  15. return this
  16. }
  17. // additional parameters
  18. const args = []
  19. if (lib) {
  20. args.push(lib)
  21. }
  22. args.unshift(this)
  23. if (typeof plugin.install === 'function') {
  24. plugin.install.apply(plugin, args)
  25. } else if (typeof plugin === 'function') {
  26. plugin.apply(null, args)
  27. }
  28. installedPlugins[plugin.name] = plugin
  29. return this
  30. }
  31. }