MCPcopy Create free account
hub / github.com/DTStack/molecule / InstanceService

Class InstanceService

src/services/instanceService.tsx:43–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41}
42
43export default class InstanceService
44 extends GlobalEvent
45 implements IInstanceServiceProps
46{
47 private _config = {
48 extensions: defaultExtensions.concat(),
49 defaultLocale: 'en',
50 };
51
52 private rendered = false;
53
54 constructor(config: IConfigProps) {
55 super();
56 if (config.defaultLocale) {
57 this._config.defaultLocale = config.defaultLocale;
58 }
59
60 if (Array.isArray(config.extensions)) {
61 this._config.extensions.push(...config.extensions);
62 }
63 }
64
65 private initialLocaleService = (languagesExts: IExtension[]) => {
66 const locales = languagesExts.reduce((pre, cur) => {
67 const languages = cur.contributes?.languages || [];
68 return pre.concat(languages);
69 }, [] as ILocale[]);
70
71 molecule.i18n.initialize(
72 locales,
73 localStorage.getItem(STORE_KEY) || this._config.defaultLocale
74 );
75 };
76
77 public getConfig: () => IConfigProps = () => {
78 return Object.assign({}, this._config);
79 };
80
81 public render = (workbench: ReactElement) => {
82 if (!this.rendered) {
83 this.emit(InstanceHookKind.beforeInit);
84
85 // get all locales including builtin and custom locales
86 const [languages, others] = molecule.extension.splitLanguagesExts(
87 this._config.extensions
88 );
89 this.initialLocaleService(languages);
90
91 const controllers = [
92 ActivityBarController,
93 AuxiliaryController,
94 EditorController,
95 /**
96 * Explorer should called before EditorTreeController,
97 * @refer https://github.com/DTStack/molecule/issues/829
98 */
99 ExplorerController,
100 EditorTreeController,

Callers

nothing calls this directly

Calls 9

getItemMethod · 0.80
emitMethod · 0.80
subscribeMethod · 0.80
initializeMethod · 0.65
splitLanguagesExtsMethod · 0.65
onWorkbenchDidMountMethod · 0.65
initWorkspaceMethod · 0.65
loadMethod · 0.65
initViewMethod · 0.45

Tested by

no test coverage detected