Skip to content

Commit

Permalink
feat: defintion a dev modules register
Browse files Browse the repository at this point in the history
  • Loading branch information
hubert committed Dec 30, 2024
1 parent 7fc7d95 commit 820240e
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion packages/module-loader/src/register.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getCurrentInstance, inject, isVue2 } from 'vue-demi';
import { isArray, isPlainObject, isFunction, isUndef } from '@ace-util/core';
import { isArray, isPlainObject, isFunction, isUndef, warn } from '@ace-util/core';
import { getLocation, compilePathRegex } from './utils/path';
import { debug } from './env';

Expand Down Expand Up @@ -315,6 +315,30 @@ export function registerComponents<T extends Record<string, string | { src: stri
return useLoader;
}

const DEV_MODULE_KEY = 'dev-modules';
/**
* Register dev modules from localStorage
*/
export function useDevModules(...args: [Lifecycles?, ModuleLoader?] | [ModuleLoader?]) {
let loader: ModuleLoader | undefined, lifeCycles: Lifecycles | undefined;
if (args[0] && (('setOptions' in args[0]) as any)) {
loader = args[0] as ModuleLoader;
} else {
lifeCycles = args[0] as Lifecycles;
loader = args[1];
}
const devModuleStr = localStorage.getItem(DEV_MODULE_KEY);
let devModules = [];
if (devModuleStr) {
try {
devModules = JSON.parse(devModuleStr);
} catch {
warn(process.env.NODE_ENV === 'production', `{DEV_MODULE_KEY} is not a valid JSON string`);
}
}
return registerSubModules(devModules, lifeCycles)(loader);
}

/**
* Format module config from user input
* @param config user input module config
Expand Down

0 comments on commit 820240e

Please # to comment.