mirror of
https://github.com/konvajs/konva.git
synced 2026-01-08 18:54:40 +08:00
warning on dublicate ids
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { Util, Collection } from './Util';
|
||||
import { Factory, Validators } from './Factory';
|
||||
import { Node } from './Node';
|
||||
import { getGlobalKonva, ids, names } from './Global';
|
||||
import { Node, ids } from './Node';
|
||||
import { getGlobalKonva, names } from './Global';
|
||||
|
||||
import { GetSet, Vector2d, IRect } from './types';
|
||||
import { GetSet, IRect } from './types';
|
||||
|
||||
/**
|
||||
* Container constructor. Containers are used to contain nodes or other containers
|
||||
|
||||
@@ -15,8 +15,6 @@ var PI_OVER_180 = Math.PI / 180;
|
||||
*/
|
||||
export const version = '@@version';
|
||||
|
||||
// private
|
||||
export const ids = {};
|
||||
export const names = {};
|
||||
export const shapes = {};
|
||||
|
||||
@@ -66,32 +64,6 @@ export const isDragReady = function() {
|
||||
}
|
||||
return false;
|
||||
};
|
||||
export const _addId = function(node: any, id) {
|
||||
if (!id) {
|
||||
return;
|
||||
}
|
||||
// do we need this warning?
|
||||
// if (ids[id]) {
|
||||
// console.warn(
|
||||
// 'Duplicate id "' +
|
||||
// id +
|
||||
// '". Please don not use same id several times. It may break find() method look up.'
|
||||
// );
|
||||
// }
|
||||
ids[id] = node;
|
||||
};
|
||||
|
||||
export const _removeId = function(id: string, node: any) {
|
||||
// node has no id
|
||||
if (!id) {
|
||||
return;
|
||||
}
|
||||
// another node is registered (possible for duplicate ids)
|
||||
if (ids[id] !== node) {
|
||||
return;
|
||||
}
|
||||
delete ids[id];
|
||||
};
|
||||
|
||||
export const _addName = function(node: any, name) {
|
||||
if (name) {
|
||||
|
||||
37
src/Node.ts
37
src/Node.ts
@@ -1,16 +1,39 @@
|
||||
import { Util, Collection, Transform, RectConf, Point } from './Util';
|
||||
import { Factory, Validators } from './Factory';
|
||||
import { SceneCanvas, HitCanvas } from './Canvas';
|
||||
import {
|
||||
_removeId,
|
||||
_removeName,
|
||||
_addId,
|
||||
_addName,
|
||||
getGlobalKonva
|
||||
} from './Global';
|
||||
import { _removeName, _addName, getGlobalKonva } from './Global';
|
||||
import { Container } from './Container';
|
||||
import { GetSet, Vector2d } from './types';
|
||||
|
||||
export const ids = {};
|
||||
|
||||
const ID_WARNING = `Duplicate id "{id}".
|
||||
Please do not use same id several times, it will break find() method look up.
|
||||
If you have duplicates it is better to use "name" property instead.
|
||||
`;
|
||||
|
||||
const _addId = function(node: Node, id) {
|
||||
if (!id) {
|
||||
return;
|
||||
}
|
||||
if (ids[id]) {
|
||||
Util.warn(ID_WARNING.replace('{id}', id));
|
||||
}
|
||||
ids[id] = node;
|
||||
};
|
||||
|
||||
export const _removeId = function(id: string, node: any) {
|
||||
// node has no id
|
||||
if (!id) {
|
||||
return;
|
||||
}
|
||||
// another node is registered (possible for duplicate ids)
|
||||
if (ids[id] !== node) {
|
||||
return;
|
||||
}
|
||||
delete ids[id];
|
||||
};
|
||||
|
||||
export type Filter = (this: Node, imageData: ImageData) => void;
|
||||
|
||||
type globalCompositeOperationType =
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export * from './Global';
|
||||
|
||||
export { Collection, Util } from './Util';
|
||||
export { Node } from './Node';
|
||||
export { Node, ids } from './Node';
|
||||
export { Container } from './Container';
|
||||
|
||||
export { Stage, stages } from './Stage';
|
||||
|
||||
Reference in New Issue
Block a user