mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
how-tos made with markdown snippet injector
This commit is contained in:
@@ -2,15 +2,11 @@
|
||||
import platform = require("platform");
|
||||
var timer = require("timer/timer");
|
||||
|
||||
// <snippet module="timer" title="timer">
|
||||
// # Timer module
|
||||
// ### How to require timer module
|
||||
// ``` JavaScript
|
||||
// >> timer-require
|
||||
// require("globals");
|
||||
//// OR
|
||||
// var timer = require("timer");
|
||||
// ```
|
||||
// </snippet>
|
||||
// << timer-require
|
||||
|
||||
export var test_setTimeout_isDefined = function () {
|
||||
TKUnit.assert(typeof (timer.setTimeout) !== "undefined", "Method timer.setTimeout() should be defined!");
|
||||
@@ -32,16 +28,13 @@ export var test_setTimeout = function () {
|
||||
var completed: boolean;
|
||||
var isReady = function () { return completed; }
|
||||
|
||||
// <snippet module="timer" title="timer">
|
||||
// ### Evaluates an expression after 0 milliseconds.
|
||||
// ``` JavaScript
|
||||
// >> timer-set-zero
|
||||
timer.setTimeout(function () {
|
||||
// <hide>
|
||||
// >> (hide)
|
||||
completed = true;
|
||||
// </hide>
|
||||
// << (hide)
|
||||
});
|
||||
// ```
|
||||
// </snippet>
|
||||
// << timer-set-zero
|
||||
|
||||
TKUnit.waitUntilReady(isReady, 0.5);
|
||||
TKUnit.assert(completed, "Callback should be called!");
|
||||
@@ -51,16 +44,13 @@ export var test_setTimeout_callbackCalledAfterSpecifiedTime = function () {
|
||||
var completed: boolean;
|
||||
var isReady = function () { return completed; }
|
||||
|
||||
// <snippet module="timer" title="timer">
|
||||
// ### Evaluates an expression after a specified number of milliseconds.
|
||||
// ``` JavaScript
|
||||
// >> timer-set-fivehundred
|
||||
timer.setTimeout(function () {
|
||||
// <hide>
|
||||
// >> (hide)
|
||||
completed = true;
|
||||
// </hide>
|
||||
// << (hide)
|
||||
}, 500);
|
||||
// ```
|
||||
// </snippet>
|
||||
// << timer-set-fivehundred
|
||||
|
||||
TKUnit.waitUntilReady(isReady, 1);
|
||||
TKUnit.assert(completed, "Callback should be called after specified time!");
|
||||
@@ -95,20 +85,17 @@ export var test_setTimeout_callbackShouldBeCleared = function () {
|
||||
var completed: boolean;
|
||||
var isReady = function () { return completed; }
|
||||
|
||||
// <snippet module="timer" title="timer">
|
||||
// ### Cancels the evaluation with the clearTimeout method.
|
||||
// ``` JavaScript
|
||||
// >> timer-set-twothousands
|
||||
var id = timer.setTimeout(function () {
|
||||
// <hide>
|
||||
// >> (hide)
|
||||
completed = true;
|
||||
// </hide>
|
||||
// << (hide)
|
||||
}, 2000);
|
||||
|
||||
//// Clear timeout with specified id.
|
||||
timer.clearTimeout(id);
|
||||
|
||||
// ```
|
||||
// </snippet>
|
||||
// << timer-set-twothousands
|
||||
|
||||
TKUnit.waitUntilReady(isReady, 3);
|
||||
TKUnit.assert(!completed, "Callback should be cleared when clearTimeout() is executed for specified id!");
|
||||
@@ -119,16 +106,13 @@ export var test_setInterval_callbackCalledDuringPeriod = function () {
|
||||
var expected = 4;
|
||||
var isReady = function () { return counter >= expected; }
|
||||
|
||||
// <snippet module="timer" title="timer">
|
||||
// ### Evaluates an expression each time a specified number of milliseconds has elapsed.
|
||||
// ``` JavaScript
|
||||
// >> timer-set-expression
|
||||
timer.setInterval(function () {
|
||||
// <hide>
|
||||
// >> (hide)
|
||||
counter++;
|
||||
// </hide>
|
||||
// << (hide)
|
||||
}, 100);
|
||||
// ```
|
||||
// </snippet>
|
||||
// << timer-set-expression
|
||||
|
||||
TKUnit.waitUntilReady(isReady, 0.5);
|
||||
TKUnit.assert(isReady(), "Callback should be raised at least" + expected + "times! Callback raised " + counter + " times.");
|
||||
@@ -138,17 +122,14 @@ export var test_setInterval_callbackShouldBeCleared = function () {
|
||||
var counter = 0;
|
||||
var isReady = function () { return false; }
|
||||
|
||||
// <snippet module="timer" title="timer">
|
||||
// ### Cancel the interval previously started using the setInterval method.
|
||||
// ``` JavaScript
|
||||
// >> timer-set-interval
|
||||
var id = timer.setInterval(function () {
|
||||
// <hide>
|
||||
// >> (hide)
|
||||
counter++;
|
||||
// </hide>
|
||||
// << (hide)
|
||||
timer.clearInterval(id);
|
||||
}, 100);
|
||||
// ```
|
||||
// </snippet>
|
||||
// << timer-set-interval
|
||||
|
||||
TKUnit.waitUntilReady(isReady, 0.5);
|
||||
TKUnit.assert(counter === 1, "Callback should be raised only once!");
|
||||
|
||||
Reference in New Issue
Block a user