feat: optimize framework

Signed-off-by: MiaoWoo <admin@yumc.pw>
clean
MiaoWoo 2020-05-12 14:22:31 +08:00
parent d3d7a9cdbf
commit aab94fe5ea
3 changed files with 19 additions and 15 deletions

View File

@ -43,14 +43,14 @@ class MiaoScriptCore {
console.i18n("ms.core.plugin.initialize")
this.pluginManager.scan(this.pluginFolder)
this.pluginManager.build()
this.pluginManager.load()
this.pluginManager.enable()
this.pluginManager.load(this.pluginManager.getPlugins())
this.pluginManager.enable(this.pluginManager.getPlugins())
console.i18n("ms.core.plugin.completed", { time: (new Date().getTime() - loadPluginStartTime) / 1000 })
}
disable() {
console.i18n("ms.core.engine.disable")
this.pluginManager.disable()
this.pluginManager.disable(this.pluginManager.getPlugins())
this.taskManager.disable()
//@ts-ignore
require.disable()

View File

@ -87,6 +87,7 @@ export class XMLHttpRequest {
private _status: number = 0;
private _statusText: string = null;
private _response: any;
private _responseText: any;
private _responseURL: string;
private _responseHeaders: HttpHeader = {};
@ -115,10 +116,10 @@ export class XMLHttpRequest {
return this._statusText;
}
get response() {
return this._response ? JSON.parse(this._response) : this._response;
return this._response || this.get();
}
get responseText() {
return this._response;
return this._responseText;
}
get responseXML() {
return this._response;
@ -181,14 +182,17 @@ export class XMLHttpRequest {
return future;
}
get() {
switch (this._responseType) {
case "json":
return this.response;
case "text":
return this.responseText;
default:
throw Error(`Unsupport ResponseType: ${this._responseType} !`)
if (this._response === undefined) {
switch (this._responseType) {
case "json":
return this._response = JSON.parse(this._responseText);
case "text":
return this._response = this._responseText;
default:
throw Error(`Unsupport ResponseType: ${this._responseType} !`)
}
}
return this._response;
}
abort() {
this._connection.disconnect();
@ -211,11 +215,11 @@ export class XMLHttpRequest {
this._status = this._connection.getResponseCode();
this._statusText = this._connection.getResponseMessage();
if (this._status >= 0 && this._status < 300) {
this._response = this.readOutput(this._connection.getInputStream());
this._responseText = this.readOutput(this._connection.getInputStream());
} else if (this._status >= 300 && this._status < 400) {
this._responseURL = this.getResponseHeader('Location');
} else {
this._response = this.readOutput(this._connection.getErrorStream());
this._responseText = this.readOutput(this._connection.getErrorStream());
}
this.setResponseHeaders(this._connection.getHeaderFields());
this.onloadend && this.onloadend();

View File

@ -123,7 +123,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
}
private checkAndGet(name: string | interfaces.Plugin | undefined | any): Map<string, interfaces.Plugin> | interfaces.Plugin[] {
if (name == undefined) { return this.pluginInstanceMap }
if (name == this.pluginInstanceMap) { return this.pluginInstanceMap }
if (typeof name == 'string' && this.pluginInstanceMap.has(name)) { return [this.pluginInstanceMap.get(name)] }
if (name instanceof interfaces.Plugin) { return [name as interfaces.Plugin] }
if (name.description || name.description.name) { return [name as interfaces.Plugin] }