index.ts 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // 加载第三方库
  2. export const loadLib = (() => {
  3. const cache: Record<string, Promise<void>> = {};
  4. const load = (
  5. lib: string,
  6. success: () => void,
  7. err: () => void,
  8. maxReq = 0
  9. ) => {
  10. const el = document.createElement("script");
  11. el.src = lib;
  12. document.body.appendChild(el);
  13. el.onload = success;
  14. el.onerror = () => {
  15. if (maxReq > 0) {
  16. load(lib, success, err, --maxReq);
  17. } else {
  18. err();
  19. }
  20. };
  21. };
  22. return (lib: string) => {
  23. if (!cache[lib]) {
  24. cache[lib] = new Promise((resolve, reject) => {
  25. load(lib, resolve, reject, 3);
  26. });
  27. }
  28. return cache[lib];
  29. };
  30. })();
  31. export const togetherCallback = (cbs: (() => void)[]) => () => together(cbs)
  32. export const together = (cbs: (() => void)[]) => {
  33. cbs.forEach(cb => cb())
  34. }
  35. export * from './store-help'
  36. export * from "./stack";
  37. export * from "./loading";
  38. export * from "./route";
  39. export * from "./asyncBus";
  40. export * from './mount'
  41. export * from './watch'
  42. export * from './diff'