fix: make insertAfter & insertBefore work

This commit is contained in:
LeoYuan 袁力皓 2022-03-11 11:24:45 +08:00
parent d5c3ca1068
commit 70fd3720d0
2 changed files with 34 additions and 2 deletions

View File

@ -232,19 +232,39 @@ export class EngineConfig {
this.config = config || {};
}
/**
* key
* @param key
* @returns
*/
has(key: string): boolean {
return this.config[key] !== undefined;
}
/**
* key
* @param key
* @param defaultValue
* @returns
*/
get(key: string, defaultValue?: any): any {
return lodashGet(this.config, key, defaultValue);
}
/**
* key
* @param key
* @param value
*/
set(key: string, value: any) {
this.config[key] = value;
this.notifyGot(key);
}
/**
* set
* @param config
*/
setConfig(config: { [key: string]: any }) {
if (config) {
Object.keys(config).forEach((key) => {
@ -281,6 +301,12 @@ export class EngineConfig {
}
}
/**
* key
* Promise fullfill
* @param key
* @returns
*/
onceGot(key: string): Promise<any> {
const val = this.config[key];
if (val !== undefined) {
@ -291,6 +317,12 @@ export class EngineConfig {
});
}
/**
* key
* @param key
* @param fn
* @returns
*/
onGot(key: string, fn: (data: any) => void): () => void {
const val = this.config?.[key];
if (val !== undefined) {

View File

@ -348,7 +348,7 @@ export default class Node {
* @param useMutator
*/
insertBefore(node: Node, ref?: Node | undefined, useMutator?: boolean) {
this[nodeSymbol].insertBefore(node[nodeSymbol], ref?.[nodeSymbol], useMutator);
this[nodeSymbol].insertBefore(node[nodeSymbol] || node, ref?.[nodeSymbol], useMutator);
}
/**
@ -358,7 +358,7 @@ export default class Node {
* @param useMutator
*/
insertAfter(node: Node, ref?: Node | undefined, useMutator?: boolean) {
this[nodeSymbol].insertAfter(node[nodeSymbol], ref?.[nodeSymbol], useMutator);
this[nodeSymbol].insertAfter(node[nodeSymbol] || node, ref?.[nodeSymbol], useMutator);
}
/**