index.js 1009 B

1234567891011121314151617181920212223242526
  1. import { getTarget, getDevtoolsGlobalHook, isProxyAvailable } from './env.js';
  2. import { HOOK_SETUP } from './const.js';
  3. import { ApiProxy } from './proxy.js';
  4. export * from './api/index.js';
  5. export * from './plugin.js';
  6. export * from './time.js';
  7. export function setupDevtoolsPlugin(pluginDescriptor, setupFn) {
  8. const descriptor = pluginDescriptor;
  9. const target = getTarget();
  10. const hook = getDevtoolsGlobalHook();
  11. const enableProxy = isProxyAvailable && descriptor.enableEarlyProxy;
  12. if (hook && (target.__VUE_DEVTOOLS_PLUGIN_API_AVAILABLE__ || !enableProxy)) {
  13. hook.emit(HOOK_SETUP, pluginDescriptor, setupFn);
  14. }
  15. else {
  16. const proxy = enableProxy ? new ApiProxy(descriptor, hook) : null;
  17. const list = target.__VUE_DEVTOOLS_PLUGINS__ = target.__VUE_DEVTOOLS_PLUGINS__ || [];
  18. list.push({
  19. pluginDescriptor: descriptor,
  20. setupFn,
  21. proxy,
  22. });
  23. if (proxy)
  24. setupFn(proxy.proxiedTarget);
  25. }
  26. }