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

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