#12 fix addObserver函数异常错误
This commit is contained in:
@@ -214,7 +214,9 @@ Array.prototype.groupBy = function (keySelector) {
|
|||||||
var keys_1 = [];
|
var keys_1 = [];
|
||||||
return array.reduce(function (groups, element, index) {
|
return array.reduce(function (groups, element, index) {
|
||||||
var key = JSON.stringify(keySelector.call(arguments[1], element, index, array));
|
var key = JSON.stringify(keySelector.call(arguments[1], element, index, array));
|
||||||
var index2 = keys_1.findIndex(function (x) { return x === key; });
|
var index2 = keys_1.findIndex(function (x) {
|
||||||
|
return x === key;
|
||||||
|
});
|
||||||
if (index2 < 0) {
|
if (index2 < 0) {
|
||||||
index2 = keys_1.push(key) - 1;
|
index2 = keys_1.push(key) - 1;
|
||||||
}
|
}
|
||||||
@@ -230,7 +232,9 @@ Array.prototype.groupBy = function (keySelector) {
|
|||||||
var keys = [];
|
var keys = [];
|
||||||
var _loop_1 = function (i, len) {
|
var _loop_1 = function (i, len) {
|
||||||
var key = JSON.stringify(keySelector.call(arguments_1[1], array[i], i, array));
|
var key = JSON.stringify(keySelector.call(arguments_1[1], array[i], i, array));
|
||||||
var index = keys.findIndex(function (x) { return x === key; });
|
var index = keys.findIndex(function (x) {
|
||||||
|
return x === key;
|
||||||
|
});
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
index = keys.push(key) - 1;
|
index = keys.push(key) - 1;
|
||||||
}
|
}
|
||||||
@@ -7056,7 +7060,7 @@ var es;
|
|||||||
list = [];
|
list = [];
|
||||||
this._messageTable.set(eventType, list);
|
this._messageTable.set(eventType, list);
|
||||||
}
|
}
|
||||||
if (list.contains(handler))
|
if (list.findIndex(function (funcPack) { return funcPack.func == handler; }) != -1)
|
||||||
console.warn("您试图添加相同的观察者两次");
|
console.warn("您试图添加相同的观察者两次");
|
||||||
list.push(new FuncPack(handler, context));
|
list.push(new FuncPack(handler, context));
|
||||||
};
|
};
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -214,7 +214,9 @@ Array.prototype.groupBy = function (keySelector) {
|
|||||||
var keys_1 = [];
|
var keys_1 = [];
|
||||||
return array.reduce(function (groups, element, index) {
|
return array.reduce(function (groups, element, index) {
|
||||||
var key = JSON.stringify(keySelector.call(arguments[1], element, index, array));
|
var key = JSON.stringify(keySelector.call(arguments[1], element, index, array));
|
||||||
var index2 = keys_1.findIndex(function (x) { return x === key; });
|
var index2 = keys_1.findIndex(function (x) {
|
||||||
|
return x === key;
|
||||||
|
});
|
||||||
if (index2 < 0) {
|
if (index2 < 0) {
|
||||||
index2 = keys_1.push(key) - 1;
|
index2 = keys_1.push(key) - 1;
|
||||||
}
|
}
|
||||||
@@ -230,7 +232,9 @@ Array.prototype.groupBy = function (keySelector) {
|
|||||||
var keys = [];
|
var keys = [];
|
||||||
var _loop_1 = function (i, len) {
|
var _loop_1 = function (i, len) {
|
||||||
var key = JSON.stringify(keySelector.call(arguments_1[1], array[i], i, array));
|
var key = JSON.stringify(keySelector.call(arguments_1[1], array[i], i, array));
|
||||||
var index = keys.findIndex(function (x) { return x === key; });
|
var index = keys.findIndex(function (x) {
|
||||||
|
return x === key;
|
||||||
|
});
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
index = keys.push(key) - 1;
|
index = keys.push(key) - 1;
|
||||||
}
|
}
|
||||||
@@ -7056,7 +7060,7 @@ var es;
|
|||||||
list = [];
|
list = [];
|
||||||
this._messageTable.set(eventType, list);
|
this._messageTable.set(eventType, list);
|
||||||
}
|
}
|
||||||
if (list.contains(handler))
|
if (list.findIndex(function (funcPack) { return funcPack.func == handler; }) != -1)
|
||||||
console.warn("您试图添加相同的观察者两次");
|
console.warn("您试图添加相同的观察者两次");
|
||||||
list.push(new FuncPack(handler, context));
|
list.push(new FuncPack(handler, context));
|
||||||
};
|
};
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+54
-43
@@ -4,84 +4,100 @@ declare interface Array<T> {
|
|||||||
* @param predicate 表达式
|
* @param predicate 表达式
|
||||||
*/
|
*/
|
||||||
findIndex(predicate: Function): number;
|
findIndex(predicate: Function): number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否存在满足表达式的数组元素
|
* 是否存在满足表达式的数组元素
|
||||||
* @param predicate 表达式
|
* @param predicate 表达式
|
||||||
*/
|
*/
|
||||||
any(predicate: Function): boolean;
|
any(predicate: Function): boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取满足表达式的第一个或默认数组元素
|
* 获取满足表达式的第一个或默认数组元素
|
||||||
* @param predicate 表达式
|
* @param predicate 表达式
|
||||||
*/
|
*/
|
||||||
firstOrDefault(predicate: Function): T;
|
firstOrDefault(predicate: Function): T;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取满足表达式的第一个数组元素
|
* 获取满足表达式的第一个数组元素
|
||||||
* @param predicate 表达式
|
* @param predicate 表达式
|
||||||
*/
|
*/
|
||||||
find(predicate: Function): T;
|
find(predicate: Function): T;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 筛选满足表达式的数组元素
|
* 筛选满足表达式的数组元素
|
||||||
* @param predicate 表达式
|
* @param predicate 表达式
|
||||||
*/
|
*/
|
||||||
where(predicate: Function): Array<T>;
|
where(predicate: Function): Array<T>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取满足表达式的数组元素的计数
|
* 获取满足表达式的数组元素的计数
|
||||||
* @param predicate 表达式
|
* @param predicate 表达式
|
||||||
*/
|
*/
|
||||||
count(predicate: Function): number;
|
count(predicate: Function): number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取满足表达式的数组元素的数组
|
* 获取满足表达式的数组元素的数组
|
||||||
* @param predicate 表达式
|
* @param predicate 表达式
|
||||||
*/
|
*/
|
||||||
findAll(predicate: Function): Array<T>;
|
findAll(predicate: Function): Array<T>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否有获取满足表达式的数组元素
|
* 是否有获取满足表达式的数组元素
|
||||||
* @param value 值
|
* @param value 值
|
||||||
*/
|
*/
|
||||||
contains(value): boolean;
|
contains(value): boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 移除满足表达式的数组元素
|
* 移除满足表达式的数组元素
|
||||||
* @param predicate 表达式
|
* @param predicate 表达式
|
||||||
*/
|
*/
|
||||||
removeAll(predicate: Function): void;
|
removeAll(predicate: Function): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 移除数组元素
|
* 移除数组元素
|
||||||
* @param element 数组元素
|
* @param element 数组元素
|
||||||
*/
|
*/
|
||||||
remove(element: T): boolean;
|
remove(element: T): boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 移除特定索引数组元素
|
* 移除特定索引数组元素
|
||||||
* @param index 索引
|
* @param index 索引
|
||||||
*/
|
*/
|
||||||
removeAt(index): void;
|
removeAt(index): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 移除范围数组元素
|
* 移除范围数组元素
|
||||||
* @param index 开始索引
|
* @param index 开始索引
|
||||||
* @param count 删除的个数
|
* @param count 删除的个数
|
||||||
*/
|
*/
|
||||||
removeRange(index, count): void;
|
removeRange(index, count): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取通过选择器转换的数组
|
* 获取通过选择器转换的数组
|
||||||
* @param selector 选择器
|
* @param selector 选择器
|
||||||
*/
|
*/
|
||||||
select(selector: Function): Array<T>;
|
select(selector: Function): Array<T>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 排序(升序)
|
* 排序(升序)
|
||||||
* @param keySelector key选择器
|
* @param keySelector key选择器
|
||||||
* @param comparer 比较器
|
* @param comparer 比较器
|
||||||
*/
|
*/
|
||||||
orderBy(keySelector: Function, comparer: Function): Array<T>;
|
orderBy(keySelector: Function, comparer: Function): Array<T>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 排序(降序)
|
* 排序(降序)
|
||||||
* @param keySelector key选择器
|
* @param keySelector key选择器
|
||||||
* @param comparer 比较器
|
* @param comparer 比较器
|
||||||
*/
|
*/
|
||||||
orderByDescending(keySelector: Function, comparer: Function): Array<T>;
|
orderByDescending(keySelector: Function, comparer: Function): Array<T>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分组
|
* 分组
|
||||||
* @param keySelector key选择器
|
* @param keySelector key选择器
|
||||||
*/
|
*/
|
||||||
groupBy(keySelector: Function): Array<T>;
|
groupBy(keySelector: Function): Array<T>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 求和
|
* 求和
|
||||||
* @param selector 选择器
|
* @param selector 选择器
|
||||||
@@ -101,7 +117,7 @@ Array.prototype.findIndex = function (predicate) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return findIndex(this, predicate);
|
return findIndex(this, predicate);
|
||||||
}
|
};
|
||||||
|
|
||||||
Array.prototype.any = function (predicate) {
|
Array.prototype.any = function (predicate) {
|
||||||
function any(array, predicate) {
|
function any(array, predicate) {
|
||||||
@@ -109,7 +125,7 @@ Array.prototype.any = function (predicate) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return any(this, predicate);
|
return any(this, predicate);
|
||||||
}
|
};
|
||||||
|
|
||||||
Array.prototype.firstOrDefault = function (predicate) {
|
Array.prototype.firstOrDefault = function (predicate) {
|
||||||
function firstOrDefault(array, predicate) {
|
function firstOrDefault(array, predicate) {
|
||||||
@@ -118,7 +134,7 @@ Array.prototype.firstOrDefault = function (predicate) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return firstOrDefault(this, predicate);
|
return firstOrDefault(this, predicate);
|
||||||
}
|
};
|
||||||
|
|
||||||
Array.prototype.find = function (predicate) {
|
Array.prototype.find = function (predicate) {
|
||||||
function find(array, predicate) {
|
function find(array, predicate) {
|
||||||
@@ -126,7 +142,7 @@ Array.prototype.find = function (predicate) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return find(this, predicate);
|
return find(this, predicate);
|
||||||
}
|
};
|
||||||
|
|
||||||
Array.prototype.where = function (predicate) {
|
Array.prototype.where = function (predicate) {
|
||||||
function where(array, predicate) {
|
function where(array, predicate) {
|
||||||
@@ -138,8 +154,7 @@ Array.prototype.where = function (predicate) {
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}, []);
|
}, []);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
let ret = [];
|
let ret = [];
|
||||||
for (let i = 0, len = array.length; i < len; i++) {
|
for (let i = 0, len = array.length; i < len; i++) {
|
||||||
let element = array[i];
|
let element = array[i];
|
||||||
@@ -153,7 +168,7 @@ Array.prototype.where = function (predicate) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return where(this, predicate);
|
return where(this, predicate);
|
||||||
}
|
};
|
||||||
|
|
||||||
Array.prototype.count = function (predicate) {
|
Array.prototype.count = function (predicate) {
|
||||||
function count(array, predicate) {
|
function count(array, predicate) {
|
||||||
@@ -161,7 +176,7 @@ Array.prototype.count = function (predicate) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return count(this, predicate);
|
return count(this, predicate);
|
||||||
}
|
};
|
||||||
|
|
||||||
Array.prototype.findAll = function (predicate) {
|
Array.prototype.findAll = function (predicate) {
|
||||||
function findAll(array, predicate) {
|
function findAll(array, predicate) {
|
||||||
@@ -169,7 +184,7 @@ Array.prototype.findAll = function (predicate) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return findAll(this, predicate);
|
return findAll(this, predicate);
|
||||||
}
|
};
|
||||||
|
|
||||||
Array.prototype.contains = function (value) {
|
Array.prototype.contains = function (value) {
|
||||||
function contains(array, value) {
|
function contains(array, value) {
|
||||||
@@ -183,7 +198,7 @@ Array.prototype.contains = function (value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return contains(this, value);
|
return contains(this, value);
|
||||||
}
|
};
|
||||||
|
|
||||||
Array.prototype.removeAll = function (predicate) {
|
Array.prototype.removeAll = function (predicate) {
|
||||||
function removeAll(array, predicate) {
|
function removeAll(array, predicate) {
|
||||||
@@ -198,7 +213,7 @@ Array.prototype.removeAll = function (predicate) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
removeAll(this, predicate);
|
removeAll(this, predicate);
|
||||||
}
|
};
|
||||||
|
|
||||||
Array.prototype.remove = function (element) {
|
Array.prototype.remove = function (element) {
|
||||||
function remove(array, element) {
|
function remove(array, element) {
|
||||||
@@ -209,14 +224,13 @@ Array.prototype.remove = function (element) {
|
|||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
array.splice(index, 1);
|
array.splice(index, 1);
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return remove(this, element);
|
return remove(this, element);
|
||||||
}
|
};
|
||||||
|
|
||||||
Array.prototype.removeAt = function (index) {
|
Array.prototype.removeAt = function (index) {
|
||||||
function removeAt(array, index) {
|
function removeAt(array, index) {
|
||||||
@@ -224,7 +238,7 @@ Array.prototype.removeAt = function (index) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return removeAt(this, index);
|
return removeAt(this, index);
|
||||||
}
|
};
|
||||||
|
|
||||||
Array.prototype.removeRange = function (index, count) {
|
Array.prototype.removeRange = function (index, count) {
|
||||||
function removeRange(array, index, count) {
|
function removeRange(array, index, count) {
|
||||||
@@ -232,7 +246,7 @@ Array.prototype.removeRange = function (index, count) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return removeRange(this, index, count);
|
return removeRange(this, index, count);
|
||||||
}
|
};
|
||||||
|
|
||||||
Array.prototype.select = function (selector) {
|
Array.prototype.select = function (selector) {
|
||||||
function select(array, selector) {
|
function select(array, selector) {
|
||||||
@@ -241,8 +255,7 @@ Array.prototype.select = function (selector) {
|
|||||||
ret.push(selector.call(arguments[2], element, index, array));
|
ret.push(selector.call(arguments[2], element, index, array));
|
||||||
return ret;
|
return ret;
|
||||||
}, []);
|
}, []);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
let ret = [];
|
let ret = [];
|
||||||
for (let i = 0, len = array.length; i < len; i++) {
|
for (let i = 0, len = array.length; i < len; i++) {
|
||||||
ret.push(selector.call(arguments[2], array[i], i, array))
|
ret.push(selector.call(arguments[2], array[i], i, array))
|
||||||
@@ -253,17 +266,16 @@ Array.prototype.select = function (selector) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return select(this, selector);
|
return select(this, selector);
|
||||||
}
|
};
|
||||||
|
|
||||||
Array.prototype.orderBy = function (keySelector, comparer) {
|
Array.prototype.orderBy = function (keySelector, comparer) {
|
||||||
function orderBy(array, keySelector, comparer) {
|
function orderBy(array, keySelector, comparer) {
|
||||||
array.sort(function (x, y) {
|
array.sort(function (x, y) {
|
||||||
let v1 = keySelector(x)
|
let v1 = keySelector(x);
|
||||||
let v2 = keySelector(y)
|
let v2 = keySelector(y);
|
||||||
if (comparer) {
|
if (comparer) {
|
||||||
return comparer(v1, v2);
|
return comparer(v1, v2);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return (v1 > v2) ? 1 : -1;
|
return (v1 > v2) ? 1 : -1;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -272,17 +284,16 @@ Array.prototype.orderBy = function (keySelector, comparer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return orderBy(this, keySelector, comparer);
|
return orderBy(this, keySelector, comparer);
|
||||||
}
|
};
|
||||||
|
|
||||||
Array.prototype.orderByDescending = function (keySelector, comparer) {
|
Array.prototype.orderByDescending = function (keySelector, comparer) {
|
||||||
function orderByDescending(array, keySelector, comparer) {
|
function orderByDescending(array, keySelector, comparer) {
|
||||||
array.sort(function (x, y) {
|
array.sort(function (x, y) {
|
||||||
let v1 = keySelector(x)
|
let v1 = keySelector(x);
|
||||||
let v2 = keySelector(y)
|
let v2 = keySelector(y);
|
||||||
if (comparer) {
|
if (comparer) {
|
||||||
return -comparer(v1, v2);
|
return -comparer(v1, v2);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return (v1 < v2) ? 1 : -1;
|
return (v1 < v2) ? 1 : -1;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -291,7 +302,7 @@ Array.prototype.orderByDescending = function (keySelector, comparer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return orderByDescending(this, keySelector, comparer);
|
return orderByDescending(this, keySelector, comparer);
|
||||||
}
|
};
|
||||||
|
|
||||||
Array.prototype.groupBy = function (keySelector) {
|
Array.prototype.groupBy = function (keySelector) {
|
||||||
function groupBy(array, keySelector) {
|
function groupBy(array, keySelector) {
|
||||||
@@ -299,7 +310,9 @@ Array.prototype.groupBy = function (keySelector) {
|
|||||||
let keys = [];
|
let keys = [];
|
||||||
return array.reduce(function (groups, element, index) {
|
return array.reduce(function (groups, element, index) {
|
||||||
let key = JSON.stringify(keySelector.call(arguments[1], element, index, array))
|
let key = JSON.stringify(keySelector.call(arguments[1], element, index, array))
|
||||||
let index2 = keys.findIndex(function (x) { return x === key });
|
let index2 = keys.findIndex(function (x) {
|
||||||
|
return x === key;
|
||||||
|
});
|
||||||
|
|
||||||
if (index2 < 0) {
|
if (index2 < 0) {
|
||||||
index2 = keys.push(key) - 1;
|
index2 = keys.push(key) - 1;
|
||||||
@@ -312,13 +325,14 @@ Array.prototype.groupBy = function (keySelector) {
|
|||||||
groups[index2].push(element);
|
groups[index2].push(element);
|
||||||
return groups;
|
return groups;
|
||||||
}, []);
|
}, []);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
let groups = [];
|
let groups = [];
|
||||||
let keys = [];
|
let keys = [];
|
||||||
for (let i = 0, len = array.length; i < len; i++) {
|
for (let i = 0, len = array.length; i < len; i++) {
|
||||||
let key = JSON.stringify(keySelector.call(arguments[1], array[i], i, array));
|
let key = JSON.stringify(keySelector.call(arguments[1], array[i], i, array));
|
||||||
let index = keys.findIndex(function (x) { return x === key });
|
let index = keys.findIndex(function (x) {
|
||||||
|
return x === key;
|
||||||
|
});
|
||||||
|
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
index = keys.push(key) - 1;
|
index = keys.push(key) - 1;
|
||||||
@@ -336,7 +350,7 @@ Array.prototype.groupBy = function (keySelector) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return groupBy(this, keySelector);
|
return groupBy(this, keySelector);
|
||||||
}
|
};
|
||||||
|
|
||||||
Array.prototype.sum = function (selector) {
|
Array.prototype.sum = function (selector) {
|
||||||
function sum(array, selector) {
|
function sum(array, selector) {
|
||||||
@@ -345,17 +359,14 @@ Array.prototype.sum = function (selector) {
|
|||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
if (selector) {
|
if (selector) {
|
||||||
ret = selector.call(arguments[2], array[i], i, array);
|
ret = selector.call(arguments[2], array[i], i, array);
|
||||||
|
} else {
|
||||||
|
ret = array[i];
|
||||||
}
|
}
|
||||||
else {
|
} else {
|
||||||
ret = array[i]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (selector) {
|
if (selector) {
|
||||||
ret += selector.call(arguments[2], array[i], i, array);
|
ret += selector.call(arguments[2], array[i], i, array);
|
||||||
}
|
} else {
|
||||||
else {
|
ret += array[i];
|
||||||
ret += array[i]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -364,4 +375,4 @@ Array.prototype.sum = function (selector) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return sum(this, selector);
|
return sum(this, selector);
|
||||||
}
|
};
|
||||||
@@ -36,7 +36,7 @@ module es {
|
|||||||
this._messageTable.set(eventType, list);
|
this._messageTable.set(eventType, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (list.contains(handler))
|
if (list.findIndex(funcPack => funcPack.func == handler) != -1)
|
||||||
console.warn("您试图添加相同的观察者两次");
|
console.warn("您试图添加相同的观察者两次");
|
||||||
list.push(new FuncPack(handler, context));
|
list.push(new FuncPack(handler, context));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user