fix: nextId() 逻辑调整

This commit is contained in:
mario.gk 2020-08-23 11:28:46 +08:00
parent ffaa15fc6b
commit 488a5d8283
2 changed files with 15 additions and 10 deletions

View File

@ -20,14 +20,14 @@ export type GetDataType<T, NodeType> = T extends undefined
: any
: T;
export interface ComponentMap {
componentName: string;
package: string;
version?: string;
destructuring?: boolean;
exportName?: string;
subName?: string;
}
export interface ComponentMap {
componentName: string;
package: string;
version?: string;
destructuring?: boolean;
exportName?: string;
subName?: string;
}
export class DocumentModel {
/**
@ -148,7 +148,12 @@ export class DocumentModel {
* id
*/
nextId() {
return (this.id.slice(-10) + (++this.seqId).toString(36)).toLocaleLowerCase();
let id;
do {
id = 'node_' + (this.id.slice(-10) + (++this.seqId).toString(36)).toLocaleLowerCase();
} while (this.nodesMap.get(id))
return id;
}
/**

View File

@ -148,7 +148,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
constructor(readonly document: DocumentModel, nodeSchema: Schema) {
const { componentName, id, children, props, ...extras } = nodeSchema;
this.id = id || `node_${document.nextId()}`;
this.id = id || document.nextId();
this.componentName = componentName;
if (this.componentName === 'Leaf') {
this.props = new Props(this, {