本文整理汇总了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 });
}