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.

27 lines
1021 B

2 weeks ago
  1. import { getDevtoolsGlobalHook, getTarget, 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. }
  27. }