Skip to content

Commit be21b74

Browse files
committed
【update】fix 循环引用; review by luox
1 parent 2a000cd commit be21b74

File tree

5 files changed

+62
-42
lines changed

5 files changed

+62
-42
lines changed

src/common/commontypes/BaseTypes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
22
* This program are made available under the terms of the Apache License, Version 2.0
33
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
4-
import {Util} from './Util';
4+
import { CircularUtil } from './CircularUtil';
55

66
/**
77
* @function inherit
@@ -21,7 +21,7 @@ export var inheritExt = function (C, P) {
2121
if (typeof o === "function") {
2222
o = o.prototype;
2323
}
24-
Util.extend(C.prototype, o);
24+
CircularUtil.extend(C.prototype, o);
2525
}
2626
};
2727

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const CircularUtil = {
2+
lastSeqID: 0,
3+
createUniqueID: function (prefix) {
4+
if (prefix == null) {
5+
prefix = 'id_';
6+
}
7+
CircularUtil.lastSeqID += 1;
8+
return prefix + CircularUtil.lastSeqID;
9+
},
10+
extend: function (destination, source) {
11+
destination = destination || {};
12+
if (source) {
13+
for (var property in source) {
14+
var value = source[property];
15+
if (value !== undefined) {
16+
destination[property] = value;
17+
}
18+
}
19+
20+
/**
21+
* IE doesn't include the toString property when iterating over an object's
22+
* properties with the for(property in object) syntax. Explicitly check if
23+
* the source has its own toString property.
24+
*/
25+
26+
/*
27+
* FF/Windows < 2.0.0.13 reports "Illegal operation on WrappedNative
28+
* prototype object" when calling hawOwnProperty if the source object
29+
* is an instance of window.Event.
30+
*/
31+
32+
var sourceIsEvt = typeof window.Event === 'function' && source instanceof window.Event;
33+
34+
if (!sourceIsEvt && source.hasOwnProperty && source.hasOwnProperty('toString')) {
35+
destination.toString = source.toString;
36+
}
37+
}
38+
return destination;
39+
}
40+
};
41+
42+
export { CircularUtil };

src/common/commontypes/Geometry.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
44
// import {WKT} from '../format/WKT';
55
// import {Vector} from './Vector';
6-
import {Util} from './Util';
6+
import { CircularUtil } from './CircularUtil';
77

88
/**
99
* @class Geometry
@@ -22,7 +22,7 @@ export class Geometry {
2222
* @description 几何对象的唯一标识符。
2323
*
2424
*/
25-
this.id = Util.createUniqueID(this.CLASS_NAME + "_");
25+
this.id = CircularUtil.createUniqueID(this.CLASS_NAME + "_");
2626

2727
/**
2828
* @member {Geometry} Geometry.prototype.parent

src/common/commontypes/Util.js

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { StringExt } from './BaseTypes';
55
import { Geometry } from './Geometry';
66
import URI from 'urijs';
7+
import { CircularUtil } from './CircularUtil';
78

89
/**
910
* @description 浏览器名称,依赖于 userAgent 属性,BROWSER_NAME 可以是空,或者以下浏览器:<br>
@@ -168,36 +169,7 @@ const Util = {
168169
* @returns {Object} 目标对象。
169170
*/
170171

171-
extend: function (destination, source) {
172-
destination = destination || {};
173-
if (source) {
174-
for (var property in source) {
175-
var value = source[property];
176-
if (value !== undefined) {
177-
destination[property] = value;
178-
}
179-
}
180-
181-
/**
182-
* IE doesn't include the toString property when iterating over an object's
183-
* properties with the for(property in object) syntax. Explicitly check if
184-
* the source has its own toString property.
185-
*/
186-
187-
/*
188-
* FF/Windows < 2.0.0.13 reports "Illegal operation on WrappedNative
189-
* prototype object" when calling hawOwnProperty if the source object
190-
* is an instance of window.Event.
191-
*/
192-
193-
var sourceIsEvt = typeof window.Event === 'function' && source instanceof window.Event;
194-
195-
if (!sourceIsEvt && source.hasOwnProperty && source.hasOwnProperty('toString')) {
196-
destination.toString = source.toString;
197-
}
198-
}
199-
return destination;
200-
},
172+
extend: CircularUtil.extend,
201173
/**
202174
* @memberOf CommonUtil
203175
* @description 对象拷贝。
@@ -583,21 +555,15 @@ const Util = {
583555
* @type {number}
584556
* @default 0
585557
*/
586-
lastSeqID: 0,
558+
lastSeqID: CircularUtil.lastSeqID,
587559

588560
/**
589561
* @memberOf CommonUtil
590562
* @description 创建唯一 ID 值。
591563
* @param {string} [prefix] - 前缀。
592564
* @returns {string} 唯一的 ID 值。
593565
*/
594-
createUniqueID: function (prefix) {
595-
if (prefix == null) {
596-
prefix = 'id_';
597-
}
598-
Util.lastSeqID += 1;
599-
return prefix + Util.lastSeqID;
600-
},
566+
createUniqueID: CircularUtil.createUniqueID,
601567

602568
/**
603569
* @memberOf CommonUtil

test/common/commontypes/UtilSpec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,4 +386,16 @@ describe('Util', () => {
386386
expect(result.textHeight).toEqual(18);
387387
});
388388

389+
it('createUniqueID', () => {
390+
let id = Util.createUniqueID();
391+
expect(id).toBe('id_0');
392+
expect(Util.lastSeqID).toBe(0);
393+
id = Util.createUniqueID('custom_');
394+
expect(id).toBe('custom_1');
395+
expect(Util.lastSeqID).toBe(1);
396+
id = Util.createUniqueID();
397+
expect(id).toBe('id_2');
398+
expect(Util.lastSeqID).toBe(2);
399+
})
400+
389401
});

0 commit comments

Comments
 (0)