优化
This commit is contained in:
@@ -235,27 +235,30 @@ export function clear() {
|
||||
}
|
||||
|
||||
export function onScanListener(listener, key, match, level) {
|
||||
if (!key || typeof key !== 'string') {
|
||||
return;
|
||||
}
|
||||
if (typeof listener !== 'function') {
|
||||
return;
|
||||
}
|
||||
let item = null;
|
||||
for (let i = 0; i < _scan_listener_list.length; i++) {
|
||||
const _i = _scan_listener_list[i];
|
||||
if (_i.listener === listener) {
|
||||
if (_i.key === key) {
|
||||
item = _i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (item) {
|
||||
item.key = key;
|
||||
item.level = level;
|
||||
item.match = match;
|
||||
item.listener = listener;
|
||||
} else {
|
||||
item = {
|
||||
key,
|
||||
match,
|
||||
level,
|
||||
listener,
|
||||
match: match || "",
|
||||
level: level || 0,
|
||||
listener: listener ,
|
||||
cancel: () => {
|
||||
const index = _scan_listener_list.indexOf(item);
|
||||
if (index !== -1) {
|
||||
|
||||
Reference in New Issue
Block a user