|
@@ -21,22 +21,22 @@ var isDebug = true;
|
|
|
* observer: 注册对象,指Page对象
|
|
|
*/
|
|
|
function addNotification(name, selector, observer) {
|
|
|
- if (name && selector) {
|
|
|
- if (!observer) {
|
|
|
- // console.log("addNotification Warning: no observer will can't remove notice");
|
|
|
- }
|
|
|
- // console.log("addNotification:" + name);
|
|
|
- var newNotice = {
|
|
|
- name: name,
|
|
|
- selector: selector,
|
|
|
- observer: observer
|
|
|
- };
|
|
|
-
|
|
|
- addNotices(newNotice);
|
|
|
-
|
|
|
- } else {
|
|
|
- // console.log("addNotification error: no selector or name");
|
|
|
+ if (name && selector) {
|
|
|
+ if (!observer) {
|
|
|
+ // console.log("addNotification Warning: no observer will can't remove notice");
|
|
|
}
|
|
|
+ // console.log("addNotification:" + name);
|
|
|
+ var newNotice = {
|
|
|
+ name: name,
|
|
|
+ selector: selector,
|
|
|
+ observer: observer
|
|
|
+ };
|
|
|
+
|
|
|
+ addNotices(newNotice);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ // console.log("addNotification error: no selector or name");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -48,39 +48,39 @@ function addNotification(name, selector, observer) {
|
|
|
* observer: 注册对象,指Page对象
|
|
|
*/
|
|
|
function addOnceNotification(name, selector, observer) {
|
|
|
- if (__notices.length > 0) {
|
|
|
- for (var i = 0; i < __notices.length; i++) {
|
|
|
- var notice = __notices[i];
|
|
|
- if (notice.name === name) {
|
|
|
- if (notice.observer === observer) {
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
+ if (__notices.length > 0) {
|
|
|
+ for (var i = 0; i < __notices.length; i++) {
|
|
|
+ var notice = __notices[i];
|
|
|
+ if (notice.name === name) {
|
|
|
+ if (notice.observer === observer) {
|
|
|
+ return;
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
- this.addNotification(name, selector, observer)
|
|
|
+ }
|
|
|
+ this.addNotification(name, selector, observer)
|
|
|
}
|
|
|
|
|
|
function addNotices(newNotice) {
|
|
|
- // if (__notices.length > 0) {
|
|
|
- // for (var i = 0; i < __notices.length; i++) {
|
|
|
- // var hisNotice = __notices[i];
|
|
|
- // //当名称一样时进行对比,如果不是同一个 则放入数组,否则跳出
|
|
|
- // if (newNotice.name === hisNotice.name) {
|
|
|
- // if (!cmp(hisNotice, newNotice)) {
|
|
|
- // __notices.push(newNotice);
|
|
|
- // }
|
|
|
- // return;
|
|
|
- // }else{
|
|
|
- // __notices.push(newNotice);
|
|
|
- // }
|
|
|
-
|
|
|
- // }
|
|
|
- // } else {
|
|
|
-
|
|
|
- // }
|
|
|
-
|
|
|
- __notices.push(newNotice);
|
|
|
+ // if (__notices.length > 0) {
|
|
|
+ // for (var i = 0; i < __notices.length; i++) {
|
|
|
+ // var hisNotice = __notices[i];
|
|
|
+ // //当名称一样时进行对比,如果不是同一个 则放入数组,否则跳出
|
|
|
+ // if (newNotice.name === hisNotice.name) {
|
|
|
+ // if (!cmp(hisNotice, newNotice)) {
|
|
|
+ // __notices.push(newNotice);
|
|
|
+ // }
|
|
|
+ // return;
|
|
|
+ // }else{
|
|
|
+ // __notices.push(newNotice);
|
|
|
+ // }
|
|
|
+
|
|
|
+ // }
|
|
|
+ // } else {
|
|
|
+
|
|
|
+ // }
|
|
|
+
|
|
|
+ __notices.push(newNotice);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -93,16 +93,16 @@ function addNotices(newNotice) {
|
|
|
*/
|
|
|
|
|
|
function removeNotification(name, observer) {
|
|
|
- // console.log("removeNotification:" + name);
|
|
|
- for (var i = 0; i < __notices.length; i++) {
|
|
|
- var notice = __notices[i];
|
|
|
- if (notice.name === name) {
|
|
|
- if (notice.observer === observer) {
|
|
|
- __notices.splice(i, 1);
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
+ // console.log("removeNotification:" + name);
|
|
|
+ for (var i = 0; i < __notices.length; i++) {
|
|
|
+ var notice = __notices[i];
|
|
|
+ if (notice.name === name) {
|
|
|
+ if (notice.observer === observer) {
|
|
|
+ __notices.splice(i, 1);
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|
|
@@ -116,94 +116,94 @@ function removeNotification(name, observer) {
|
|
|
* info: 携带的参数
|
|
|
*/
|
|
|
function fire(cmdEvent) {
|
|
|
- let name = "cmdEventNotification";
|
|
|
- let info = cmdEvent;
|
|
|
- // console.log("fire:" + name);
|
|
|
- if (__notices.length == 0) {
|
|
|
- console.log("fire error: u hadn't add any notice.");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- for (var i = 0; i < __notices.length; i++) {
|
|
|
- var notice = __notices[i];
|
|
|
- if (notice.name === name) {
|
|
|
- notice.selector(info);
|
|
|
- }
|
|
|
+ let name = "cmdEventNotification";
|
|
|
+ let info = cmdEvent;
|
|
|
+ // console.log("fire:" + name);
|
|
|
+ if (__notices.length == 0) {
|
|
|
+ console.log("fire error: u hadn't add any notice.");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (var i = 0; i < __notices.length; i++) {
|
|
|
+ var notice = __notices[i];
|
|
|
+ if (notice.name === name) {
|
|
|
+ notice.selector(info);
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
function fireName(name, cmdEvent) {
|
|
|
- let info = cmdEvent;
|
|
|
- // console.log("fire:" + name);
|
|
|
- if (__notices.length == 0) {
|
|
|
- console.log("fire error: u hadn't add any notice.");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- for (var i = 0; i < __notices.length; i++) {
|
|
|
- var notice = __notices[i];
|
|
|
- if (notice.name === name) {
|
|
|
- notice.selector(info);
|
|
|
- }
|
|
|
+ let info = cmdEvent;
|
|
|
+ // console.log("fire:" + name);
|
|
|
+ if (__notices.length == 0) {
|
|
|
+ console.log("fire error: u hadn't add any notice.");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (var i = 0; i < __notices.length; i++) {
|
|
|
+ var notice = __notices[i];
|
|
|
+ if (notice.name === name) {
|
|
|
+ notice.selector(info);
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 用于对比两个对象是否相等
|
|
|
function cmp(x, y) {
|
|
|
- // If both x and y are null or undefined and exactly the same
|
|
|
- if (x === y) {
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- // If they are not strictly equal, they both need to be Objects
|
|
|
- if (!(x instanceof Object) || !(y instanceof Object)) {
|
|
|
+ // If both x and y are null or undefined and exactly the same
|
|
|
+ if (x === y) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // If they are not strictly equal, they both need to be Objects
|
|
|
+ if (!(x instanceof Object) || !(y instanceof Object)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // They must have the exact same prototype chain, the closest we can do is
|
|
|
+ // test the constructor.
|
|
|
+ if (x.constructor !== y.constructor) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (var p in x) {
|
|
|
+ // Inherited properties were tested using x.constructor === y.constructor
|
|
|
+ if (x.hasOwnProperty(p)) {
|
|
|
+ // Allows comparing x[ p ] and y[ p ] when set to undefined
|
|
|
+ if (!y.hasOwnProperty(p)) {
|
|
|
return false;
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- // They must have the exact same prototype chain, the closest we can do is
|
|
|
- // test the constructor.
|
|
|
- if (x.constructor !== y.constructor) {
|
|
|
+ // If they have the same strict value or identity then they are equal
|
|
|
+ if (x[p] === y[p]) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Numbers, Strings, Functions, Booleans must be strictly equal
|
|
|
+ if (typeof (x[p]) !== "object") {
|
|
|
return false;
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- for (var p in x) {
|
|
|
- // Inherited properties were tested using x.constructor === y.constructor
|
|
|
- if (x.hasOwnProperty(p)) {
|
|
|
- // Allows comparing x[ p ] and y[ p ] when set to undefined
|
|
|
- if (!y.hasOwnProperty(p)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- // If they have the same strict value or identity then they are equal
|
|
|
- if (x[p] === y[p]) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- // Numbers, Strings, Functions, Booleans must be strictly equal
|
|
|
- if (typeof (x[p]) !== "object") {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- // Objects and Arrays must be tested recursively
|
|
|
- if (!Object.equals(x[p], y[p])) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
+ // Objects and Arrays must be tested recursively
|
|
|
+ if (!Object.equals(x[p], y[p])) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- for (p in y) {
|
|
|
- // allows x[ p ] to be set to undefined
|
|
|
- if (y.hasOwnProperty(p) && !x.hasOwnProperty(p)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
+ for (p in y) {
|
|
|
+ // allows x[ p ] to be set to undefined
|
|
|
+ if (y.hasOwnProperty(p) && !x.hasOwnProperty(p)) {
|
|
|
+ return false;
|
|
|
}
|
|
|
- return true;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
};
|
|
|
|
|
|
module.exports = {
|
|
|
- addNotification: addNotification,
|
|
|
- removeNotification: removeNotification,
|
|
|
- fire: fire,
|
|
|
- fireName: fireName,
|
|
|
- addOnceNotification: addOnceNotification
|
|
|
+ addNotification: addNotification,
|
|
|
+ removeNotification: removeNotification,
|
|
|
+ fire: fire,
|
|
|
+ fireName: fireName,
|
|
|
+ addOnceNotification: addOnceNotification
|
|
|
}
|