本文整理匯總了TypeScript中tns-core-modules/data/observable.Observable.notify方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Observable.notify方法的具體用法?TypeScript Observable.notify怎麽用?TypeScript Observable.notify使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tns-core-modules/data/observable.Observable
的用法示例。
在下文中一共展示了Observable.notify方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it("fire once when fired recursively", () => {
const observable = new Observable();
let callCount1 = 0;
let callCount2 = 0;
const handler2 = function () {
callCount2++;
}
const handler1 = function () {
callCount1++;
observable.once("test", handler2);
observable.notify({ eventName: "test", object: observable });
}
observable.once("test", handler1);
observable.notify({ eventName: "test", object: observable });
assert.equal(callCount1, 1, "Expected the first handler to unsubscribe before being fired and to notify just once");
assert.equal(callCount2, 1, "Expected the second handler to be fired once when recursively notified by the first handler");
});
示例2: function
const handler1 = function () {
callCount1++;
observable.once("test", handler2);
observable.notify({ eventName: "test", object: observable });
}
示例3: notifyWrong
function notifyWrong() {
observable.notify({ eventName: "test2", object: observable });
}