Added "External Ambient Module Declarations" for most modules.

Now they are required by module name e.g require("file-system") instead of by file name.
This commit is contained in:
PanayotCankov
2014-05-21 12:23:19 +03:00
parent f3446e4099
commit 9dd3ba70c5
30 changed files with 470 additions and 467 deletions

View File

@ -9,7 +9,7 @@
*/
import Application = require("application/application");
import Application = require("application");
import timer = require("timer/timer");
var runTest = function (test, testName) {

View File

@ -4,7 +4,7 @@
// It is the main BCL module and is required for other BCL modules to work properly.
// The default bootstrap.js implementation for each platform loads and initializes this module.
// ``` JavaScript
import app = require("application/application");
import app = require("application");
// ```
// The pre-required `app` module is used throughout the following code snippets.
// </snippet>

View File

@ -1,4 +1,4 @@
import app = require("application/application");
import app = require("application");
import TKUnit = require("Tests/TKUnit");
import commonTests = require("Tests/application-tests-common");

View File

@ -4,7 +4,7 @@
// Using the file system requires the FileSystem module.
// TODO: var fs = require("file-system"); => this will break the intellisense of the tests
// ``` JavaScript
import fs = require("file-system/file-system");
import fs = require("file-system");
// ```
// The pre-required `fs` module is used throughout the following code snippets.
// </snippet>

View File

@ -1,5 +1,5 @@
import TKUnit = require("Tests/TKUnit");
import http = require("http/http");
import http = require("http");
require("globals");
// <snippet name="http">

View File

@ -13,8 +13,8 @@
// </snippet>
import imageSource = require("image-source/image-source");
import fs = require("file-system/file-system");
import app = require("application/application");
import fs = require("file-system");
import app = require("application");
import TKUnit = require("Tests/TKUnit");
export var testFromResource = function () {

View File

@ -1,47 +1,50 @@
/**

declare module "application" {
/**
* The main entry point event. This method is expected to return an instance of the root UI for the application.
* This will be an Activity extends for Android and a RootViewController for iOS.
*/
export declare function onLaunch(): any;
function onLaunch(): any;
/**
* This method will be called when the Application is suspended.
*/
export declare function onSuspend();
function onSuspend();
/**
* This method will be called when the Application is resumed after it has been suspended.
*/
export declare function onResume();
function onResume();
/**
* This method will be called when the Application is about to exit.
*/
export declare function onExit();
function onExit();
/**
* This method will be called when there is low memory on the target device.
*/
export declare function onLowMemory();
function onLowMemory();
/**
* This is the Android-specific application object instance.
* Encapsulates methods and properties specific to the Android platform.
* Will be undefined when TargetOS is iOS.
*/
export declare var android: AndroidApplication;
var android: AndroidApplication;
/**
* This is the iOS-specific application object instance.
* Encapsulates methods and properties specific to the iOS platform.
* Will be undefined when TargetOS is Android.
*/
export declare var ios: iOSApplication;
var ios: iOSApplication;
/**
* The abstraction of an Android-specific application object.
*/
export declare class AndroidApplication {
class AndroidApplication {
/**
* The android.app.Application object instance provided to the init of the module.
*/
@ -112,7 +115,7 @@ export declare class AndroidApplication {
/**
* The abstraction of an iOS-specific application object.
*/
export declare class iOSApplication {
class iOSApplication {
/**
* The root view controller for the application.
*/
@ -127,4 +130,5 @@ export declare class iOSApplication {
/**
* Entry point for the module. Initializes the Application singleton and hooks application lifecycle events.
*/
export declare function init(nativeApp: any);
function init(nativeApp: any);
}

View File

@ -2,7 +2,7 @@
/*
Current launch sequence for iOS looks like:
var app = require("application/application");
var app = require("application");
app.tk.ui.Application.current.onLaunch = function() {
log("tk.ui.Application.current.onLaunch");

View File

@ -1,2 +1,2 @@
declare var module, require;
module.exports = require("application/application");
module.exports = require("application");

View File

@ -1,4 +1,4 @@
import appModule = require("application/application");
import appModule = require("application");
var REQUEST_IMAGE_CAPTURE: number = 1;
var REQUEST_SELECT_PICTURE: number = 2;

17
camera/camera.d.ts vendored
View File

@ -1,36 +1,39 @@

declare module "camera" {
import promises = require("promises/promises");
import imageSource = require("image-source/image-source");
export declare enum CameraPosition {
enum CameraPosition {
FRONT = 0,
BACK = 1,
}
export declare enum FlashMode {
enum FlashMode {
AUTO = 0, // default
ON = 1,
OFF = 2
}
export interface Options {
interface Options {
/**
* Specifies which Camera to use
* Specifies which Camera to use.
*/
cameraPosition?: CameraPosition;
/**
* Specifies flash mode
* Specifies flash mode.
*/
flashMode?: FlashMode;
}
// TODO most of hardware related parts need to handle onPause and onResume of the calling activities
export declare class CameraManager {
class CameraManager {
takePicture(params: any, onSuccess: (imageData: any) => any, onError?: (error: any) => any);
// options { useSavedPhotos: true }
pictureFromLibrary(params: any, onSuccess: (imageData: any) => any, onError?: (error: any) => any);
}
export declare var takePicture: (options?: Options) => promises.Promise<imageSource.ImageSource>;
var takePicture: (options?: Options) => promises.Promise<imageSource.ImageSource>;
}

View File

@ -1,4 +1,4 @@
import appModule = require("application/application");
import appModule = require("application");
import textModule = require("text/text");
export class FileSystemAccess {

View File

@ -1,4 +1,4 @@
import app_module = require("application/application");
import app_module = require("application");
import utilsModule = require("utils/utils_ios");
import textModule = require("text/text");

View File

@ -1,6 +1,9 @@
import promises = require("promises/promises");

declare module "file-system" {
export declare class FileSystemEntity {
import promises = require("promises/promises");
class FileSystemEntity {
/**
* Gets the Date object specifying the last time this entity was modified.
*/
@ -34,7 +37,7 @@ export declare class FileSystemEntity {
public rename(newName: string): promises.Promise<any>;
}
export declare class File extends FileSystemEntity {
class File extends FileSystemEntity {
/**
* Checks whether a File with the specified path already exists.
*/
@ -66,7 +69,7 @@ export declare class File extends FileSystemEntity {
public writeText(content: string, encoding?: string): promises.Promise<any>;
}
export declare class Folder extends FileSystemEntity {
class Folder extends FileSystemEntity {
/**
* Determines whether this instance is a KnownFolder (accessed through the KnownFolders object).
*/
@ -119,7 +122,7 @@ export declare class Folder extends FileSystemEntity {
/**
* Provides access to the top-level Folders instances that are accessible from the application. Use these as entry points to access the FileSystem.
*/
export declare module knownFolders {
module knownFolders {
/**
* Gets the Documents folder available for the current application. This Folder is private for the application and not accessible from Users/External apps.
*/
@ -134,7 +137,7 @@ export declare module knownFolders {
/**
* Enables path-specific operations like join, extension, etc.
*/
export declare module path {
module path {
/**
* Normalizes a path, taking care of occurrances like ".." and "//"
*/
@ -150,3 +153,4 @@ export declare module path {
*/
export var separator: string;
}
}

View File

@ -1,2 +1,2 @@
declare var module, require;
module.exports = require("file-system/file-system");
module.exports = require("file-system");

View File

@ -8,3 +8,4 @@ setInterval = timer.setInterval;
clearInterval = timer.clearInterval;
console = new consoleModule.Console();

View File

@ -1,6 +1,6 @@
import image = require("image-source/image-source");
import promises = require("promises/promises");
import http = require("http/http");
import http = require("http");
/**
* Gets string from url.

View File

@ -2,7 +2,7 @@
* Android specific http request implementation.
*/
import promises = require("promises/promises");
import http = require("http/http");
import http = require("http");
declare var exports;
require("utils/module-merge").merge(require("http/http-common"), exports);

25
http/http.d.ts vendored
View File

@ -1,18 +1,20 @@
import image = require("image-source/image-source");

declare module "http" {
import image = require("image-source/image-source");
import promises = require("promises/promises");
export declare function getString(url: string): promises.Promise<string>
export declare function getString(options: HttpRequestOptions): promises.Promise<string>
function getString(url: string): promises.Promise<string>
function getString(options: HttpRequestOptions): promises.Promise<string>
export declare function getJSON<T>(url: string): promises.Promise<T>
export declare function getJSON<T>(options: HttpRequestOptions): promises.Promise<T>
function getJSON<T>(url: string): promises.Promise<T>
function getJSON<T>(options: HttpRequestOptions): promises.Promise<T>
export declare function getImage(url: string): promises.Promise<image.ImageSource>
export declare function getImage(options: HttpRequestOptions): promises.Promise<image.ImageSource>
function getImage(url: string): promises.Promise<image.ImageSource>
function getImage(options: HttpRequestOptions): promises.Promise<image.ImageSource>
export declare function request(options: HttpRequestOptions): promises.Promise<HttpResponse>;
function request(options: HttpRequestOptions): promises.Promise<HttpResponse>;
export interface HttpRequestOptions {
interface HttpRequestOptions {
url: string;
method: string;
headers?: any;
@ -20,15 +22,16 @@ export interface HttpRequestOptions {
timeout?: number;
}
export interface HttpResponse {
interface HttpResponse {
statusCode: number;
headers: any;
content?: HttpContent;
}
export interface HttpContent {
interface HttpContent {
raw: any;
toString: () => string;
toJSON: () => any;
toImage: () => image.ImageSource;
}
}

View File

@ -2,7 +2,7 @@
* iOS specific http request implementation.
*/
import promises = require("promises/promises");
import http = require("http/http");
import http = require("http");
declare var exports;
require("utils/module-merge").merge(require("http/http-common"), exports);

View File

@ -1,4 +1,4 @@
import appModule = require("application/application");
import appModule = require("application");
export var fromResource = function (name: string) {
var androidApp = appModule.android;

View File

@ -1,9 +1,11 @@
import promises = require("promises/promises");

declare module "image-source" {
import promises = require("promises/promises");
/**
* Defines the recognized image formats.
*/
export declare enum ImageFormat {
enum ImageFormat {
PNG,
JPEG,
}
@ -11,7 +13,7 @@ export declare enum ImageFormat {
/**
* Encapsulates the common abstraction behind a platform specific object (typically a Bitmap) that is used as a source for images.
*/
export declare class ImageSource {
class ImageSource {
/**
* Gets the height of this instance. This is a read-only property.
*/
@ -62,25 +64,26 @@ export declare class ImageSource {
/**
* Creates a new Image instance and loads it from the specified resource name.
*/
export declare function fromResource(name: string): ImageSource;
function fromResource(name: string): ImageSource;
/**
* Creates a new Image instance and loads it from the specified file.
*/
export declare function fromFile(path: string): ImageSource;
function fromFile(path: string): ImageSource;
/**
* Creates a new Image instance and loads it from the specified resource name.
*/
export declare function fromData(data: any): ImageSource;
function fromData(data: any): ImageSource;
/**
* Creates a new Image instance and sets the provided native source object (typically a Bitmap).
* The native source object will update either the android or ios properties, depending on the target os.
*/
export declare function fromNativeSource(source: any): ImageSource;
function fromNativeSource(source: any): ImageSource;
/**
* Downloads the image from the provided Url and creates a new Image instance from it.
*/
export declare function fromUrl(url: string): promises.Promise<ImageSource>;
function fromUrl(url: string): promises.Promise<ImageSource>;
}

View File

@ -1,7 +1,7 @@
import app = require("application/application");
import app = require("application");
import native = require("image-source/image-source-native");
import promises = require("promises/promises");
import http = require("http/http");
import http = require("http");
export enum ImageFormat {
PNG,

View File

@ -1,4 +1,4 @@
import appModule = require("application/application");
import appModule = require("application");
import Common = require("local-settings/local-settings-common");
var sharedPreferences = appModule.android.context.getSharedPreferences("prefs.db", 0);

View File

@ -1,73 +1,72 @@
/**

declare module "local-settings" {
/**
* report does such key exist
*/
export declare var hasKey: (key: string) => boolean;
// getters
var hasKey: (key: string) => boolean;
/**
* gets value of the key as boolean, user can provide default value in case there is no value for the key
*/
export declare var getBoolean: (key: string, defaultValue?: boolean) => boolean;
var getBoolean: (key: string, defaultValue?: boolean) => boolean;
/**
* gets value of the key as string, user can provide default value in case there is no value for the key
*/
export declare var getString: (key: string, defaultValue?: string) => string;
var getString: (key: string, defaultValue?: string) => string;
/**
* gets value of the key as string array, user can provide default value in case there is no value for the key
*/
export declare var getStringArray: (key: string, defaultValue?: string[]) => string[];
var getStringArray: (key: string, defaultValue?: string[]) => string[];
/**
* gets value of the key as number (double), user can provide default value in case there is no value for the key
*/
export declare var getNumber: (key: string, defaultValue?: number) => number;
var getNumber: (key: string, defaultValue?: number) => number;
/**
* gets value of the key as integer, user can provide default value in case there is no value for the key
*/
export declare var getInt: (key: string, defaultValue?: number) => number;
var getInt: (key: string, defaultValue?: number) => number;
/**
* gets value of the key as long integer (not fully supported by JS), user can provide default value in case there is no value for the key
*/
export declare var getLong: (key: string, defaultValue?: number) => number;
// setters
var getLong: (key: string, defaultValue?: number) => number;
/**
* sets value for a key as boolean
*/
export declare var setBoolean: (key: string, value: boolean) => void;
var setBoolean: (key: string, value: boolean) => void;
/**
* sets value for a key as string
*/
export declare var setString: (key: string, value: string) => void;
var setString: (key: string, value: string) => void;
/**
* sets value for a key as string array
*/
export declare var setStringArray: (key: string, value: string[]) => void;
var setStringArray: (key: string, value: string[]) => void;
/**
* sets value for a key as JS number (double)
*/
export declare var setNumber: (key: string, value: number) => void;
var setNumber: (key: string, value: number) => void;
/**
* sets value for a key as integer
*/
export declare var setInt: (key: string, value: number) => void;
var setInt: (key: string, value: number) => void;
/**
* sets value for a key as long integer
*/
export declare var setLong: (key: string, value: number) => void;
var setLong: (key: string, value: number) => void;
/**
* removes a value for key
*/
export declare var remove: (key: string) => void;
var remove: (key: string) => void;
}

View File

@ -1,5 +1,5 @@
import types = require("location/location-types");
import appModule = require("application/application");
import appModule = require("application");
export class LocationManager {
// in meters

View File

@ -2,7 +2,7 @@
import promises = require("promises/promises");
import timer = require("timer/timer");
import types = require("location/location-types");
import locationManagerModule = require("location/location-manager");
import locationManagerModule = require("location");
// merge the exports of the types module with the exports of this file
declare var exports;

View File

@ -9,7 +9,6 @@
/**
Returns a new "Deferred" value that may be resolved or rejected.
*/
export function defer<Value>(): Deferred<Value> {
return new DeferredI<Value>();
}
@ -17,7 +16,6 @@ export function defer<Value>(): Deferred<Value> {
/**
Converts a value to a resolved promise.
*/
export function resolve<Value>(v: Value): Promise<Value> {
return defer<Value>().resolve(v).promise();
}
@ -25,7 +23,6 @@ export function resolve<Value>(v: Value): Promise<Value> {
/**
Returns a rejected promise.
*/
export function reject<Value>(err: Rejection): Promise<Value> {
return defer<Value>().reject(err).promise();
}
@ -39,7 +36,6 @@ export function reject<Value>(err: Rejection): Promise<Value> {
All the values of all promise results are collected into the resulting promise which is resolved as soon
the last generated element value is resolved.
*/
export function unfold<Seed, Element>(
unspool: (current: Seed) => { promise: Promise<Element>; next?: Seed },
seed: Seed)
@ -94,7 +90,6 @@ function unfoldCore<Seed, Element>(
Once a promise is either Rejected or Resolved, it can not change its
status anymore.
*/
export enum Status {
Unfulfilled,
Rejected,
@ -105,7 +100,6 @@ export enum Status {
If a promise gets rejected, at least a message that indicates the error or
reason for the rejection must be provided.
*/
export interface Rejection {
message: string;
}
@ -113,7 +107,6 @@ export interface Rejection {
/**
Both Promise<T> and Deferred<T> share these properties.
*/
export interface PromiseState<Value> {
/// The current status of the promise.
status: Status;
@ -132,7 +125,6 @@ export interface PromiseState<Value> {
When multiple handlers are registered with done(), fail(), or always(), they are called in the
same order.
*/
export interface Promise<Value> extends PromiseState<Value> {
/**
Returns a promise that represents a promise chain that consists of this
@ -161,7 +153,6 @@ export interface Promise<Value> extends PromiseState<Value> {
an asynchronous process. Callers of that function should only see the Promise<Value> that
is returned by promise().
*/
export interface Deferred<Value> extends PromiseState<Value> {
/// Returns the encapsulated promise of this deferred instance.
/// The returned promise supports composition but removes the ability to resolve or reject
@ -183,7 +174,6 @@ export interface Deferred<Value> extends PromiseState<Value> {
As soon one of the arguments gets rejected, the resulting promise gets rejected.
If no promises were provided, the resulting promise is immediately resolved.
*/
export function when(...promises: Promise<any>[]): Promise<any[]> {
var allDone = defer<any[]>();
if (!promises.length) {
@ -216,7 +206,6 @@ export function when(...promises: Promise<any>[]): Promise<any[]> {
The Promise<Value> instance is a proxy to the Deferred<Value> instance.
*/
class PromiseI<Value> implements Promise<Value>
{
constructor(public deferred: DeferredI<Value>)
@ -249,7 +238,6 @@ class PromiseI<Value> implements Promise<Value>
/**
Implementation of a deferred.
*/
class DeferredI<Value> implements Deferred<Value>{
private _resolved: (v: Value) => void = _ => { };
@ -379,7 +367,6 @@ class DeferredI<Value> implements Deferred<Value>{
/**
Promise Generators and Iterators.
*/
export interface Generator<E> {
(): Iterator<E>;
}
@ -419,7 +406,6 @@ class IteratorI<E> implements Iterator<E>
/**
Iterator functions.
*/
export function each<E>(gen: Generator<E>, f: (e: E) => void): Promise<{}> {
var d = defer();
eachCore(d, gen(), f);
@ -443,7 +429,6 @@ function eachCore<E>(fin: Deferred<{}>, it: Iterator<E>, f: (e: E) => void): voi
/**
std
*/
export function isUndefined(v) {
return typeof v === 'undefined';
}

1
text/text.d.ts vendored
View File

@ -9,3 +9,4 @@ export declare module encoding {
export var UTF_16LE: any;
export var UTF_8: any;
}