本文整理汇总了TypeScript中tns-core-modules/data/observable.Observable.once方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Observable.once方法的具体用法?TypeScript Observable.once怎么用?TypeScript Observable.once使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tns-core-modules/data/observable.Observable
的用法示例。
在下文中一共展示了Observable.once方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: beforeEach
beforeEach("create handlers", () => {
handler = function() {
callCount++;
}
observable = new Observable();
observable.once("test", handler);
});
示例2: 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");
});
示例3: function
const handler1 = function () {
callCount1++;
observable.once("test", handler2);
observable.notify({ eventName: "test", object: observable });
}