當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript observable.Observable類代碼示例

本文整理匯總了TypeScript中tns-core-modules/data/observable.Observable的典型用法代碼示例。如果您正苦於以下問題:TypeScript Observable類的具體用法?TypeScript Observable怎麽用?TypeScript Observable使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Observable類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: beforeEach

 beforeEach("create handlers", () => {
     handler = function() {
         callCount++;
     }
     observable = new Observable();
     observable.once("test", handler);
 });
開發者ID:NathanWalker,項目名稱:NativeScript,代碼行數:7,代碼來源:observable.ts

示例2: pageLoaded

export function pageLoaded(args) {
    var page = args.object;
    var textFieldSecured = page.getViewById("textFieldSecured");
    textFieldSecured.secure = true;

    var obj = new observable.Observable();
    obj.set("textProperty", "text");
    page.bindingContext = obj;
}
開發者ID:NathanWalker,項目名稱:NativeScript,代碼行數:9,代碼來源:secured-text-field-4135.ts

示例3: 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");
 });
開發者ID:NathanWalker,項目名稱:NativeScript,代碼行數:17,代碼來源:observable.ts

示例4: describe

    describe("once", () => {

        let observable: Observable;
        let handler: () => void;
        let callCount: number = 0;

        beforeEach("create handlers", () => {
            handler = function() {
                callCount++;
            }
            observable = new Observable();
            observable.once("test", handler);
        });
        afterEach("reset handlers", () => {
            callCount = 0;
            handler = null;
            observable = null;
        });

        function notify() {
            observable.notify({ eventName: "test", object: observable });
        }
        function notifyWrong() {
            observable.notify({ eventName: "test2", object: observable });
        }

        it("fires just once", () => {
            notify();
            notify();
            assert.equal(callCount, 1, "Expected the handler to be called exactly once");
        });
        it("does not fire for other events", () => {
            notifyWrong();
            assert.equal(callCount, 0, "Expected the handler to not be called, when other events fire");
        });
    });
開發者ID:NathanWalker,項目名稱:NativeScript,代碼行數:36,代碼來源:observable.ts

示例5: activityBackPressedCallback

function activityBackPressedCallback(args: AndroidActivityBackPressedEventData) {
    if (context && context.get("shouldCancel")) {
        context.set("shouldCancel", false);
        context.set("message", "Back-pressed canceled!");
        args.cancel = true;
    }
}
開發者ID:NathanWalker,項目名稱:NativeScript,代碼行數:7,代碼來源:android-back-button-page.ts

示例6: onPageLoaded

export function onPageLoaded(args) {
    var page = args.object;
    vm.set("firstTitle", "fiiiirst");
    vm.set("secondTitle", "secondTitle");
    vm.set("secondIcon", "res://icon");
    page.bindingContext = vm;
}
開發者ID:m-abs,項目名稱:NativeScript,代碼行數:7,代碼來源:tab-view.ts

示例7: onTap

export function onTap() {
    i++;
    vm.set("firstTitle", "changed " + i);
    if (i === 3) {
        vm.set("firstIcon", "res://ic_action");
    }
    if (i === 4) {
        vm.set("firstIcon", "");
    }
}
開發者ID:m-abs,項目名稱:NativeScript,代碼行數:10,代碼來源:tab-view.ts

示例8: pageLoaded

export function pageLoaded(args) {
  // Get the event sender
  page = args.object;
  page.bindingContext = data;
  data.set('src', '~/gifs/hammer.gif');

  setTimeout(() => {
    return data.set('src', '~/gifs/darthRide.gif');
  }, 3000);

  if (isAndroid && device.sdkVersion >= '21') {
    const window = app.android.startActivity.getWindow();
    window.setStatusBarColor(new Color('#00695C').android);
  }
}
開發者ID:bradmartin,項目名稱:nativescript-gif,代碼行數:15,代碼來源:main-page.ts

示例9: function

 const handler1 = function () {
     callCount1++;
     observable.once("test", handler2);
     observable.notify({ eventName: "test", object: observable });
 }
開發者ID:NathanWalker,項目名稱:NativeScript,代碼行數:5,代碼來源:observable.ts

示例10: notifyWrong

 function notifyWrong() {
     observable.notify({ eventName: "test2", object: observable });
 }
開發者ID:NathanWalker,項目名稱:NativeScript,代碼行數:3,代碼來源:observable.ts


注:本文中的tns-core-modules/data/observable.Observable類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。