Skip to content

Commit

Permalink
Merge pull request #264 from idrawjs/dev-v0.4
Browse files Browse the repository at this point in the history
fix: fix addElement logic
  • Loading branch information
chenshenhai authored Jan 7, 2024
2 parents 2374058 + 916c504 commit 024f1a5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions packages/idraw/src/idraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export class iDraw {
this.#core.off(name, callback);
}

trigger<T extends keyof IDrawEvent>(name: T, e: IDrawEvent[T]) {
trigger<T extends keyof IDrawEvent>(name: T, e?: IDrawEvent[T]) {
this.#core.trigger(name, e);
}

Expand Down Expand Up @@ -212,10 +212,11 @@ export class iDraw {
): Data {
const core = this.#core;
const data: Data = core.getData() || { elements: [] };
if (!opts) {
if (!opts || !opts?.position?.length) {
data.elements.push(element);
} else if (opts?.position) {
insertElementToListByPosition(element, opts?.position, data.elements);
const position = [...opts?.position];
insertElementToListByPosition(element, position, data.elements);
}
core.setData(data);
core.refresh();
Expand Down
2 changes: 1 addition & 1 deletion packages/util/src/lib/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class EventEmitter<T extends Record<string, any>> implements UtilEventEmi
}
}

trigger<K extends keyof T>(eventKey: K, e: T[K]) {
trigger<K extends keyof T>(eventKey: K, e?: T[K]) {
const callbacks = this.#listeners.get(eventKey);
if (Array.isArray(callbacks)) {
callbacks.forEach((cb) => {
Expand Down

0 comments on commit 024f1a5

Please sign in to comment.