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


TypeScript timer.setTimeout函數代碼示例

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


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

示例1: onPullToRefreshInitiated

    public onPullToRefreshInitiated(args: ListViewEventData) {
        console.log("Pull To Refresh Initiated");
        const listView = args.object;
        const that = new WeakRef(this);
        if (this._allItems.length !== 0) {

            // Add 1 more item to the '_sourceDataItems',
            // Simulating a scenario where the 'backend' has been updated with 1 more item that could be loaded by 'load on demand'
            this.addItemsToSourceDataItems(1);

            setTimeout(function () {
                let thisInstance = that.get();
                let numberOfItemsToAdd = 1;
                for (let i = 0; i < numberOfItemsToAdd; i++) {
                    if (thisInstance._allItems.length !== 0) {
                        thisInstance._dataItems.splice(0, 0, thisInstance.getNextItemFromServer());
                    }
                }
                listView.notifyPullToRefreshFinished(thisInstance.isLoadOnDemandModeNeeded());
            }, 1000);
        } else {
            args.returnValue = false;
            listView.notifyPullToRefreshFinished(this.isLoadOnDemandModeNeeded());
        }
    }
開發者ID:telerik,項目名稱:nativescript-ui-samples-angular,代碼行數:25,代碼來源:listview-fixed-size-auto-with-small-source.component.ts

示例2: test_setTimeout_shouldReturnNumber

export function test_setTimeout_shouldReturnNumber() {
    let id = timer.setTimeout(() => {
        //
    });
    timer.clearTimeout(id);
    TKUnit.assertTrue(typeof id === "number", "Callback should return number!");
};
開發者ID:sitefinitysteve,項目名稱:NativeScript,代碼行數:7,代碼來源:timer-tests.ts

示例3: onLoadMoreDataRequested

    public onLoadMoreDataRequested(args: LoadOnDemandListViewEventData) {
        const that = new WeakRef(this);
        const listView: RadListView = args.object;
        if (!this._itemsLoading) {
            if (this._sourceDataItems.length !== 0) {
                console.log("Load More Data Requested WILL LOAD");

                // Set flag to make sure that items are being loaded in the correct order.
                // This is necessary due to the asyc nature of getting and adding new items
                // to the 'items' property of the RadListView that may be caused by remote server API lag.
                this._itemsLoading = true;

                setTimeout(function () {
                    let thatInstance = that.get();
                    thatInstance.addMoreItemsFromSource(1);

                    // Reset the flag to allow next calls of 'loadMoreDataRequested' to load more items
                    thatInstance._itemsLoading = false;

                    listView.notifyLoadOnDemandFinished();
                }, 1500);
            } else {
                console.log("Load More Data Requested CANNOT LOAD");

                args.returnValue = false;
                listView.notifyLoadOnDemandFinished(true);
            }
        }
    }
開發者ID:telerik,項目名稱:nativescript-ui-samples-angular,代碼行數:29,代碼來源:listview-fixed-size-auto-with-small-source.component.ts

示例4: test_setTimeout_callbackNotCalled

export function test_setTimeout_callbackNotCalled() {
    let completed = false;

    const id = timer.setTimeout(() => completed = true, 10);
    timer.clearTimeout(id);
    TKUnit.wait(30 / 1000);

    TKUnit.assert(!completed, "Callback should not be called after the specified time!");
};
開發者ID:sitefinitysteve,項目名稱:NativeScript,代碼行數:9,代碼來源:timer-tests.ts

示例5: test_clearTimeout_insideCallback

export function test_clearTimeout_insideCallback() {
    let completed = false;

    let id = timer.setTimeout(() => {
        completed = true;
        timer.clearTimeout(id);
    });

    TKUnit.waitUntilReady(() => completed, 0.5);
    TKUnit.assert(completed, "Callback should be called");
}
開發者ID:sitefinitysteve,項目名稱:NativeScript,代碼行數:11,代碼來源:timer-tests.ts

示例6: test_clearTimeout_immediatelyAfterCreate

export function test_clearTimeout_immediatelyAfterCreate() {
    let completed = false;

    const id = timer.setTimeout(() => {
        completed = true;
    });
    timer.clearTimeout(id);

    TKUnit.wait(0.02);
    TKUnit.assert(!completed, "Callback should not be called");
}
開發者ID:sitefinitysteve,項目名稱:NativeScript,代碼行數:11,代碼來源:timer-tests.ts

示例7: createPage

export function createPage() {
    function createTxt(text: string) {
        var tv = new textView.TextView();
        tv.text = text;
        return tv;
    }

    var page = new pages.Page();
    var scrollView = new scroll.ScrollView();

    function performGet() {
        console.log("Getting CSS");
        http.getString("http://192.168.54.36:8080/test.css").then(
            function (r) {
                console.log("Applying CSS");
                page.css = r;
                timer.setTimeout(performGet, 1000);
            },
            function (e) {
                console.log("Error: " + e);
                timer.setTimeout(performGet, 1000);
            });
    }

    var stack = new stacks.StackLayout();
    scrollView.content = stack;

    var counter = 0;
    var btn = new btns.Button();
    btn.text = "tap";
    btn.on(btns.Button.tapEvent, function () {
        btn.text = "hi: " + counter++;
    });
    btn.isEnabled = false;

    stack.addChild(btn);
    stack.addChild(createTxt("this is label"));

    var info = new btns.Button();
    info.text = "info";
    info.className = "info";
    info.on(btns.Button.tapEvent, function () {
        info.text = "hi: " + counter++;
        btn.isEnabled = true;
    });
    stack.addChild(info);

    stack.addChild(createTxt("this is another label"));

    page.content = scrollView;
    timer.setTimeout(performGet, 2000);
    return page;
}
開發者ID:NathanWalker,項目名稱:NativeScript,代碼行數:53,代碼來源:page8.ts

示例8: onLoadMoreItemsRequested

 public onLoadMoreItemsRequested(args: LoadOnDemandListViewEventData) {
     const that = new WeakRef(this);
     const listView: RadListView = args.object;
     if (this._sourceDataItems.length > 0) {
         setTimeout(function () {
             that.get().addMoreItemsFromSource(2);
             listView.notifyLoadOnDemandFinished();
         }, 1500);
     } else {
         args.returnValue = false;
         listView.notifyLoadOnDemandFinished(true);
     }
 }
開發者ID:telerik,項目名稱:nativescript-ui-samples-angular,代碼行數:13,代碼來源:listview-dynamic-size-auto.component.ts

示例9: test_clearTimeout_multipleTimes_afterTick

export function test_clearTimeout_multipleTimes_afterTick() {
    let completed = false;

    const id = timer.setTimeout(() => {
        completed = true;
    });

    TKUnit.waitUntilReady(() => completed, 0.5);
    TKUnit.assert(completed, "Callback should be called");

    timer.clearTimeout(id);
    timer.clearTimeout(id);
}
開發者ID:sitefinitysteve,項目名稱:NativeScript,代碼行數:13,代碼來源:timer-tests.ts

示例10: test_setTimeout_callbackCalledAfterSpecifiedTime

export function test_setTimeout_callbackCalledAfterSpecifiedTime() {
    let completed = false;

    // >> timer-set-ten
    const id = timer.setTimeout(() => {
        // >> (hide)
        completed = true;
        // << (hide)
    }, 10);
    // << timer-set-ten

    TKUnit.waitUntilReady(() => completed, 1);
    timer.clearTimeout(id);
    TKUnit.assert(completed, "Callback should be called after the specified time!");
};
開發者ID:sitefinitysteve,項目名稱:NativeScript,代碼行數:15,代碼來源:timer-tests.ts


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