From 255c6232a0b5de5a8ccbc0c26ad27d81a2a35d1c Mon Sep 17 00:00:00 2001 From: Stefan B Date: Tue, 15 Sep 2015 12:17:39 +0300 Subject: [PATCH 01/26] add module react-dom --- react-dom/react-dom.d.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 react-dom/react-dom.d.ts diff --git a/react-dom/react-dom.d.ts b/react-dom/react-dom.d.ts new file mode 100644 index 000000000..2a70fdc37 --- /dev/null +++ b/react-dom/react-dom.d.ts @@ -0,0 +1,35 @@ +/// + +declare class __ReactDom { + public render

( + element: __React.DOMElement

, + container: Element, + callback?: () => any): __React.DOMComponent

; + public render( + element: __React.ClassicElement

, + container: Element, + callback?: () => any): __React.ClassicComponent; + public render( + element: __React.ReactElement

, + container: Element, + callback?: () => any): __React.Component; + + public findDOMNode( + componentOrElement: __React.Component | Element): TElement; + public findDOMNode( + componentOrElement: __React.Component | Element): Element; + + public unmountComponentAtNode(container: Element): boolean; +} + +declare class __ReactDomServer { + public renderToString(element: __React.ReactElement): string; + public renderToStaticMarkup(element: __React.ReactElement): string; +} +declare module "react-dom" { + export = __ReactDom +} + +declare module "react-dom/server" { + export = __ReactDomServer +} \ No newline at end of file From 0380b3bc264d2caac3673a86a7b8c53dad706ab9 Mon Sep 17 00:00:00 2001 From: Stefan B Date: Tue, 15 Sep 2015 12:25:25 +0300 Subject: [PATCH 02/26] add header --- react-dom/react-dom.d.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/react-dom/react-dom.d.ts b/react-dom/react-dom.d.ts index 2a70fdc37..a371d814e 100644 --- a/react-dom/react-dom.d.ts +++ b/react-dom/react-dom.d.ts @@ -1,3 +1,6 @@ +// Type definitions for React-DOM v0.14.0-rc +// Project: https://www.npmjs.com/package/react-dom + /// declare class __ReactDom { From 2ee9d920398988fae647922328cc1b775a5f66d9 Mon Sep 17 00:00:00 2001 From: Stefan B Date: Tue, 15 Sep 2015 12:28:20 +0300 Subject: [PATCH 03/26] add Definitions by --- react-dom/react-dom.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/react-dom/react-dom.d.ts b/react-dom/react-dom.d.ts index a371d814e..6a7bcbd28 100644 --- a/react-dom/react-dom.d.ts +++ b/react-dom/react-dom.d.ts @@ -1,5 +1,6 @@ // Type definitions for React-DOM v0.14.0-rc // Project: https://www.npmjs.com/package/react-dom +// Definitions by: Stefan Bieliauskas /// From 354b00ab6ca51e652e1becbd5a741c4aa6e40f0a Mon Sep 17 00:00:00 2001 From: Stefan B Date: Tue, 15 Sep 2015 12:31:36 +0300 Subject: [PATCH 04/26] modify header --- react-dom/react-dom.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/react-dom/react-dom.d.ts b/react-dom/react-dom.d.ts index 6a7bcbd28..fce4591dd 100644 --- a/react-dom/react-dom.d.ts +++ b/react-dom/react-dom.d.ts @@ -1,6 +1,7 @@ // Type definitions for React-DOM v0.14.0-rc // Project: https://www.npmjs.com/package/react-dom -// Definitions by: Stefan Bieliauskas +// Definitions by: Stefan-Bieliauskas +// Definitions: https://github.com/borisyankov/DefinitelyTyped /// From 90a301c5ae5696b17c4412d0591355304a4ddafa Mon Sep 17 00:00:00 2001 From: Stefan B Date: Tue, 15 Sep 2015 12:32:52 +0300 Subject: [PATCH 05/26] modify header --- react-dom/react-dom.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/react-dom/react-dom.d.ts b/react-dom/react-dom.d.ts index fce4591dd..16ded77d8 100644 --- a/react-dom/react-dom.d.ts +++ b/react-dom/react-dom.d.ts @@ -1,6 +1,6 @@ // Type definitions for React-DOM v0.14.0-rc // Project: https://www.npmjs.com/package/react-dom -// Definitions by: Stefan-Bieliauskas +// Definitions by: Stefan-Bieliauskas // Definitions: https://github.com/borisyankov/DefinitelyTyped /// From ce340e14bc4cddb77f1dd0e58faafff1e5f0c3e5 Mon Sep 17 00:00:00 2001 From: Alexandru Ciuca Date: Mon, 28 Sep 2015 17:47:43 +0300 Subject: [PATCH 06/26] node-uuid - split files and tests per environment --- node-uuid/README.md | 8 +++ node-uuid/node-uuid-base.d.ts | 52 +++++++++++++++++++ node-uuid/node-uuid-cjs-tests.ts | 36 ++++++++++++++ node-uuid/node-uuid-cjs.d.ts | 10 ++++ node-uuid/node-uuid-global-tests.ts | 27 ++++++++++ node-uuid/node-uuid-global.d.ts | 4 ++ node-uuid/node-uuid-tests.ts | 40 +++++++-------- node-uuid/node-uuid.d.ts | 77 +++++++++++------------------ 8 files changed, 186 insertions(+), 68 deletions(-) create mode 100644 node-uuid/README.md create mode 100644 node-uuid/node-uuid-base.d.ts create mode 100644 node-uuid/node-uuid-cjs-tests.ts create mode 100644 node-uuid/node-uuid-cjs.d.ts create mode 100644 node-uuid/node-uuid-global-tests.ts create mode 100644 node-uuid/node-uuid-global.d.ts diff --git a/node-uuid/README.md b/node-uuid/README.md new file mode 100644 index 000000000..234d608e8 --- /dev/null +++ b/node-uuid/README.md @@ -0,0 +1,8 @@ +This folder contains definitions for the node-uuid library in 3 flavors: + +- node-uuid.d.ts + - for use in node environment (default) +- node-uuid-global.d.ts + - for use in browser environment as a global variable +- node-uuid-cjs.d.ts + - for use in browser environment as a CommonJS module (using a loader such as webpack) \ No newline at end of file diff --git a/node-uuid/node-uuid-base.d.ts b/node-uuid/node-uuid-base.d.ts new file mode 100644 index 000000000..255bb6b33 --- /dev/null +++ b/node-uuid/node-uuid-base.d.ts @@ -0,0 +1,52 @@ +// Type definitions for node-uuid.js +// Project: https://github.com/broofa/node-uuid +// Definitions by: Jeff May +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/** Common definitions for all environments */ +declare namespace __NodeUUID { + interface UUIDOptions { + + /** + * Node id as Array of 6 bytes (per 4.1.6). + * Default: Randomly generated ID. See note 1. + */ + node?: any[]; + + /** + * (Number between 0 - 0x3fff) RFC clock sequence. + * Default: An internally maintained clockseq is used. + */ + clockseq?: number; + + /** + * (Number | Date) Time in milliseconds since unix Epoch. + * Default: The current time is used. + */ + msecs?: number|Date; + + /** + * (Number between 0-9999) additional time, in 100-nanosecond units. Ignored if msecs is unspecified. + * Default: internal uuid counter is used, as per 4.2.1.2. + */ + nsecs?: number; + } + + interface UUID { + v1(options?: UUIDOptions): string; + v1(options?: UUIDOptions, buffer?: number[], offset?: number): number[]; + + v2(options?: UUIDOptions): string; + v2(options?: UUIDOptions, buffer?: number[], offset?: number): number[]; + + v3(options?: UUIDOptions): string; + v3(options?: UUIDOptions, buffer?: number[], offset?: number): number[]; + + v4(options?: UUIDOptions): string; + v4(options?: UUIDOptions, buffer?: number[], offset?: number): number[]; + + parse(id: string, buffer?: number[], offset?: number): number[]; + + unparse(buffer: number[], offset?: number): string; + } +} diff --git a/node-uuid/node-uuid-cjs-tests.ts b/node-uuid/node-uuid-cjs-tests.ts new file mode 100644 index 000000000..e2d1d57d7 --- /dev/null +++ b/node-uuid/node-uuid-cjs-tests.ts @@ -0,0 +1,36 @@ +/// + +import nodeUuid = require('node-uuid'); + +var uid1: string = nodeUuid.v1(); +var uid2: string = nodeUuid.v2(); +var uid3: string = nodeUuid.v3(); +var uid4: string = nodeUuid.v4(); + +var options: __NodeUUID.UUIDOptions = { + node: [], + clockseq: 2, + nsecs: 3, + msecs: new Date() +}; + +var padding: number[] = [0, 1, 2]; + +var offset: number = 15; + +var buf : number[] = []; + +nodeUuid.parse(uid4, buf, offset); +nodeUuid.unparse(buf, offset); + +var uid21: number[] = nodeUuid.v1(options, padding, offset); +var uid22: number[] = nodeUuid.v2(options, padding, offset); +var uid23: number[] = nodeUuid.v3(options, padding, offset); +var uid24: number[] = nodeUuid.v4(options, padding, offset); + +var buffer: Buffer; + +var uid31: Buffer = nodeUuid.v1(options, buffer, offset); +var uid32: Buffer = nodeUuid.v2(options, buffer, offset); +var uid33: Buffer = nodeUuid.v3(options, buffer, offset); +var uid34: Buffer = nodeUuid.v4(options, buffer, offset); diff --git a/node-uuid/node-uuid-cjs.d.ts b/node-uuid/node-uuid-cjs.d.ts new file mode 100644 index 000000000..abbee3eaf --- /dev/null +++ b/node-uuid/node-uuid-cjs.d.ts @@ -0,0 +1,10 @@ +/// + +/** + * Expose as CommonJS module + * For use in node environment or browser environment (using webpack or other module loaders) + */ +declare module "node-uuid" { + var uuid: __NodeUUID.UUID; + export = uuid; +} \ No newline at end of file diff --git a/node-uuid/node-uuid-global-tests.ts b/node-uuid/node-uuid-global-tests.ts new file mode 100644 index 000000000..ad98519aa --- /dev/null +++ b/node-uuid/node-uuid-global-tests.ts @@ -0,0 +1,27 @@ +/// + +var uid1: string = uuid.v1(); +var uid2: string = uuid.v2(); +var uid3: string = uuid.v3(); +var uid4: string = uuid.v4(); + +var options: __NodeUUID.UUIDOptions = { + node: [], + clockseq: 2, + nsecs: 3, + msecs: new Date() +}; + +var padding: number[] = [0, 1, 2]; + +var offset: number = 15; + +var buf : number[] = []; + +uuid.parse(uid4, buf, offset); +uuid.unparse(buf, offset); + +var uid21: number[] = uuid.v1(options, padding, offset); +var uid22: number[] = uuid.v2(options, padding, offset); +var uid23: number[] = uuid.v3(options, padding, offset); +var uid24: number[] = uuid.v4(options, padding, offset); diff --git a/node-uuid/node-uuid-global.d.ts b/node-uuid/node-uuid-global.d.ts new file mode 100644 index 000000000..d70d9e120 --- /dev/null +++ b/node-uuid/node-uuid-global.d.ts @@ -0,0 +1,4 @@ +/// + +/** Expose as global variable */ +declare var uuid: __NodeUUID.UUID; diff --git a/node-uuid/node-uuid-tests.ts b/node-uuid/node-uuid-tests.ts index e922c04de..0c9c31109 100644 --- a/node-uuid/node-uuid-tests.ts +++ b/node-uuid/node-uuid-tests.ts @@ -1,36 +1,36 @@ /// -import uuid = require('node-uuid'); +import nodeUuid = require('node-uuid'); -var uid1: string = uuid.v1() -var uid2: string = uuid.v2() -var uid3: string = uuid.v3() -var uid4: string = uuid.v4() +var uid1: string = nodeUuid.v1(); +var uid2: string = nodeUuid.v2(); +var uid3: string = nodeUuid.v3(); +var uid4: string = nodeUuid.v4(); -var options: UUIDOptions = { +var options: __NodeUUID.UUIDOptions = { node: [], clockseq: 2, nsecs: 3, msecs: new Date() -} +}; -var padding: number[] = [0, 1, 2] +var padding: number[] = [0, 1, 2]; -var offset: number = 15 +var offset: number = 15; -var buf : number[] = [] +var buf : number[] = []; -uuid.parse(uid4, buf, offset) -uuid.unparse(buf, offset) +nodeUuid.parse(uid4, buf, offset); +nodeUuid.unparse(buf, offset); -var uid21: number[] = uuid.v1(options, padding, offset) -var uid22: number[] = uuid.v2(options, padding, offset) -var uid23: number[] = uuid.v3(options, padding, offset) -var uid24: number[] = uuid.v4(options, padding, offset) +var uid21: number[] = nodeUuid.v1(options, padding, offset); +var uid22: number[] = nodeUuid.v2(options, padding, offset); +var uid23: number[] = nodeUuid.v3(options, padding, offset); +var uid24: number[] = nodeUuid.v4(options, padding, offset); var buffer: Buffer; -var uid31: Buffer = uuid.v1(options, buffer, offset) -var uid32: Buffer = uuid.v2(options, buffer, offset) -var uid33: Buffer = uuid.v3(options, buffer, offset) -var uid34: Buffer = uuid.v4(options, buffer, offset) +var uid31: Buffer = nodeUuid.v1(options, buffer, offset); +var uid32: Buffer = nodeUuid.v2(options, buffer, offset); +var uid33: Buffer = nodeUuid.v3(options, buffer, offset); +var uid34: Buffer = nodeUuid.v4(options, buffer, offset); diff --git a/node-uuid/node-uuid.d.ts b/node-uuid/node-uuid.d.ts index aec39084f..bb7270809 100644 --- a/node-uuid/node-uuid.d.ts +++ b/node-uuid/node-uuid.d.ts @@ -4,60 +4,41 @@ // Definitions: https://github.com/borisyankov/DefinitelyTyped /// +/// +/// -interface UUIDOptions { - +/** + * Definitions for use in node environment + * + * !! For browser enviroments, use node-uuid-global or node-uuid-cjs + */ +declare module __NodeUUID { /** - * Node id as Array of 6 bytes (per 4.1.6). - * Default: Randomly generated ID. See note 1. + * Overloads for node environment + * We need to duplicate some declarations because + * interface merging doesn't work with overloads */ - node?: any[] + interface UUID { + v1(options?: UUIDOptions): string; + v1(options?: UUIDOptions, buffer?: number[], offset?: number): number[]; + v1(options?: UUIDOptions, buffer?: Buffer, offset?: number): Buffer; - /** - * (Number between 0 - 0x3fff) RFC clock sequence. - * Default: An internally maintained clockseq is used. - */ - clockseq?: number + v2(options?: UUIDOptions): string; + v2(options?: UUIDOptions, buffer?: number[], offset?: number): number[]; + v2(options?: UUIDOptions, buffer?: Buffer, offset?: number): Buffer; - /** - * (Number | Date) Time in milliseconds since unix Epoch. - * Default: The current time is used. - */ - msecs?: number|Date + v3(options?: UUIDOptions): string; + v3(options?: UUIDOptions, buffer?: number[], offset?: number): number[]; + v3(options?: UUIDOptions, buffer?: Buffer, offset?: number): Buffer; - /** - * (Number between 0-9999) additional time, in 100-nanosecond units. Ignored if msecs is unspecified. - * Default: internal uuid counter is used, as per 4.2.1.2. - */ - nsecs?: number -} + v4(options?: UUIDOptions): string; + v4(options?: UUIDOptions, buffer?: number[], offset?: number): number[]; + v4(options?: UUIDOptions, buffer?: Buffer, offset?: number): Buffer; -interface UUID { - v1(options?: UUIDOptions): string - v1(options?: UUIDOptions, buffer?: number[], offset?: number): number[] - v1(options?: UUIDOptions, buffer?: Buffer, offset?: number): Buffer + parse(id: string, buffer?: number[], offset?: number): number[]; + parse(id: string, buffer?: Buffer, offset?: number): Buffer; - v2(options?: UUIDOptions): string - v2(options?: UUIDOptions, buffer?: number[], offset?: number): number[] - v2(options?: UUIDOptions, buffer?: Buffer, offset?: number): Buffer - - v3(options?: UUIDOptions): string - v3(options?: UUIDOptions, buffer?: number[], offset?: number): number[] - v3(options?: UUIDOptions, buffer?: Buffer, offset?: number): Buffer - - v4(options?: UUIDOptions): string - v4(options?: UUIDOptions, buffer?: number[], offset?: number): number[] - v4(options?: UUIDOptions, buffer?: Buffer, offset?: number): Buffer - - parse(id: string, buffer?: number[], offset?: number): number[] - parse(id: string, buffer?: Buffer, offset?: number): Buffer - - unparse(buffer: number[], offset?: number): string - unparse(buffer: Buffer, offset?: number): string -} - -declare var uuid: UUID; - -declare module "node-uuid" { - export = uuid; + unparse(buffer: number[], offset?: number): string; + unparse(buffer: Buffer, offset?: number): string; + } } From c054c8add7865fc75b4a853f9d85344e284b5540 Mon Sep 17 00:00:00 2001 From: Alexandru Ciuca Date: Mon, 28 Sep 2015 17:53:00 +0300 Subject: [PATCH 07/26] Removed node-specific test in browser env. --- node-uuid/node-uuid-cjs-tests.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/node-uuid/node-uuid-cjs-tests.ts b/node-uuid/node-uuid-cjs-tests.ts index e2d1d57d7..197e4b384 100644 --- a/node-uuid/node-uuid-cjs-tests.ts +++ b/node-uuid/node-uuid-cjs-tests.ts @@ -27,10 +27,3 @@ var uid21: number[] = nodeUuid.v1(options, padding, offset); var uid22: number[] = nodeUuid.v2(options, padding, offset); var uid23: number[] = nodeUuid.v3(options, padding, offset); var uid24: number[] = nodeUuid.v4(options, padding, offset); - -var buffer: Buffer; - -var uid31: Buffer = nodeUuid.v1(options, buffer, offset); -var uid32: Buffer = nodeUuid.v2(options, buffer, offset); -var uid33: Buffer = nodeUuid.v3(options, buffer, offset); -var uid34: Buffer = nodeUuid.v4(options, buffer, offset); From 3de2726e83e2995643b2907359a092408172fa30 Mon Sep 17 00:00:00 2001 From: Alexandru Ciuca Date: Mon, 28 Sep 2015 17:54:52 +0300 Subject: [PATCH 08/26] Added headers to new files --- node-uuid/node-uuid-cjs.d.ts | 5 +++++ node-uuid/node-uuid-global.d.ts | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/node-uuid/node-uuid-cjs.d.ts b/node-uuid/node-uuid-cjs.d.ts index abbee3eaf..1c765abd7 100644 --- a/node-uuid/node-uuid-cjs.d.ts +++ b/node-uuid/node-uuid-cjs.d.ts @@ -1,3 +1,8 @@ +// Type definitions for node-uuid.js +// Project: https://github.com/broofa/node-uuid +// Definitions by: Jeff May +// Definitions: https://github.com/borisyankov/DefinitelyTyped + /// /** diff --git a/node-uuid/node-uuid-global.d.ts b/node-uuid/node-uuid-global.d.ts index d70d9e120..908f01dc9 100644 --- a/node-uuid/node-uuid-global.d.ts +++ b/node-uuid/node-uuid-global.d.ts @@ -1,3 +1,8 @@ +// Type definitions for node-uuid.js +// Project: https://github.com/broofa/node-uuid +// Definitions by: Jeff May +// Definitions: https://github.com/borisyankov/DefinitelyTyped + /// /** Expose as global variable */ From d9693db3e468f90edfe45d6fc5c3d1a2b8d68981 Mon Sep 17 00:00:00 2001 From: Blake Doss Date: Sat, 3 Oct 2015 10:29:27 -0400 Subject: [PATCH 09/26] Added duplicateQueryParameters method from docs. --- urijs/URIjs-tests.ts | 7 ++++++- urijs/URIjs.d.ts | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/urijs/URIjs-tests.ts b/urijs/URIjs-tests.ts index 3501a6efc..0f529fe4a 100644 --- a/urijs/URIjs-tests.ts +++ b/urijs/URIjs-tests.ts @@ -37,4 +37,9 @@ var uri: uri.URI = $('a').uri(); URI('http://example.org/foo/hello.html').segment('bar'); URI('http://example.org/foo/hello.html').segment(0, 'bar'); -URI('http://example.org/foo/hello.html').segment(['foo', 'bar', 'foobar.html']); \ No newline at end of file +URI('http://example.org/foo/hello.html').segment(['foo', 'bar', 'foobar.html']); + +var withDuplicates = URI("?bar=1&bar=1") + .duplicateQueryParameters(true) + .normalizeQuery() + .toString(); \ No newline at end of file diff --git a/urijs/URIjs.d.ts b/urijs/URIjs.d.ts index a41e06cbf..3bd4ba366 100644 --- a/urijs/URIjs.d.ts +++ b/urijs/URIjs.d.ts @@ -27,6 +27,8 @@ declare module uri { domain(): string; domain(domain: boolean): string; domain(domain: string): URI; + + duplicateQueryParameters(val: boolean): URI; equals(): boolean; equals(url: string): boolean; From 6bec6b3ebe1eb1f45cacb8782af2ef71a897dba8 Mon Sep 17 00:00:00 2001 From: Stephen Lautier Date: Tue, 6 Oct 2015 00:55:07 +0200 Subject: [PATCH 10/26] gulp-sass add more methods - logError - sync --- gulp-sass/gulp-sass-tests.ts | 1 + gulp-sass/gulp-sass.d.ts | 2 ++ 2 files changed, 3 insertions(+) diff --git a/gulp-sass/gulp-sass-tests.ts b/gulp-sass/gulp-sass-tests.ts index 429df6572..b1aeef4b4 100644 --- a/gulp-sass/gulp-sass-tests.ts +++ b/gulp-sass/gulp-sass-tests.ts @@ -12,5 +12,6 @@ gulp.task('sass', function () { gulp.task('sass', function () { gulp.src('./scss/*.scss') .pipe(sass({errLogToConsole: true})) + .pipe(sass.sync()) .pipe(gulp.dest('./css')); }); \ No newline at end of file diff --git a/gulp-sass/gulp-sass.d.ts b/gulp-sass/gulp-sass.d.ts index 781df0af7..b133461dc 100644 --- a/gulp-sass/gulp-sass.d.ts +++ b/gulp-sass/gulp-sass.d.ts @@ -45,6 +45,8 @@ declare module "gulp-sass" { interface Sass { (opts?: Options): NodeJS.ReadWriteStream; + logError(error?: string): void; + sync(options?: Options): NodeJS.ReadWriteStream; } var _tmp: Sass; From f24949bde75706196f842b0a30d3cc969dbe703a Mon Sep 17 00:00:00 2001 From: Clayton Lautier Date: Tue, 6 Oct 2015 02:23:38 +0200 Subject: [PATCH 11/26] switchery: Improvements - Added missing option: jackSecondaryColor - Added instance methods - Added module export as default --- switchery/switchery-tests.ts | 63 +++++++++++++++++++++------------- switchery/switchery.d.ts | 65 ++++++++++++++++++++++++++---------- 2 files changed, 87 insertions(+), 41 deletions(-) diff --git a/switchery/switchery-tests.ts b/switchery/switchery-tests.ts index 2a0679502..35bd77920 100644 --- a/switchery/switchery-tests.ts +++ b/switchery/switchery-tests.ts @@ -3,69 +3,86 @@ // // Examples from https://github.com/abpetkov/switchery // +import {default as Switchery} from "switchery"; function multipleSwitches() { - var elems = Array.prototype.slice.call( document.querySelectorAll( '.js-switch' ) ); + var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch')); - elems.forEach( (html: Element) => { - var switchery = new Switchery( html ); - } ); + elems.forEach((html: Element) => { + var switchery = new Switchery(html); + }); } function disabledSwitch() { - var elem = document.querySelector( '.js-switch' ) + var elem = document.querySelector('.js-switch') //inactive switch - var switchery = new Switchery( elem, {disabled: true} ); + var switchery = new Switchery(elem, { disabled: true }); //Customize the default opacity of the disabled switch, using the disabledOpacity option. - switchery = new Switchery( elem, {disabled: true, disabledOpacity: 0.75} ); + switchery = new Switchery(elem, { disabled: true, disabledOpacity: 0.75 }); } function coloredSwitch() { - var elem = document.querySelector( '.js-switch' ) + var elem = document.querySelector('.js-switch') //You can change the primary color of the switch to fit your design perfectly: - var switchery = new Switchery( elem, {color: '#41b7f1'} ); + var switchery = new Switchery(elem, { color: '#41b7f1' }); //Or the secondary color, which will change the switch background color and border color: - switchery = new Switchery( elem, {secondaryColor: '#bbf0f0'} ); + switchery = new Switchery(elem, { secondaryColor: '#bbf0f0' }); //Since version 0.6.3, you're even allowed to change the jack color from JS, as follows: - switchery = new Switchery( elem, {jackColor: '#fffc00'} ); + switchery = new Switchery(elem, { jackColor: '#fffc00', jackSecondaryColor: '#41b7f1' }); } function switchSizes() { - var elem = document.querySelector( '.js-switch' ) + var elem = document.querySelector('.js-switch') - var switchery = new Switchery( elem, {size: 'small'} ); - switchery = new Switchery( elem, {size: 'large'} ); + var switchery = new Switchery(elem, { size: 'small' }); + switchery = new Switchery(elem, { size: 'large' }); } function checkingState() { - var elem = document.querySelector( '.js-switch' ) + var elem = document.querySelector('.js-switch') //On click: - var clickCheckbox = document.querySelector( '.js-check-click' ) - var clickButton = document.querySelector( '.js-check-click-button' ); + var clickCheckbox = document.querySelector('.js-check-click') + var clickButton = document.querySelector('.js-check-click-button'); - clickButton.addEventListener( 'click', () => { - alert( clickCheckbox.checked ); - } ); + clickButton.addEventListener('click', () => { + alert(clickCheckbox.checked); + }); //On change: - var changeCheckbox = document.querySelector( '.js-check-change' ); + var changeCheckbox = document.querySelector('.js-check-change'); - changeCheckbox.onchange = function () { - alert( changeCheckbox.checked ); + changeCheckbox.onchange = function() { + alert(changeCheckbox.checked); }; +} + +function detached() { + var elem = document.querySelector('.js-switch') + var switchery = new Switchery(elem, { size: 'small' }); + + switchery.destroy(); +} + +function toggleState() { + var elem = document.querySelector('.js-switch') + var switchery = new Switchery(elem, { size: 'small' }); + var isDisabled = switchery.isDisabled(); + + switchery.enable(); + switchery.disable(); } \ No newline at end of file diff --git a/switchery/switchery.d.ts b/switchery/switchery.d.ts index 4d953aff8..79934c776 100644 --- a/switchery/switchery.d.ts +++ b/switchery/switchery.d.ts @@ -1,64 +1,93 @@ -// Type definitions for switchery 0.7.0 +// Type definitions for switchery 0.8.1 // Project: https://github.com/abpetkov/switchery -// Definitions by: Bruno Grieder +// Definitions by: Bruno Grieder , Clayton Lautier // Definitions: https://github.com/borisyankov/DefinitelyTyped declare module Switchery { - export interface Options { + interface SwitcheryStatic { + new (node: Node, options?: Options): Switchery; + } + + interface Options { /** * color of the switch element (HEX or RGB value) * @default '#64bd63' */ - color? : string; + color?: string; /** * secondary color for background color and border, when the switch is off * @default '#dfdfdf' */ - secondaryColor? : string; + secondaryColor?: string; /** * color of the jack/handle element * @default '#fff' */ - jackColor? : string; + jackColor?: string; + /** + * color of unchecked jack/handle element + * @default 'null' + */ + jackSecondaryColor?: string; /** * class name for the switch element (by default styled in switchery.css) * @default 'switchery' */ - className? : string; + className?: string; /** * enable or disable click events and changing the state of the switch (boolean value) * @default false */ - disabled? : boolean; + disabled?: boolean; /** * opacity of the switch when it's disabled (0 to 1) * @default 0.5 */ - disabledOpacity? : number; + disabledOpacity?: number; /** * length of time that the transition will take, ex. '0.4s', '1s', '2.2s' (Note: transition speed of the handle is twice shorter) - * @default '0.4s' + * @default '0.1s' */ - speed? : string; + speed?: string; /** * size of the switch element (small or large) * @default 'default' */ - size? : string; + size?: string; } - - } -declare class Switchery { +interface Switchery { - constructor(node: Node, options?: Switchery.Options); + /** + * Unbinding all event handlers attached to the switch element to prepare the object for garbage collection. + * @returns {void} + */ + destroy(): void; + /** + * Enable disabled switch by re-adding event handlers and changing the opacity to 1. + * @returns {void} + */ + enable(): void; + + /** + * Disable switch by unbinding attached events and changing opacity to disabledOpacity value + * @returns {void} + */ + disable(): void; + + /** + * Check if switch is currently disabled by checking the readonly and disabled attributes on the checkbox and the disabled option set via JS. + * If any of those are present, the returned value is true. + * @returns {boolean} whether it's disabled or not. + */ + isDisabled(): boolean; } declare module "switchery" { - - export = Switchery + var switchery: Switchery.SwitcheryStatic; + export default switchery; } \ No newline at end of file From d5a8570c0be9ce200062f730a11f9db8e905be58 Mon Sep 17 00:00:00 2001 From: Egist Li Date: Tue, 6 Oct 2015 18:31:37 +0800 Subject: [PATCH 12/26] Change Parse.Promise to be a class Also update is, error, as and when method to be static method with corresponding arguments. --- parse/parse-tests.ts | 13 +++++++++++++ parse/parse.d.ts | 12 ++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/parse/parse-tests.ts b/parse/parse-tests.ts index d373c064d..d3af6be5c 100644 --- a/parse/parse-tests.ts +++ b/parse/parse-tests.ts @@ -400,3 +400,16 @@ function test_view() { var model = Parse.User.current(); var view = new Parse.View(); } + +function test_promise() { + let resolved = Parse.Promise.as(true); + let rejected = Parse.Promise.error("an error object"); + Parse.Promise.when([resolved, rejected]).then(function() { + // success + }, function() { + // failed + }); + + // can check whether an object is a Parse.Promise object or not + Parse.Promise.is(resolved); +} diff --git a/parse/parse.d.ts b/parse/parse.d.ts index 85d3682f5..2455c56b8 100644 --- a/parse/parse.d.ts +++ b/parse/parse.d.ts @@ -72,14 +72,16 @@ declare namespace Parse { then(resolvedCallback: (value: T) => U, rejectedCallback?: (reason: any) => U): IPromise; } - interface Promise { + class Promise { + + static as(resolvedValue: any): Promise; + static error(error: any): Promise; + static is(possiblePromise: any): Boolean; + static when(promises: Promise[]): Promise; always(callback: Function): Promise; - as(): Promise; done(callback: Function): Promise; - error(): Promise; fail(callback: Function): Promise; - is(): Promise; reject(error: any): void; resolve(result: any): void; then(resolvedCallback: (value: T) => Promise, @@ -88,8 +90,6 @@ declare namespace Parse { rejectedCallback?: (reason: any) => IPromise): IPromise; then(resolvedCallback: (value: T) => U, rejectedCallback?: (reason: any) => U): IPromise; - - when(promises: Promise[]): Promise; } interface IBaseObject { From 994fdb216a01a77aa1294298060c24bb6dd15d14 Mon Sep 17 00:00:00 2001 From: Neil Culver Date: Tue, 6 Oct 2015 14:48:17 +0100 Subject: [PATCH 13/26] Support for custom functions when using no implicit any. --- knockout/knockout.d.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/knockout/knockout.d.ts b/knockout/knockout.d.ts index 94964950c..bdb52738c 100644 --- a/knockout/knockout.d.ts +++ b/knockout/knockout.d.ts @@ -5,13 +5,18 @@ interface KnockoutSubscribableFunctions { + [key: string]: KnockoutBindingHandler; + notifySubscribers(valueToWrite?: T, event?: string): void; } interface KnockoutComputedFunctions { + [key: string]: KnockoutBindingHandler; } interface KnockoutObservableFunctions { + [key: string]: KnockoutBindingHandler; + equalityComparer(a: any, b: any): boolean; } @@ -30,6 +35,8 @@ interface KnockoutObservableArrayFunctions { sort(compareFunction: (left: T, right: T) => number): void; // Ko specific + [key: string]: KnockoutBindingHandler; + replace(oldItem: T, newItem: T): void; remove(item: T): T[]; From b1223bd7e2f6e3a417a8ed4e5490e3bfb000e55e Mon Sep 17 00:00:00 2001 From: vvakame Date: Wed, 7 Oct 2015 02:42:50 +0900 Subject: [PATCH 14/26] fix ui-router-extras/ui-router-extras.d.ts --- ui-router-extras/ui-router-extras.d.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ui-router-extras/ui-router-extras.d.ts b/ui-router-extras/ui-router-extras.d.ts index df0d0aa3e..1fc5846c8 100644 --- a/ui-router-extras/ui-router-extras.d.ts +++ b/ui-router-extras/ui-router-extras.d.ts @@ -21,7 +21,7 @@ declare module angular.ui { /* * This method resets stored $deepStateRedirect data so following transitions will behave like there have not been previous transitions. * @param stateParams Can be passed in to select specific states to reset: - * { + * { * 'paramName': 'paramvalue' | ['list', 'of', 'possible', 'paramvalues'] * } */ @@ -33,13 +33,13 @@ declare module angular.ui { */ interface IDeepStateRedirectConfig { /* - * If no deep state has been recorded, DSR will instead redirect to the default substate and params that you specify. + * If no deep state has been recorded, DSR will instead redirect to the default substate and params that you specify. * If default is a string it is interpreted as the substate. */ default?: string | IRedirectParams; /* * Specify params: true if your DSR state takes parameters. - * If only a subset of the parameters should be included in the parameter grouping for recording deep states, + * If only a subset of the parameters should be included in the parameter grouping for recording deep states, * specify an array of parameter names. */ params?: boolean | string[]; @@ -58,8 +58,8 @@ declare module angular.ui { /* * Previous state */ - interface IPreviousState { - state: IState; + interface IPreviousState { + state: IState; params?: ui.IStateParamsService; } @@ -96,7 +96,7 @@ declare module angular.ui { * @param memoName Memo name */ forget(memoName: string): void; - } + } /** * Sticky state @@ -128,7 +128,7 @@ declare module angular.ui { /* * Note: named views are mandatory when using sticky states! */ - views?: {}; + views?: { [name:string]: angular.ui.IState }; } From 7810c2ff7872e9d27d40adc4d90f762ef30e2410 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Bourgeois?= Date: Tue, 6 Oct 2015 21:40:26 +0200 Subject: [PATCH 15/26] Changed basic-auth declarations to be compatible with ES6 style imports --- basic-auth/basic-auth.d.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/basic-auth/basic-auth.d.ts b/basic-auth/basic-auth.d.ts index e03998997..e25f217e4 100644 --- a/basic-auth/basic-auth.d.ts +++ b/basic-auth/basic-auth.d.ts @@ -5,15 +5,15 @@ /// -declare module BasicAuth { - export interface BasicAuthResult { - name:string; - pass:string; - } -} - declare module "basic-auth" { - function auth(req: Express.Request): BasicAuth.BasicAuthResult; + function auth(req: Express.Request): auth.BasicAuthResult; + + namespace auth { + interface BasicAuthResult { + name: string; + pass: string; + } + } export = auth; } From c321c3c9021950fdb16d1838bf07d421e8910f26 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Tue, 6 Oct 2015 13:05:18 -0700 Subject: [PATCH 16/26] angular2-2.0.0-alpha.39 --- angular2/angular2-2.0.0-alpha.39.d.ts | 17105 ++++++++++++++++++++++++ angular2/angular2.d.ts | 127 +- angular2/http-2.0.0-alpha.39.d.ts | 1310 ++ angular2/http.d.ts | 4 +- angular2/router-2.0.0-alpha.39.d.ts | 1330 ++ angular2/router.d.ts | 12 +- angular2/test_lib-2.0.0-alpha.39.d.ts | 408 + angular2/test_lib.d.ts | 2 +- 8 files changed, 20225 insertions(+), 73 deletions(-) create mode 100644 angular2/angular2-2.0.0-alpha.39.d.ts create mode 100644 angular2/http-2.0.0-alpha.39.d.ts create mode 100644 angular2/router-2.0.0-alpha.39.d.ts create mode 100644 angular2/test_lib-2.0.0-alpha.39.d.ts diff --git a/angular2/angular2-2.0.0-alpha.39.d.ts b/angular2/angular2-2.0.0-alpha.39.d.ts new file mode 100644 index 000000000..616157aaf --- /dev/null +++ b/angular2/angular2-2.0.0-alpha.39.d.ts @@ -0,0 +1,17105 @@ +// Type definitions for Angular v2.0.0-39 +// Project: http://angular.io/ +// Definitions by: angular team +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +// *********************************************************** +// This file is generated by the Angular build process. +// Please do not create manual edits or send pull requests +// modifying this file. +// *********************************************************** + +// angular2/angular2 depends transitively on these libraries. +// If you don't have them installed you can install them using TSD +// https://github.com/DefinitelyTyped/tsd + +/// +// angular2/web_worker/worker depends transitively on these libraries. +// If you don't have them installed you can install them using TSD +// https://github.com/DefinitelyTyped/tsd + +/// +// angular2/web_worker/ui depends transitively on these libraries. +// If you don't have them installed you can install them using TSD +// https://github.com/DefinitelyTyped/tsd + +/// + + +interface Map {} + + +declare module ng { + // See https://github.com/Microsoft/TypeScript/issues/1168 + class BaseException /* extends Error */ { + message: string; + stack: string; + toString(): string; + } + interface InjectableReference {} +} + +declare module ngWorker { + // See https://github.com/Microsoft/TypeScript/issues/1168 + class BaseException /* extends Error */ { + message: string; + stack: string; + toString(): string; + } + interface InjectableReference {} +} + +declare module ngUi { + // See https://github.com/Microsoft/TypeScript/issues/1168 + class BaseException /* extends Error */ { + message: string; + stack: string; + toString(): string; + } + interface InjectableReference {} +} + + + + +declare module ng { + /** + * Declares an injectable parameter to be a live list of directives or variable + * bindings from the content children of a directive. + * + * ### Example ([live demo](http://plnkr.co/edit/lY9m8HLy7z06vDoUaSN2?p=preview)) + * + * Assume that `` component would like to get a list its children `` + * components as shown in this example: + * + * ```html + * + * ... + * {{o.text}} + * + * ``` + * + * The preferred solution is to query for `Pane` directives using this decorator. + * + * ```javascript + * @Component({ + * selector: 'pane', + * inputs: ['title'] + * }) + * @View(...) + * class Pane { + * title:string; + * } + * + * @Component({ + * selector: 'tabs' + * }) + * @View({ + * template: ` + *

+ * + * ` + * }) + * class Tabs { + * panes: QueryList; + * constructor(@Query(Pane) panes:QueryList) { + * this.panes = panes; + * } + * } + * ``` + * + * A query can look for variable bindings by passing in a string with desired binding symbol. + * + * ### Example ([live demo](http://plnkr.co/edit/sT2j25cH1dURAyBRCKx1?p=preview)) + * ```html + * + *
...
+ *
+ * + * @Component({ + * selector: 'foo' + * }) + * @View(...) + * class seeker { + * constructor(@Query('findme') elList: QueryList) {...} + * } + * ``` + * + * In this case the object that is injected depend on the type of the variable + * binding. It can be an ElementRef, a directive or a component. + * + * Passing in a comma separated list of variable bindings will query for all of them. + * + * ```html + * + *
...
+ *
...
+ *
+ * + * @Component({ + * selector: 'foo' + * }) + * @View(...) + * class Seeker { + * constructor(@Query('findMe, findMeToo') elList: QueryList) {...} + * } + * ``` + * + * Configure whether query looks for direct children or all descendants + * of the querying element, by using the `descendants` parameter. + * It is set to `false` by default. + * + * ### Example ([live demo](http://plnkr.co/edit/wtGeB977bv7qvA5FTYl9?p=preview)) + * ```html + * + * a + * b + * + * c + * + * + * ``` + * + * When querying for items, the first container will see only `a` and `b` by default, + * but with `Query(TextDirective, {descendants: true})` it will see `c` too. + * + * The queried directives are kept in a depth-first pre-order with respect to their + * positions in the DOM. + * + * Query does not look deep into any subcomponent views. + * + * Query is updated as part of the change-detection cycle. Since change detection + * happens after construction of a directive, QueryList will always be empty when observed in the + * constructor. + * + * The injected object is an unmodifiable live list. + * See {@link QueryList} for more details. + */ + class QueryMetadata extends DependencyMetadata { + + constructor(_selector: Type | string, {descendants, first}?: {descendants?: boolean, first?: boolean}); + + /** + * whether we want to query only direct children (false) or all + * children (true). + */ + descendants: boolean; + + first: boolean; + + /** + * always `false` to differentiate it with {@link ViewQueryMetadata}. + */ + isViewQuery: boolean; + + /** + * what this is querying for. + */ + selector: any; + + /** + * whether this is querying for a variable binding or a directive. + */ + isVarBindingQuery: boolean; + + /** + * returns a list of variable bindings this is querying for. + * Only applicable if this is a variable bindings query. + */ + varBindings: string[]; + + toString(): string; + + } + + + /** + * Configures a content query. + * + * Content queries are set before the `afterContentInit` callback is called. + * + * ### Example + * + * ``` + * @Directive({ + * selector: 'someDir' + * }) + * class SomeDir { + * @ContentChildren(ChildDirective) contentChildren: QueryList; + * + * afterContentInit() { + * // contentChildren is set + * } + * } + * ``` + */ + class ContentChildrenMetadata extends QueryMetadata { + + constructor(_selector: Type | string, {descendants}?: {descendants?: boolean}); + + } + + + /** + * Configures a content query. + * + * Content queries are set before the `afterContentInit` callback is called. + * + * ### Example + * + * ``` + * @Directive({ + * selector: 'someDir' + * }) + * class SomeDir { + * @ContentChild(ChildDirective) contentChild; + * + * afterContentInit() { + * // contentChild is set + * } + * } + * ``` + */ + class ContentChildMetadata extends QueryMetadata { + + constructor(_selector: Type | string); + + } + + + /** + * Configures a view query. + * + * View queries are set before the `afterViewInit` callback is called. + * + * ### Example + * + * ``` + * @Component({ + * selector: 'someDir' + * }) + * @View({templateUrl: 'someTemplate', directives: [ItemDirective]}) + * class SomeDir { + * @ViewChildren(ItemDirective) viewChildren: QueryList; + * + * afterViewInit() { + * // viewChildren is set + * } + * } + * ``` + */ + class ViewChildrenMetadata extends ViewQueryMetadata { + + constructor(_selector: Type | string); + + } + + + /** + * Similar to {@link QueryMetadata}, but querying the component view, instead of + * the content children. + * + * ### Example ([live demo](http://plnkr.co/edit/eNsFHDf7YjyM6IzKxM1j?p=preview)) + * + * ```javascript + * @Component({...}) + * @View({ + * template: ` + * a + * b + * c + * ` + * }) + * class MyComponent { + * shown: boolean; + * + * constructor(private @Query(Item) items:QueryList) { + * items.onChange(() => console.log(items.length)); + * } + * } + * ``` + * + * Supports the same querying parameters as {@link QueryMetadata}, except + * `descendants`. This always queries the whole view. + * + * As `shown` is flipped between true and false, items will contain zero of one + * items. + * + * Specifies that a {@link QueryList} should be injected. + * + * The injected object is an iterable and observable live list. + * See {@link QueryList} for more details. + */ + class ViewQueryMetadata extends QueryMetadata { + + constructor(_selector: Type | string, {descendants, first}?: {descendants?: boolean, first?: boolean}); + + /** + * always `true` to differentiate it with {@link QueryMetadata}. + */ + isViewQuery: any; + + toString(): string; + + } + + + /** + * Configures a view query. + * + * View queries are set before the `afterViewInit` callback is called. + * + * ### Example + * + * ``` + * @Component({ + * selector: 'someDir' + * }) + * @View({templateUrl: 'someTemplate', directives: [ItemDirective]}) + * class SomeDir { + * @ViewChild(ItemDirective) viewChild:ItemDirective; + * + * afterViewInit() { + * // viewChild is set + * } + * } + * ``` + */ + class ViewChildMetadata extends ViewQueryMetadata { + + constructor(_selector: Type | string); + + } + + + /** + * Specifies that a constant attribute value should be injected. + * + * The directive can inject constant string literals of host element attributes. + * + * ## Example + * + * Suppose we have an `` element and want to know its `type`. + * + * ```html + * + * ``` + * + * A decorator can inject string literal `text` like so: + * + * ```javascript + * @Directive({ + * selector: `input' + * }) + * class InputDirective { + * constructor(@Attribute('type') type) { + * // type would be `text` in this example + * } + * } + * ``` + */ + class AttributeMetadata extends DependencyMetadata { + + constructor(attributeName: string); + + attributeName: string; + + token: any; + + toString(): string; + + } + + + /** + * Declare reusable UI building blocks for an application. + * + * Each Angular component requires a single `@Component` and at least one `@View` annotation. The + * `@Component` + * annotation specifies when a component is instantiated, and which properties and hostListeners it + * binds to. + * + * When a component is instantiated, Angular + * - creates a shadow DOM for the component. + * - loads the selected template into the shadow DOM. + * - creates all the injectable objects configured with `bindings` and `viewBindings`. + * + * All template expressions and statements are then evaluated against the component instance. + * + * For details on the `@View` annotation, see {@link ViewMetadata}. + * + * ## Lifecycle hooks + * + * When the component class implements some {@link angular2/lifecycle_hooks} the callbacks are + * called by the change detection at defined points in time during the life of the component. + * + * ## Example + * + * ``` + * @Component({ + * selector: 'greet' + * }) + * @View({ + * template: 'Hello {{name}}!' + * }) + * class Greet { + * name: string; + * + * constructor() { + * this.name = 'World'; + * } + * } + * ``` + */ + class ComponentMetadata extends DirectiveMetadata { + + constructor({selector, inputs, outputs, properties, events, host, exportAs, moduleId, bindings, + viewBindings, changeDetection, queries}?: { + selector?: string, + inputs?: string[], + outputs?: string[], + properties?: string[], + events?: string[], + host?: {[key: string]: string}, + bindings?: any[], + exportAs?: string, + moduleId?: string, + viewBindings?: any[], + queries?: {[key: string]: any}, + changeDetection?: ChangeDetectionStrategy, + }); + + /** + * Defines the used change detection strategy. + * + * When a component is instantiated, Angular creates a change detector, which is responsible for + * propagating the component's bindings. + * + * The `changeDetection` property defines, whether the change detection will be checked every time + * or only when the component tells it to do so. + */ + changeDetection: ChangeDetectionStrategy; + + /** + * Defines the set of injectable objects that are visible to its view DOM children. + * + * ## Simple Example + * + * Here is an example of a class that can be injected: + * + * ``` + * class Greeter { + * greet(name:string) { + * return 'Hello ' + name + '!'; + * } + * } + * + * @Directive({ + * selector: 'needs-greeter' + * }) + * class NeedsGreeter { + * greeter:Greeter; + * + * constructor(greeter:Greeter) { + * this.greeter = greeter; + * } + * } + * + * @Component({ + * selector: 'greet', + * viewBindings: [ + * Greeter + * ] + * }) + * @View({ + * template: ``, + * directives: [NeedsGreeter] + * }) + * class HelloWorld { + * } + * + * ``` + */ + viewBindings: any[]; + + } + + + /** + * Directives allow you to attach behavior to elements in the DOM. + * + * {@link DirectiveMetadata}s with an embedded view are called {@link ComponentMetadata}s. + * + * A directive consists of a single directive annotation and a controller class. When the + * directive's `selector` matches + * elements in the DOM, the following steps occur: + * + * 1. For each directive, the `ElementInjector` attempts to resolve the directive's constructor + * arguments. + * 2. Angular instantiates directives for each matched element using `ElementInjector` in a + * depth-first order, + * as declared in the HTML. + * + * ## Understanding How Injection Works + * + * There are three stages of injection resolution. + * - *Pre-existing Injectors*: + * - The terminal {@link Injector} cannot resolve dependencies. It either throws an error or, if + * the dependency was + * specified as `@Optional`, returns `null`. + * - The platform injector resolves browser singleton resources, such as: cookies, title, + * location, and others. + * - *Component Injectors*: Each component instance has its own {@link Injector}, and they follow + * the same parent-child hierarchy + * as the component instances in the DOM. + * - *Element Injectors*: Each component instance has a Shadow DOM. Within the Shadow DOM each + * element has an `ElementInjector` + * which follow the same parent-child hierarchy as the DOM elements themselves. + * + * When a template is instantiated, it also must instantiate the corresponding directives in a + * depth-first order. The + * current `ElementInjector` resolves the constructor dependencies for each directive. + * + * Angular then resolves dependencies as follows, according to the order in which they appear in the + * {@link ViewMetadata}: + * + * 1. Dependencies on the current element + * 2. Dependencies on element injectors and their parents until it encounters a Shadow DOM boundary + * 3. Dependencies on component injectors and their parents until it encounters the root component + * 4. Dependencies on pre-existing injectors + * + * + * The `ElementInjector` can inject other directives, element-specific special objects, or it can + * delegate to the parent + * injector. + * + * To inject other directives, declare the constructor parameter as: + * - `directive:DirectiveType`: a directive on the current element only + * - `@Host() directive:DirectiveType`: any directive that matches the type between the current + * element and the + * Shadow DOM root. + * - `@Query(DirectiveType) query:QueryList`: A live collection of direct child + * directives. + * - `@QueryDescendants(DirectiveType) query:QueryList`: A live collection of any + * child directives. + * + * To inject element-specific special objects, declare the constructor parameter as: + * - `element: ElementRef` to obtain a reference to logical element in the view. + * - `viewContainer: ViewContainerRef` to control child template instantiation, for + * {@link DirectiveMetadata} directives only + * - `bindingPropagation: BindingPropagation` to control change detection in a more granular way. + * + * ## Example + * + * The following example demonstrates how dependency injection resolves constructor arguments in + * practice. + * + * + * Assume this HTML template: + * + * ``` + *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ * ``` + * + * With the following `dependency` decorator and `SomeService` injectable class. + * + * ``` + * @Injectable() + * class SomeService { + * } + * + * @Directive({ + * selector: '[dependency]', + * inputs: [ + * 'id: dependency' + * ] + * }) + * class Dependency { + * id:string; + * } + * ``` + * + * Let's step through the different ways in which `MyDirective` could be declared... + * + * + * ### No injection + * + * Here the constructor is declared with no arguments, therefore nothing is injected into + * `MyDirective`. + * + * ``` + * @Directive({ selector: '[my-directive]' }) + * class MyDirective { + * constructor() { + * } + * } + * ``` + * + * This directive would be instantiated with no dependencies. + * + * + * ### Component-level injection + * + * Directives can inject any injectable instance from the closest component injector or any of its + * parents. + * + * Here, the constructor declares a parameter, `someService`, and injects the `SomeService` type + * from the parent + * component's injector. + * ``` + * @Directive({ selector: '[my-directive]' }) + * class MyDirective { + * constructor(someService: SomeService) { + * } + * } + * ``` + * + * This directive would be instantiated with a dependency on `SomeService`. + * + * + * ### Injecting a directive from the current element + * + * Directives can inject other directives declared on the current element. + * + * ``` + * @Directive({ selector: '[my-directive]' }) + * class MyDirective { + * constructor(dependency: Dependency) { + * expect(dependency.id).toEqual(3); + * } + * } + * ``` + * This directive would be instantiated with `Dependency` declared at the same element, in this case + * `dependency="3"`. + * + * ### Injecting a directive from any ancestor elements + * + * Directives can inject other directives declared on any ancestor element (in the current Shadow + * DOM), i.e. on the current element, the + * parent element, or its parents. + * ``` + * @Directive({ selector: '[my-directive]' }) + * class MyDirective { + * constructor(@Host() dependency: Dependency) { + * expect(dependency.id).toEqual(2); + * } + * } + * ``` + * + * `@Host` checks the current element, the parent, as well as its parents recursively. If + * `dependency="2"` didn't + * exist on the direct parent, this injection would + * have returned + * `dependency="1"`. + * + * + * ### Injecting a live collection of direct child directives + * + * + * A directive can also query for other child directives. Since parent directives are instantiated + * before child directives, a directive can't simply inject the list of child directives. Instead, + * the directive injects a {@link QueryList}, which updates its contents as children are added, + * removed, or moved by a directive that uses a {@link ViewContainerRef} such as a `ng-for`, an + * `ng-if`, or an `ng-switch`. + * + * ``` + * @Directive({ selector: '[my-directive]' }) + * class MyDirective { + * constructor(@Query(Dependency) dependencies:QueryList) { + * } + * } + * ``` + * + * This directive would be instantiated with a {@link QueryList} which contains `Dependency` 4 and + * 6. Here, `Dependency` 5 would not be included, because it is not a direct child. + * + * ### Injecting a live collection of descendant directives + * + * By passing the descendant flag to `@Query` above, we can include the children of the child + * elements. + * + * ``` + * @Directive({ selector: '[my-directive]' }) + * class MyDirective { + * constructor(@Query(Dependency, {descendants: true}) dependencies:QueryList) { + * } + * } + * ``` + * + * This directive would be instantiated with a Query which would contain `Dependency` 4, 5 and 6. + * + * ### Optional injection + * + * The normal behavior of directives is to return an error when a specified dependency cannot be + * resolved. If you + * would like to inject `null` on unresolved dependency instead, you can annotate that dependency + * with `@Optional()`. + * This explicitly permits the author of a template to treat some of the surrounding directives as + * optional. + * + * ``` + * @Directive({ selector: '[my-directive]' }) + * class MyDirective { + * constructor(@Optional() dependency:Dependency) { + * } + * } + * ``` + * + * This directive would be instantiated with a `Dependency` directive found on the current element. + * If none can be + * found, the injector supplies `null` instead of throwing an error. + * + * ## Example + * + * Here we use a decorator directive to simply define basic tool-tip behavior. + * + * ``` + * @Directive({ + * selector: '[tooltip]', + * inputs: [ + * 'text: tooltip' + * ], + * host: { + * '(mouseenter)': 'onMouseEnter()', + * '(mouseleave)': 'onMouseLeave()' + * } + * }) + * class Tooltip{ + * text:string; + * overlay:Overlay; // NOT YET IMPLEMENTED + * overlayManager:OverlayManager; // NOT YET IMPLEMENTED + * + * constructor(overlayManager:OverlayManager) { + * this.overlay = overlay; + * } + * + * onMouseEnter() { + * // exact signature to be determined + * this.overlay = this.overlayManager.open(text, ...); + * } + * + * onMouseLeave() { + * this.overlay.close(); + * this.overlay = null; + * } + * } + * ``` + * In our HTML template, we can then add this behavior to a `
` or any other element with the + * `tooltip` selector, + * like so: + * + * ``` + *
+ * ``` + * + * Directives can also control the instantiation, destruction, and positioning of inline template + * elements: + * + * A directive uses a {@link ViewContainerRef} to instantiate, insert, move, and destroy views at + * runtime. + * The {@link ViewContainerRef} is created as a result of `