warning on dublicate ids

This commit is contained in:
Anton Lavrenov
2019-01-24 22:52:16 -05:00
parent 645c344d32
commit 11d805795a
8 changed files with 67 additions and 78 deletions

View File

@@ -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

View File

@@ -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) {

View File

@@ -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 =

View File

@@ -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';