mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 14:57:10 +00:00
Merge branch 'master' of https://github.com/DefinitelyTyped/DefinitelyTyped into jquery/promise-compatibility
This commit is contained in:
@@ -1278,6 +1278,12 @@
|
||||
"sourceRepoURL": "https://github.com/zalmoxisus/redux-devtools-extension",
|
||||
"asOfVersion": "2.13.2"
|
||||
},
|
||||
{
|
||||
"libraryName": "redux-little-router",
|
||||
"typingsPackageName": "redux-little-router",
|
||||
"sourceRepoURL": "https://github.com/FormidableLabs/redux-little-router",
|
||||
"asOfVersion": "15.1.0"
|
||||
},
|
||||
{
|
||||
"libraryName": "redux-persist",
|
||||
"typingsPackageName": "redux-persist",
|
||||
|
||||
@@ -132,9 +132,8 @@ myApp.controller('sortableController', function ($scope: MySortableControllerSco
|
||||
$scope.sortableOptions.tolerance = 'pointer';
|
||||
$scope.sortableOptions.zIndex = 9999;
|
||||
|
||||
$scope.sortableOptions['ui-floating'] = undefined;
|
||||
$scope.sortableOptions['ui-floating'] = null;
|
||||
$scope.sortableOptions['ui-floating'] = false;
|
||||
$scope.sortableOptions['ui-floating'] = true;
|
||||
$scope.sortableOptions['ui-floating'] = "auto";
|
||||
const sortableFloatingOption0: ng.ui.UISortableOptions<SortableModelInfo> = { 'ui-floating': undefined };
|
||||
const sortableFloatingOption1: ng.ui.UISortableOptions<SortableModelInfo> = { 'ui-floating': false };
|
||||
const sortableFloatingOption2: ng.ui.UISortableOptions<SortableModelInfo> = { 'ui-floating': true };
|
||||
const sortableFloatingOption3: ng.ui.UISortableOptions<SortableModelInfo> = { 'ui-floating': 'auto' };
|
||||
});
|
||||
|
||||
Vendored
+1
-1
@@ -12,7 +12,7 @@ declare module 'angular' {
|
||||
export namespace ui {
|
||||
|
||||
interface UISortableOptions<T> extends SortableOptions<T> {
|
||||
'ui-floating'?: string | boolean;
|
||||
'ui-floating'?: 'auto' | boolean;
|
||||
}
|
||||
|
||||
interface UISortableProperties<T> {
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import BloomFilter = require('bloom-filter');
|
||||
|
||||
const numElements = 3;
|
||||
const falsePositiveRate = 0.01;
|
||||
const filter = BloomFilter.create(numElements, falsePositiveRate);
|
||||
|
||||
// elements
|
||||
const a = Buffer.from('99108ad8ed9bb6274d3980bab5a85c048f0950c8', 'hex');
|
||||
const c = Buffer.from('b5a2c786d9ef4658287ced5914b37a1b4aa32eee', 'hex');
|
||||
|
||||
// insert elements
|
||||
// $ExpectType void
|
||||
filter.insert(a);
|
||||
|
||||
// $ExpectType boolean
|
||||
!filter.contains(c);
|
||||
|
||||
// reinstantiate from an object
|
||||
const serialized = filter.toObject();
|
||||
const woahFilter = new BloomFilter(serialized);
|
||||
|
||||
// initialize directly
|
||||
const newFilter = new BloomFilter({
|
||||
vData: Buffer.from('123', 'hex'), // the data of the filter
|
||||
nHashFuncs: 3, // the number of hash functions to use
|
||||
nTweak: 2147483649, // the seed used for the hash fuctions
|
||||
nFlags: 0 // flags used to update the filter when matched
|
||||
});
|
||||
Vendored
+38
@@ -0,0 +1,38 @@
|
||||
// Type definitions for bloom-filter 0.2
|
||||
// Project: https://github.com/bitpay/bloom-filter
|
||||
// Definitions by: Daniel Byrne <https://github.com/danwbyrne>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
declare class Filter {
|
||||
constructor(options: Filter.FilterOptions);
|
||||
static create(elements: number, falsePositiveRate: number, nTweak?: number, nFlags?: number): Filter;
|
||||
toObject(): Filter.FilterOptions;
|
||||
hash(nHashNum: number, vDataToHash: Buffer): number;
|
||||
insert(data: Buffer): void;
|
||||
contains(data: Buffer): boolean;
|
||||
clear(): void;
|
||||
inspect(): string;
|
||||
BLOOM_UPDATE_NONE: number;
|
||||
BLOOM_UPDATE_ALL: number;
|
||||
BLOOM_UPDATE_P2PUBKEY_ONLY: number;
|
||||
MAX_BLOOM_FILTER_SIZE: number;
|
||||
MAX_HASH_FUNCS: number;
|
||||
MIN_HASH_FUNCS: number;
|
||||
LN2SQUARED: number;
|
||||
LN2: number;
|
||||
}
|
||||
|
||||
declare namespace Filter {
|
||||
interface FilterOptions {
|
||||
vData: Buffer;
|
||||
nHashFuncs: number;
|
||||
nTweak?: number;
|
||||
nFlags?: number;
|
||||
}
|
||||
|
||||
function MurmurHash3(seed: number, data: Buffer): number;
|
||||
}
|
||||
|
||||
export = Filter;
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["es6"],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": ["../"],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"bloom-filter-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Vendored
+2
@@ -391,6 +391,8 @@ declare namespace Chart {
|
||||
easing?: string;
|
||||
onProgress?(chart: any): void;
|
||||
onComplete?(chart: any): void;
|
||||
animateRotate?: boolean;
|
||||
animateScale?: boolean;
|
||||
}
|
||||
|
||||
interface ChartElementsOptions {
|
||||
|
||||
Vendored
+2
-2
@@ -124,7 +124,7 @@ declare namespace chroma {
|
||||
* Computes the eucledian distance between two colors in a given color space (default is 'lab').
|
||||
* {@link https://en.wikipedia.org/wiki/Euclidean_distance#Three_dimensions}
|
||||
*/
|
||||
distance(color1: string | Color, color2: string | Color, colorSpace?: keyof ColorSpaces): Color;
|
||||
distance(color1: string | Color, color2: string | Color, colorSpace?: keyof ColorSpaces): number;
|
||||
|
||||
/**
|
||||
* Computes color difference {@link https://en.wikipedia.org/wiki/Color_difference#CMC_l:c_.281984.29} as
|
||||
@@ -133,7 +133,7 @@ declare namespace chroma {
|
||||
* {@link https://web.archive.org/web/20160306044036/http://www.brucelindbloom.com/javascript/ColorDiff.js}
|
||||
* The parameters L (default 1) and C (default 1) are weighting factors for lightness and chromacity.
|
||||
*/
|
||||
deltaE(color1: string | Color, color2: string | Color, L?: number, C?: number): Color;
|
||||
deltaE(color1: string | Color, color2: string | Color, L?: number, C?: number): number;
|
||||
|
||||
/**
|
||||
* chroma.brewer is an map of ColorBrewer scales that are included in chroma.js for convenience.
|
||||
|
||||
@@ -16,4 +16,5 @@ graph.transition = (selection: d3.Selection<any>) => {
|
||||
const render = new dagreD3.render();
|
||||
const svg = d3.select("svg");
|
||||
render.arrows()["arrowType"] = (parent: d3.Selection<any>, id: string, edge: dagre.Edge, type: string) => {};
|
||||
render.shapes()["shapeName"] = (parent: d3.Selection<any>, bbox: any, node: dagre.Node) => {};
|
||||
render(svg, graph);
|
||||
|
||||
Vendored
+2
@@ -11,6 +11,7 @@ export as namespace dagreD3;
|
||||
|
||||
export * from "dagre";
|
||||
export const render: { new(): Render };
|
||||
export const intersect: { [shapeName: string]: (node: dagre.Node, points: Array<{}>, point: any) => void };
|
||||
|
||||
declare module "dagre" {
|
||||
namespace graphlib {
|
||||
@@ -32,4 +33,5 @@ export interface Render {
|
||||
// see http://cpettitt.github.io/project/dagre-d3/latest/demo/user-defined.html for example usage
|
||||
arrows(): { [arrowStyleName: string]: (parent: d3.Selection<any>, id: string, edge: dagre.Edge, type: string) => void };
|
||||
(selection: d3.Selection<any>, g: dagre.graphlib.Graph): void;
|
||||
shapes(): { [shapeStyleName: string]: (parent: d3.Selection<any>, bbox: any, node: dagre.Node) => void };
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import elliptic = require('elliptic');
|
||||
|
||||
const ec = new elliptic.ec('secp256k1');
|
||||
|
||||
// Generate keys
|
||||
const key = ec.genKeyPair();
|
||||
|
||||
// Sign the message's hash (input must be an array, or a hex-string)
|
||||
const msgHash = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||
const signature = key.sign(msgHash);
|
||||
|
||||
// Export DER encoded signature in Array
|
||||
const derSign = signature.toDER();
|
||||
|
||||
// Verify signature
|
||||
console.log(key.verify(msgHash, derSign));
|
||||
|
||||
// CHECK WITH NO PRIVATE KEY
|
||||
|
||||
const pubPoint = key.getPublic();
|
||||
const x = pubPoint.getX();
|
||||
const y = pubPoint.getY();
|
||||
|
||||
// Public Key MUST be either:
|
||||
// 1) '04' + hex string of x + hex string of y; or
|
||||
// 2) object with two hex string properties (x and y); or
|
||||
// 3) object with two buffer properties (x and y)
|
||||
const pub = pubPoint.encode('hex'); // case 1
|
||||
const aPub = { x: x.toString('hex'), y: y.toString('hex') }; // case 2
|
||||
const bPub = { x: x.toBuffer(), y: y.toBuffer() }; // case 3
|
||||
const cPub = { x: x.toArrayLike(Buffer), y: y.toArrayLike(Buffer) }; // case 3
|
||||
|
||||
// Import public key
|
||||
const newKey = ec.keyFromPublic(pub, 'hex');
|
||||
|
||||
// Signature MUST be either:
|
||||
// 1) DER-encoded signature as hex-string; or
|
||||
// 2) DER-encoded signature as buffer; or
|
||||
// 3) object with two hex-string properties (r and s); or
|
||||
// 4) object with two buffer properties (r and s)
|
||||
|
||||
// const signature = '3046022100...'; // case 1
|
||||
// const signature = new Buffer('...'); // case 2
|
||||
// const signature = { r: 'b1fc...', s: '9c42...' }; // case 3
|
||||
|
||||
// Verify signature
|
||||
console.log(key.verify(msgHash, signature));
|
||||
Vendored
+158
@@ -0,0 +1,158 @@
|
||||
// Type definitions for elliptic 6.4
|
||||
// Project: https://github.com/indutny/elliptic
|
||||
// Definitions by: Daniel Byrne <https://github.com/danwbyrne>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
import BN = require('bn.js');
|
||||
|
||||
// incomplete typings
|
||||
export const utils: any;
|
||||
export const rand: any;
|
||||
export const eddsa: any;
|
||||
|
||||
export type BNInput = string | BN | number | Buffer | number[];
|
||||
|
||||
export const version: number;
|
||||
|
||||
export namespace curve {
|
||||
class BaseCurve {
|
||||
constructor(type: string, conf: BaseCurve.BaseCurveOptions)
|
||||
p: BN;
|
||||
type: string;
|
||||
red: any; // ?
|
||||
zero: any; // ?
|
||||
one: any; // ?
|
||||
two: any; // ?
|
||||
n: BN | undefined | null;
|
||||
g: any; // ?
|
||||
redN: any; // ?
|
||||
decodePoint(bytes: any, enc: string): any; // ?
|
||||
}
|
||||
|
||||
namespace BaseCurve {
|
||||
class BasePoint {
|
||||
constructor(curve: any, type: string);
|
||||
curve: any;
|
||||
type: string;
|
||||
precomputed: PrecomputedValues | null;
|
||||
encode(enc: string, compact: boolean): BN;
|
||||
encodeCompressed(enc: string): BN;
|
||||
validate(): boolean;
|
||||
precompute(power: number): BasePoint;
|
||||
dblp(k: any): any; // ?
|
||||
}
|
||||
|
||||
interface BaseCurveOptions {
|
||||
p: number | string | number[] | Buffer | BN;
|
||||
prime?: BN | string;
|
||||
n?: number | BN | Buffer;
|
||||
g?: any; // ?
|
||||
gRed?: any; // ?
|
||||
}
|
||||
|
||||
interface PrecomputedValues {
|
||||
doubles: any; // ?
|
||||
naf: any; // ?
|
||||
beta: any; // ?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export namespace curves {
|
||||
class PresetCurve {
|
||||
constructor(options: PresetCurve.Options)
|
||||
type: string;
|
||||
g: any; // ?
|
||||
n: BN | undefined | null;
|
||||
hash: any; // ?
|
||||
}
|
||||
|
||||
namespace PresetCurve {
|
||||
interface Options {
|
||||
type: string;
|
||||
prime: string | null;
|
||||
p: string;
|
||||
a: string;
|
||||
b: string;
|
||||
n: string;
|
||||
hash: any;
|
||||
gRed: boolean;
|
||||
g: any; // ?
|
||||
beta?: string;
|
||||
lambda?: string;
|
||||
basis?: any; // ?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class ec {
|
||||
constructor(options: string | curves.PresetCurve)
|
||||
curve: any;
|
||||
n: BN | undefined | null;
|
||||
nh: any;
|
||||
g: any;
|
||||
hash: any;
|
||||
|
||||
keyPair(options: ec.KeyPairOptions): ec.KeyPair;
|
||||
keyFromPrivate(priv: Buffer | ec.KeyPair, enc?: string): ec.KeyPair;
|
||||
keyFromPublic(pub: Buffer | ec.KeyPair, enc?: string): ec.KeyPair;
|
||||
genKeyPair(options?: ec.GenKeyPairOptions): ec.KeyPair;
|
||||
sign(msg: BNInput, key: Buffer | ec.KeyPair, enc: string, options?: ec.SignOptions): ec.Signature;
|
||||
sign(msg: BNInput, key: Buffer | ec.KeyPair, options?: ec.SignOptions): ec.Signature;
|
||||
verify(msg: BNInput, signature: ec.Signature | ec.SignatureOptions, key: Buffer | ec.KeyPair, enc?: string): boolean;
|
||||
recoverPubKey(msg: BNInput, signature: ec.Signature | ec.SignatureOptions, j: number, enc?: string): any;
|
||||
getKeyRecoveryParam(e: Error | undefined, signature: ec.Signature | ec.SignatureOptions, Q: BN, enc?: string): number;
|
||||
}
|
||||
|
||||
export namespace ec {
|
||||
interface GenKeyPairOptions {
|
||||
pers: any;
|
||||
entropy: any;
|
||||
persEnc?: string;
|
||||
entropyEnc?: string;
|
||||
}
|
||||
|
||||
interface SignOptions {
|
||||
pers: any;
|
||||
persEnc?: string;
|
||||
canonical?: boolean;
|
||||
k?: BN;
|
||||
}
|
||||
|
||||
class KeyPair {
|
||||
static fromPublic(ec: ec, pub: Buffer | KeyPair, enc?: string): KeyPair;
|
||||
static fromPrivate(ec: ec, priv: Buffer | KeyPair, enc?: string): KeyPair;
|
||||
constructor(ec: ec, options: KeyPairOptions)
|
||||
ec: ec;
|
||||
validate(): { readonly result: boolean, readonly reason: string };
|
||||
getPublic(compact: boolean, enc?: string): any; // ?
|
||||
getPublic(enc?: string): any; // ?
|
||||
getPrivate(enc?: 'hex'): Buffer | BN | string;
|
||||
derive(pub: any): any; // ?
|
||||
sign(msg: BNInput, enc: string, options?: SignOptions): Signature;
|
||||
sign(msg: BNInput, options?: SignOptions): Signature;
|
||||
verify(msg: BNInput, signature: Signature | SignatureOptions): boolean;
|
||||
inspect(): string;
|
||||
}
|
||||
|
||||
class Signature {
|
||||
constructor(options: SignatureOptions | Signature, enc?: string)
|
||||
r: BN;
|
||||
s: BN;
|
||||
recoveryParam: number | null;
|
||||
toDER(enc?: string | null): any; // ?
|
||||
}
|
||||
|
||||
interface SignatureOptions {
|
||||
r: number;
|
||||
s: number;
|
||||
recoveryParam?: number;
|
||||
}
|
||||
|
||||
interface KeyPairOptions {
|
||||
priv?: Buffer;
|
||||
privEnc?: string;
|
||||
pub?: Buffer;
|
||||
pubEnc?: string;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"elliptic-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import Application from '@ember/application';
|
||||
import EmberResolver from 'ember-resolver';
|
||||
import { Ember } from 'ember';
|
||||
|
||||
const MyResolver = EmberResolver.extend({
|
||||
pluralizedTypes: {
|
||||
@@ -7,6 +7,6 @@ const MyResolver = EmberResolver.extend({
|
||||
}
|
||||
});
|
||||
|
||||
const App = Application.extend({
|
||||
const App = Ember.Application.extend({
|
||||
Resolver: MyResolver
|
||||
});
|
||||
|
||||
Vendored
+2
-4
@@ -5,11 +5,9 @@
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
/// <reference types="ember" />
|
||||
|
||||
import Resolver from '@ember/application/resolver';
|
||||
import Ember from 'ember';
|
||||
|
||||
/**
|
||||
* An Ember `Resolver` implementation used by ember-cli.
|
||||
*/
|
||||
export default class EmberResolver extends Resolver {}
|
||||
export default class EmberResolver extends Ember.Resolver {}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Application from '@ember/application';
|
||||
import Ember from 'ember';
|
||||
import EmberResolver from 'ember-resolver';
|
||||
|
||||
const MyResolver = EmberResolver.extend({
|
||||
@@ -7,6 +7,6 @@ const MyResolver = EmberResolver.extend({
|
||||
}
|
||||
});
|
||||
|
||||
const App = Application.extend({
|
||||
const App = Ember.Application.extend({
|
||||
Resolver: MyResolver
|
||||
});
|
||||
|
||||
Vendored
+2
-4
@@ -5,11 +5,9 @@
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.4
|
||||
|
||||
/// <reference types="ember" />
|
||||
|
||||
import Resolver from '@ember/application/resolver';
|
||||
import Ember from 'ember';
|
||||
|
||||
/**
|
||||
* An Ember `Resolver` implementation used by ember-cli.
|
||||
*/
|
||||
export default class EmberResolver extends Resolver {}
|
||||
export default class EmberResolver extends Ember.Resolver {}
|
||||
|
||||
Vendored
+82
-113
@@ -13,7 +13,6 @@
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
/// <reference types="jquery" />
|
||||
/// <reference types="handlebars" />
|
||||
|
||||
declare module 'ember' {
|
||||
import {
|
||||
@@ -25,7 +24,7 @@ declare module 'ember' {
|
||||
} from 'ember/-private-types/object/computed';
|
||||
import { Objectify, Fix, KeysOfType, TypeLookup } from 'ember/-private-types/utils';
|
||||
import { EmberClassArguments, EmberClassConstructor, EmberInstanceArguments } from 'ember/-private-types/object';
|
||||
|
||||
import * as HandlebarsNamespace from 'handlebars';
|
||||
// Capitalization is intentional: this makes it much easier to re-export RSVP on
|
||||
// the Ember namespace.
|
||||
import Rsvp from 'rsvp';
|
||||
@@ -34,6 +33,8 @@ declare module 'ember' {
|
||||
import { Registry as ServiceRegistry } from '@ember/service';
|
||||
import { Registry as ControllerRegistry } from '@ember/controller';
|
||||
import ModuleComputed from '@ember/object/computed';
|
||||
import * as EmberString from '@ember/string';
|
||||
import * as EmberPolyfills from '@ember/polyfills';
|
||||
|
||||
// Get an alias to the global Array type to use in inner scope below.
|
||||
type GlobalArray<T> = T[];
|
||||
@@ -739,7 +740,7 @@ declare module 'ember' {
|
||||
class ContainerDebugAdapter extends Object {
|
||||
resolver: Resolver;
|
||||
canCatalogEntriesByType(type: string): boolean;
|
||||
catalogEntriesByType(type: string): any[];
|
||||
catalogEntriesByType(type: string): string[];
|
||||
}
|
||||
/**
|
||||
* Additional methods for the Controller.
|
||||
@@ -1004,32 +1005,54 @@ declare module 'ember' {
|
||||
* The container-debug-adapter which is used
|
||||
* to list all models.
|
||||
*/
|
||||
containerDebugAdapter: any;
|
||||
containerDebugAdapter: ContainerDebugAdapter;
|
||||
/**
|
||||
* Ember Data > v1.0.0-beta.18
|
||||
* requires string model names to be passed
|
||||
* around instead of the actual factories.
|
||||
*/
|
||||
acceptsModelName: any;
|
||||
acceptsModelName: boolean;
|
||||
/**
|
||||
* Specifies how records can be filtered.
|
||||
* Records returned will need to have a `filterValues`
|
||||
* property with a key for every name in the returned array.
|
||||
*/
|
||||
getFilters(): any[];
|
||||
getFilters(): DataAdapter.Column[];
|
||||
/**
|
||||
* Fetch the model types and observe them for changes.
|
||||
*/
|
||||
watchModelTypes(typesAdded: Function, typesUpdated: Function): Function;
|
||||
watchModelTypes(
|
||||
typesAdded: (types: DataAdapter.WrappedType[]) => void,
|
||||
typesUpdated: (types: DataAdapter.WrappedType[]) => void
|
||||
): () => void;
|
||||
/**
|
||||
* Fetch the records of a given type and observe them for changes.
|
||||
*/
|
||||
watchRecords(
|
||||
modelName: string,
|
||||
recordsAdded: Function,
|
||||
recordsUpdated: Function,
|
||||
recordsRemoved: Function
|
||||
): Function;
|
||||
recordsAdded: (records: DataAdapter.WrappedRecord[]) => void,
|
||||
recordsUpdated: (records: DataAdapter.WrappedRecord[]) => void,
|
||||
recordsRemoved: (idx: number, count: number) => void
|
||||
): () => void;
|
||||
}
|
||||
namespace DataAdapter {
|
||||
interface Column {
|
||||
name: string;
|
||||
desc: string;
|
||||
}
|
||||
interface WrappedRecord {
|
||||
columnValues: object;
|
||||
object: object;
|
||||
}
|
||||
interface WrappedType {
|
||||
type: {
|
||||
name: string;
|
||||
count: number;
|
||||
columns: Column[];
|
||||
object: typeof Object;
|
||||
};
|
||||
release: () => void;
|
||||
}
|
||||
}
|
||||
const Debug: {
|
||||
/**
|
||||
@@ -1038,14 +1061,14 @@ declare module 'ember' {
|
||||
* The following example demonstrates its usage by registering a handler that throws an error if the
|
||||
* message contains the word "should", otherwise defers to the default handler.
|
||||
*/
|
||||
registerDeprecationHandler(handler: Function): any;
|
||||
registerDeprecationHandler(handler: (message: string, options: { id: string, until: string }, next: () => void) => void): void;
|
||||
/**
|
||||
* Allows for runtime registration of handler functions that override the default warning behavior.
|
||||
* Warnings are invoked by calls made to [Ember.warn](http://emberjs.com/api/classes/Ember.html#method_warn).
|
||||
* The following example demonstrates its usage by registering a handler that does nothing overriding Ember's
|
||||
* default warning behavior.
|
||||
*/
|
||||
registerWarnHandler(handler: Function): any;
|
||||
registerWarnHandler(handler: (message: string, options: { id: string }, next: () => void) => void): void;
|
||||
};
|
||||
/**
|
||||
* The DefaultResolver defines the default lookup rules to resolve
|
||||
@@ -1711,11 +1734,11 @@ declare module 'ember' {
|
||||
key: keyof this,
|
||||
target: Target,
|
||||
method: ObserverMethod<Target, this>
|
||||
): void;
|
||||
): this;
|
||||
addObserver(
|
||||
key: keyof this,
|
||||
method: ObserverMethod<this, this>
|
||||
): void;
|
||||
): this;
|
||||
/**
|
||||
* Remove an observer you have previously registered on this object. Pass
|
||||
* the same key, target, and method you passed to `addObserver()` and your
|
||||
@@ -1725,11 +1748,11 @@ declare module 'ember' {
|
||||
key: keyof this,
|
||||
target: Target,
|
||||
method: ObserverMethod<Target, this>
|
||||
): any;
|
||||
): this;
|
||||
removeObserver(
|
||||
key: keyof this,
|
||||
method: ObserverMethod<this, this>
|
||||
): any;
|
||||
): this;
|
||||
/**
|
||||
* Retrieves the value of a property, or a default value in the case that the
|
||||
* property returns `undefined`.
|
||||
@@ -2399,27 +2422,24 @@ declare module 'ember' {
|
||||
function K(): any;
|
||||
function createFrame(objec: any): any;
|
||||
function Exception(message: string): void;
|
||||
class SafeString {
|
||||
constructor(str: string);
|
||||
toString(): string;
|
||||
}
|
||||
const SafeString: typeof HandlebarsNamespace.SafeString;
|
||||
function parse(string: string): any;
|
||||
function print(ast: any): void;
|
||||
const logger: typeof Ember.Logger;
|
||||
function log(level: string, str: string): void;
|
||||
}
|
||||
namespace String {
|
||||
function camelize(str: string): string;
|
||||
function capitalize(str: string): string;
|
||||
function classify(str: string): string;
|
||||
function dasherize(str: string): string;
|
||||
function decamelize(str: string): string;
|
||||
const camelize: typeof EmberString.camelize;
|
||||
const capitalize: typeof EmberString.capitalize;
|
||||
const classify: typeof EmberString.classify;
|
||||
const dasherize: typeof EmberString.dasherize;
|
||||
const decamelize: typeof EmberString.decamelize;
|
||||
function fmt(...args: string[]): string;
|
||||
function htmlSafe(str: string): Handlebars.SafeString;
|
||||
function isHTMLSafe(str: string): boolean;
|
||||
function loc(template: string, args?: string[]): string;
|
||||
function underscore(str: string): string;
|
||||
function w(str: string): string[];
|
||||
const htmlSafe: typeof EmberString.htmlSafe;
|
||||
const isHTMLSafe: typeof EmberString.isHTMLSafe;
|
||||
const loc: typeof EmberString.loc;
|
||||
const underscore: typeof EmberString.underscore;
|
||||
const w: typeof EmberString.w;
|
||||
}
|
||||
const computed: {
|
||||
<T>(cb: ComputedPropertyCallback<T>): ComputedProperty<T>;
|
||||
@@ -3017,20 +3037,20 @@ declare module 'ember' {
|
||||
/**
|
||||
* Run a function meant for debugging.
|
||||
*/
|
||||
function runInDebug(func: () => void): any;
|
||||
function runInDebug(func: () => any): void;
|
||||
/**
|
||||
* Display a warning with the provided message.
|
||||
*/
|
||||
function warn(message: string, test: boolean, options: { id: string }): any;
|
||||
function warn(message: string, options: { id: string }): any;
|
||||
function warn(message: string, test: boolean, options: { id: string }): void;
|
||||
function warn(message: string, options: { id: string }): void;
|
||||
/**
|
||||
* @deprecated Missing deprecation options: https://emberjs.com/deprecations/v2.x/#toc_ember-debug-function-options
|
||||
*/
|
||||
function warn(message: string, test: boolean, options?: { id?: string }): any;
|
||||
function warn(message: string, test: boolean, options?: { id?: string }): void;
|
||||
/**
|
||||
* @deprecated Missing deprecation options: https://emberjs.com/deprecations/v2.x/#toc_ember-debug-function-options
|
||||
*/
|
||||
function warn(message: string, options?: { id?: string }): any;
|
||||
function warn(message: string, options?: { id?: string }): void;
|
||||
/**
|
||||
* Global helper method to create a new binding. Just pass the root object
|
||||
* along with a `to` and `from` path to create and connect the binding.
|
||||
@@ -3116,11 +3136,7 @@ declare module 'ember' {
|
||||
* A value is present if it not `isBlank`.
|
||||
*/
|
||||
function isPresent(obj?: any): boolean;
|
||||
/**
|
||||
* Merge the contents of two objects together into the first object.
|
||||
* @deprecated Use Object.assign
|
||||
*/
|
||||
function merge<T extends object, U extends object>(original: T, updates: U): Mix<T, U>;
|
||||
const merge: typeof EmberPolyfills.merge;
|
||||
/**
|
||||
* Makes a method available via an additional name.
|
||||
*/
|
||||
@@ -3128,33 +3144,33 @@ declare module 'ember' {
|
||||
/**
|
||||
* Specify a method that observes property changes.
|
||||
*/
|
||||
function observer(key1: string, func: (target: any, key: string) => void): void;
|
||||
function observer(
|
||||
function observer<Fn extends (target: any, key: string) => void>(key1: string, func: Fn): Fn;
|
||||
function observer<Fn extends (target: any, key: string) => void>(
|
||||
key1: string,
|
||||
key2: string,
|
||||
func: (target: any, key: string) => void
|
||||
): void;
|
||||
function observer(
|
||||
func: Fn
|
||||
): Fn;
|
||||
function observer<Fn extends (target: any, key: string) => void>(
|
||||
key1: string,
|
||||
key2: string,
|
||||
key3: string,
|
||||
func: (target: any, key: string) => void
|
||||
): void;
|
||||
function observer(
|
||||
func: Fn
|
||||
): Fn;
|
||||
function observer<Fn extends (target: any, key: string) => void>(
|
||||
key1: string,
|
||||
key2: string,
|
||||
key3: string,
|
||||
key4: string,
|
||||
func: (target: any, key: string) => void
|
||||
): void;
|
||||
function observer(
|
||||
func: Fn
|
||||
): Fn;
|
||||
function observer<Fn extends (target: any, key: string) => void>(
|
||||
key1: string,
|
||||
key2: string,
|
||||
key3: string,
|
||||
key4: string,
|
||||
key5: string,
|
||||
func: (target: any, key: string) => void
|
||||
): void;
|
||||
func: Fn
|
||||
): Fn;
|
||||
/**
|
||||
* Adds an observer on a property.
|
||||
*/
|
||||
@@ -3211,6 +3227,11 @@ declare module 'ember' {
|
||||
key: K,
|
||||
value: UnwrapComputedPropertySetter<T[K]>
|
||||
): UnwrapComputedPropertyGetter<T[K]>;
|
||||
function set<T, K extends keyof T>(
|
||||
obj: T,
|
||||
key: K,
|
||||
value: T[K]
|
||||
): T[K];
|
||||
/**
|
||||
* Error-tolerant form of `Ember.set`. Will not blow up if any part of the
|
||||
* chain is `undefined`, `null`, or destroyed.
|
||||
@@ -3225,6 +3246,11 @@ declare module 'ember' {
|
||||
obj: T,
|
||||
hash: Pick<UnwrapComputedPropertySetters<T>, K>
|
||||
): Pick<UnwrapComputedPropertyGetters<T>, K>;
|
||||
// TODO: in TS2.9 - Pick<UnwrapComputedPropertySetters<T> | T, K>
|
||||
function setProperties<T, K extends keyof T>(
|
||||
obj: T,
|
||||
hash: Pick<T, K>
|
||||
): Pick<T, K>;
|
||||
/**
|
||||
* Detects when a specific package of Ember (e.g. 'Ember.Application')
|
||||
* has fully loaded and is available for extension.
|
||||
@@ -3267,14 +3293,12 @@ declare module 'ember' {
|
||||
function typeOf<T>(value: T): KeysOfType<TypeLookup, T>;
|
||||
function typeOf(): 'undefined';
|
||||
function typeOf(item: any): string;
|
||||
// TODO: replace with an es6 reexport when declare module 'ember' is removed
|
||||
/**
|
||||
* Copy properties from a source object to a target object.
|
||||
* @deprecated Use Object.assign
|
||||
*/
|
||||
function assign<T extends object, U extends object>(target: T, source: U): Mix<T, U>;
|
||||
function assign<T extends object, U extends object, V extends object>(target: T, source1: U, source2: V): Mix3<T, U, V>;
|
||||
function assign<T extends object, U extends object, V extends object, W extends object>(target: T, source1: U, source2: V, source3: W): Mix4<T, U, V, W>;
|
||||
|
||||
const assign: typeof EmberPolyfills.assign;
|
||||
/**
|
||||
* Polyfill for Object.create
|
||||
* @deprecated Use Object.create
|
||||
@@ -3309,12 +3333,6 @@ declare module 'ember' {
|
||||
: undefined;
|
||||
function tryInvoke<FNAME extends keyof T, T extends object>(obj: T, methodName: FNAME): T[FNAME] extends (() => any) ? ReturnType<T[FNAME]> : undefined;
|
||||
function tryInvoke(obj: object, methodName: string, args?: any[]): undefined;
|
||||
/**
|
||||
* Forces the passed object to be part of an array. If the object is already
|
||||
* an array, it will return the object. Otherwise, it will add the object to
|
||||
* an array. If obj is `null` or `undefined`, it will return an empty array.
|
||||
*/
|
||||
function makeArray<T>(obj?: T[] | T | null): T[];
|
||||
/**
|
||||
* Framework objects in an Ember application (components, services, routes, etc.)
|
||||
* are created via a factory and dependency injection system. Each of these
|
||||
@@ -3529,7 +3547,6 @@ declare module '@ember/array' {
|
||||
export default EmberArray;
|
||||
export const A: typeof Ember.A;
|
||||
export const isArray: typeof Ember.isArray;
|
||||
export const makeArray: typeof Ember.makeArray;
|
||||
}
|
||||
|
||||
declare module '@ember/array/mutable' {
|
||||
@@ -3625,37 +3642,12 @@ declare module '@ember/engine/instance' {
|
||||
export default class EngineInstance extends Ember.EngineInstance { }
|
||||
}
|
||||
|
||||
declare module '@ember/enumerable' {
|
||||
import Ember from 'ember';
|
||||
type Enumerable<T> = Ember.Enumerable<T>;
|
||||
const Enumerable: typeof Ember.Enumerable;
|
||||
export default Enumerable;
|
||||
}
|
||||
|
||||
declare module '@ember/error' {
|
||||
import Ember from 'ember';
|
||||
const Error: typeof Ember.Error;
|
||||
export default Error;
|
||||
}
|
||||
|
||||
declare module '@ember/instrumentation' {
|
||||
import Ember from 'ember';
|
||||
export const instrument: typeof Ember.instrument;
|
||||
export const reset: typeof Ember.reset;
|
||||
export const subscribe: typeof Ember.subscribe;
|
||||
export const unsubscribe: typeof Ember.unsubscribe;
|
||||
}
|
||||
|
||||
declare module '@ember/map' {
|
||||
import Ember from 'ember';
|
||||
export default class EmberMap extends Ember.Map { }
|
||||
}
|
||||
|
||||
declare module '@ember/map/with-default' {
|
||||
import Ember from 'ember';
|
||||
export default class MapWithDefault extends Ember.MapWithDefault { }
|
||||
}
|
||||
|
||||
declare module '@ember/object' {
|
||||
import Ember from 'ember';
|
||||
export default class EmberObject extends Ember.Object { }
|
||||
@@ -3768,15 +3760,6 @@ declare module '@ember/object/proxy' {
|
||||
export default class ObjectProxy extends Ember.ObjectProxy { }
|
||||
}
|
||||
|
||||
declare module '@ember/polyfills' {
|
||||
import Ember from 'ember';
|
||||
export const assign: typeof Ember.assign;
|
||||
export const create: typeof Ember.create;
|
||||
export const hasPropertyAccessors: typeof Ember.platform.hasPropertyAccessors;
|
||||
export const keys: typeof Ember.keys;
|
||||
export const merge: typeof Ember.merge;
|
||||
}
|
||||
|
||||
declare module '@ember/routing/auto-location' {
|
||||
import Ember from 'ember';
|
||||
export default class AutoLocation extends Ember.AutoLocation { }
|
||||
@@ -3850,20 +3833,6 @@ declare module '@ember/service' {
|
||||
interface Registry {}
|
||||
}
|
||||
|
||||
declare module '@ember/string' {
|
||||
import Ember from 'ember';
|
||||
export const camelize: typeof Ember.String.camelize;
|
||||
export const capitalize: typeof Ember.String.capitalize;
|
||||
export const classify: typeof Ember.String.classify;
|
||||
export const dasherize: typeof Ember.String.dasherize;
|
||||
export const decamelize: typeof Ember.String.decamelize;
|
||||
export const htmlSafe: typeof Ember.String.htmlSafe;
|
||||
export const isHTMLSafe: typeof Ember.String.isHTMLSafe;
|
||||
export const loc: typeof Ember.String.loc;
|
||||
export const underscore: typeof Ember.String.underscore;
|
||||
export const w: typeof Ember.String.w;
|
||||
}
|
||||
|
||||
declare module '@ember/test' {
|
||||
import Ember from 'ember';
|
||||
export const registerAsyncHelper: typeof Ember.Test.registerAsyncHelper;
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
const da = Ember.DataAdapter.create();
|
||||
|
||||
const filters = da.getFilters();
|
||||
filters.includes({ name: 'foo', desc: 'bar'}); // $ExpectType boolean
|
||||
filters.includes({}); // $ExpectError
|
||||
|
||||
filters[0].name; // $ExpectType string
|
||||
filters[0].desc; // $ExpectType string
|
||||
|
||||
da.watchModelTypes(// $ExpectType () => void
|
||||
function added(wrappedTypes) {
|
||||
wrappedTypes;
|
||||
wrappedTypes[0].release; // $ExpectType () => void
|
||||
wrappedTypes[0].type.columns[0].desc; // $ExpectType string
|
||||
wrappedTypes[0].type.columns[0].name; // $ExpectType string
|
||||
wrappedTypes[0].type.count; // $ExpectType number
|
||||
wrappedTypes[0].type.name; // $ExpectType string
|
||||
},
|
||||
function updated(wrappedTypes) {
|
||||
wrappedTypes;
|
||||
wrappedTypes[0].release; // $ExpectType () => void
|
||||
wrappedTypes[0].type.columns[0].desc; // $ExpectType string
|
||||
wrappedTypes[0].type.columns[0].name; // $ExpectType string
|
||||
wrappedTypes[0].type.count; // $ExpectType number
|
||||
wrappedTypes[0].type.name; // $ExpectType string
|
||||
}
|
||||
);
|
||||
da.watchModelTypes(() => void); // $ExpectError
|
||||
|
||||
da.watchRecords('house', // $ExpectType () => void
|
||||
function added(records) {
|
||||
records[0].object; // $ExpectType object
|
||||
records[0].columnValues; // $ExpectType object
|
||||
},
|
||||
function updated(records) {
|
||||
records[0].object; // $ExpectType object
|
||||
records[0].columnValues; // $ExpectType object
|
||||
},
|
||||
function removed(idx, count) {
|
||||
idx; // $ExpectType number
|
||||
count; // $ExpectType number
|
||||
}
|
||||
);
|
||||
da.watchRecords(() => void); // $ExpectError
|
||||
|
||||
da.acceptsModelName; // $ExpectType boolean
|
||||
da.containerDebugAdapter; // $ExpectType ContainerDebugAdapter
|
||||
|
||||
const ca: Ember.ContainerDebugAdapter = da.containerDebugAdapter;
|
||||
ca.canCatalogEntriesByType('controller'); // $ExpectType boolean
|
||||
ca.catalogEntriesByType('controller'); // $ExpectType string[]
|
||||
@@ -0,0 +1,53 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
const {
|
||||
runInDebug,
|
||||
warn,
|
||||
debug,
|
||||
assert,
|
||||
Debug: { registerDeprecationHandler, registerWarnHandler }
|
||||
} = Ember;
|
||||
|
||||
/**
|
||||
* @ember/debug tests
|
||||
*/
|
||||
runInDebug(); // $ExpectError
|
||||
let x = runInDebug(() => console.log('Should not show up in prod')); // $ExpectType void
|
||||
|
||||
// Log a warning if we have more than 3 tomsters
|
||||
const tomsterCount = 2;
|
||||
warn('Too many tomsters!'); // $ExpectType void
|
||||
warn('Too many tomsters!', tomsterCount <= 3); // $ExpectType void
|
||||
warn('Too many tomsters!', tomsterCount <= 3, { // $ExpectType void
|
||||
id: 'ember-debug.too-many-tomsters'
|
||||
});
|
||||
|
||||
debug(); // $ExpectError
|
||||
debug('Too many tomsters!'); // $ExpectType void
|
||||
debug('Too many tomsters!', 'foo'); // $ExpectError
|
||||
|
||||
// Test for truthiness
|
||||
const str = 'hello';
|
||||
assert('Must pass a string', typeof str === 'string'); // $ExpectType void
|
||||
|
||||
// Fail unconditionally
|
||||
assert('This code path should never be run'); // $ExpectType void
|
||||
|
||||
// next is not called, so no warnings get the default behavior
|
||||
registerWarnHandler(); // $ExpectError
|
||||
registerWarnHandler(() => {}); // $ExpectType void
|
||||
registerWarnHandler((message, { id }, next) => { // $ExpectType void
|
||||
message; // $ExpectType string
|
||||
id; // $ExpectType string
|
||||
next; // $ExpectType () => void
|
||||
});
|
||||
|
||||
// next is not called, so no warnings get the default behavior
|
||||
registerDeprecationHandler(); // $ExpectError
|
||||
registerDeprecationHandler(() => {}); // $ExpectType void
|
||||
registerDeprecationHandler((message, { id, until }, next) => { // $ExpectType void
|
||||
message; // $ExpectType string
|
||||
id; // $ExpectType string
|
||||
until; // $ExpectType string
|
||||
next; // $ExpectType () => void
|
||||
});
|
||||
@@ -49,3 +49,20 @@ class Foo extends Ember.Object.extend({
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export class Foo2 extends Ember.Object {
|
||||
name!: string;
|
||||
|
||||
changeName(name: string) {
|
||||
let a: string = this.set('name', name);
|
||||
let b: number = this.set('name', name); // $ExpectError
|
||||
let x: string = Ember.set(this, 'name', name);
|
||||
let y: number = Ember.set(this, 'name', name); // $ExpectError
|
||||
this.setProperties({
|
||||
name
|
||||
});
|
||||
Ember.setProperties(this, {
|
||||
name
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,13 +69,13 @@ class DemoObservable implements Observable {
|
||||
notifyPropertyChange(keyName: string): this {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
addObserver<Target>(key: keyof this, target: Target, method: keyof Target | ((this: Target, sender: this, key: keyof this, value: any, rev: number) => void)): void;
|
||||
addObserver<K extends keyof this>(key: K, method: keyof this | ((this: this, sender: this, key: K, value: this[K], rev: number) => void)): void;
|
||||
addObserver<Target>(key: keyof this, target: Target, method: keyof Target | ((this: Target, sender: this, key: string, value: any, rev: number) => void)): any;
|
||||
addObserver<K extends keyof this>(key: K, method: keyof this | ((this: this, sender: this, key: K, value: this[K], rev: number) => void)): any;
|
||||
addObserver(key: any, target: any, method?: any) {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
removeObserver<Target>(key: keyof this, target: Target, method: keyof Target | ((this: Target, sender: this, key: keyof this, value: any, rev: number) => void)): void;
|
||||
removeObserver(key: keyof this, method: keyof this | ((this: this, sender: this, key: string, value: any, rev: number) => void)): void;
|
||||
removeObserver<Target>(key: keyof this, target: Target, method: keyof Target | ((this: Target, sender: this, key: string, value: any, rev: number) => void)): any;
|
||||
removeObserver(key: keyof this, method: keyof this | ((this: this, sender: this, key: string, value: any, rev: number) => void)): any;
|
||||
removeObserver(key: any, target: any, method?: any): void {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import Ember from 'ember';
|
||||
import { SafeString } from 'handlebars';
|
||||
|
||||
const { dasherize, camelize, capitalize, classify, decamelize, htmlSafe, loc, underscore, w } = Ember.String;
|
||||
|
||||
@@ -34,3 +35,7 @@ loc(); // $ExpectError
|
||||
loc("_Hello World"); // $ExpectType string
|
||||
// TODO - fix this case upstream in @types/ember https://github.com/typed-ember/ember-cli-typescript/issues/281
|
||||
loc("_Hello %@ %@", ["John", "Smith"]); // $ExpectType string
|
||||
|
||||
const handlebarsSafeString: SafeString = Ember.String.htmlSafe('lorem ipsum...');
|
||||
Ember.String.htmlSafe('lorem ipsum...'); // $ExpectType SafeString
|
||||
const regularString: string = Ember.String.htmlSafe('lorem ipsum...'); // $ExpectError
|
||||
|
||||
@@ -62,14 +62,6 @@ function testOnError() {
|
||||
};
|
||||
}
|
||||
|
||||
function testMakeArray() {
|
||||
assertType<any[]>(Ember.makeArray());
|
||||
assertType<any[]>(Ember.makeArray(null));
|
||||
assertType<any[]>(Ember.makeArray(undefined));
|
||||
assertType<string[]>(Ember.makeArray('lindsay'));
|
||||
assertType<number[]>(Ember.makeArray([1, 2, 42]));
|
||||
}
|
||||
|
||||
function testDeprecateFunc() {
|
||||
function newMethod(first: string, second: number): string {
|
||||
return '';
|
||||
|
||||
@@ -14,6 +14,10 @@
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"paths": {
|
||||
"@ember/string": ["ember__string"],
|
||||
"@ember/polyfills": ["ember__polyfills"]
|
||||
},
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
@@ -40,6 +44,8 @@
|
||||
"test/core-object.ts",
|
||||
"test/create-negative.ts",
|
||||
"test/create.ts",
|
||||
"test/data-adapter.ts",
|
||||
"test/debug.ts",
|
||||
"test/detect-instance.ts",
|
||||
"test/detect.ts",
|
||||
"test/ember-tests.ts",
|
||||
@@ -58,8 +64,8 @@
|
||||
"test/route.ts",
|
||||
"test/router.ts",
|
||||
"test/run.ts",
|
||||
"test/string.ts",
|
||||
"test/string-ext.ts",
|
||||
"test/string.ts",
|
||||
"test/test.ts",
|
||||
"test/transition.ts",
|
||||
"test/utils.ts",
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
export const deprecate: typeof Ember.deprecate;
|
||||
export const deprecateFunc: typeof Ember.deprecateFunc;
|
||||
@@ -0,0 +1,3 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
export default class GlobalsResolver extends Ember.DefaultResolver { }
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
// Type definitions for @ember/application 3.0
|
||||
// Project: http://emberjs.com/
|
||||
// Definitions by: Mike North <https://github.com/mike-north>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import Ember from 'ember';
|
||||
|
||||
export default class Application extends Ember.Application { }
|
||||
export const getOwner: typeof Ember.getOwner;
|
||||
export const onLoad: typeof Ember.onLoad;
|
||||
export const runLoadHooks: typeof Ember.runLoadHooks;
|
||||
export const setOwner: typeof Ember.setOwner;
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
export default class ApplicationInstance extends Ember.ApplicationInstance { }
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
export default class Resolver extends Ember.Resolver { }
|
||||
@@ -0,0 +1,29 @@
|
||||
import ApplicationInstance from '@ember/application/instance';
|
||||
import hbs from 'htmlbars-inline-precompile';
|
||||
|
||||
const appInstance = ApplicationInstance.create();
|
||||
appInstance.register('some:injection', class Foo {});
|
||||
|
||||
appInstance.register('some:injection', class Foo {}, {
|
||||
singleton: true,
|
||||
});
|
||||
|
||||
appInstance.register('some:injection', class Foo {}, {
|
||||
instantiate: false,
|
||||
});
|
||||
|
||||
appInstance.register('templates:foo/bar', hbs`<h1>Hello World</h1>`);
|
||||
|
||||
appInstance.register('some:injection', class Foo {}, {
|
||||
singleton: false,
|
||||
instantiate: true,
|
||||
});
|
||||
|
||||
appInstance.factoryFor('router:main');
|
||||
appInstance.lookup('route:basic');
|
||||
|
||||
appInstance.boot();
|
||||
|
||||
(async () => {
|
||||
await appInstance.boot();
|
||||
})();
|
||||
Executable
+41
@@ -0,0 +1,41 @@
|
||||
import Application from "@ember/application";
|
||||
import EmberObject from "@ember/object";
|
||||
|
||||
const BaseApp = Application.extend({
|
||||
modulePrefix: 'my-app'
|
||||
});
|
||||
|
||||
BaseApp.initializer({
|
||||
name: 'my-initializer',
|
||||
initialize(app) {
|
||||
app.register('foo:bar', EmberObject.extend({ foo: 'bar' }));
|
||||
}
|
||||
});
|
||||
|
||||
BaseApp.instanceInitializer({
|
||||
name: 'my-instance-initializer',
|
||||
initialize(app) {
|
||||
app.lookup('foo:bar').get('foo');
|
||||
}
|
||||
});
|
||||
|
||||
const App1 = BaseApp.create({
|
||||
rootElement: '#app-one',
|
||||
customEvents: {
|
||||
paste: 'paste'
|
||||
}
|
||||
});
|
||||
|
||||
const App2 = BaseApp.create({
|
||||
rootElement: '#app-two',
|
||||
customEvents: {
|
||||
mouseenter: null,
|
||||
mouseleave: null
|
||||
}
|
||||
});
|
||||
|
||||
const App3 = BaseApp.create();
|
||||
|
||||
const App3Instance1 = App3.buildInstance(); // $ExpectType ApplicationInstance
|
||||
|
||||
const App3Instance2 = App3.buildInstance({ foo: 'bar' }); // $ExpectType ApplicationInstance
|
||||
@@ -0,0 +1,14 @@
|
||||
import { deprecate, deprecateFunc } from '@ember/application/deprecations';
|
||||
|
||||
deprecate('this is no longer advised', false, {
|
||||
id: 'no-longer-advised',
|
||||
until: 'v4.0'
|
||||
});
|
||||
deprecate('this is no longer advised', false);
|
||||
|
||||
deprecateFunc('this is no longer advised', () => {});
|
||||
deprecateFunc(
|
||||
'this is no longer advised',
|
||||
{ id: 'no-longer-do-this', until: 'v4.0' },
|
||||
() => {}
|
||||
);
|
||||
@@ -0,0 +1,6 @@
|
||||
import GlobalsResolver from "@ember/application/globals-resolver";
|
||||
|
||||
const gr = GlobalsResolver.create();
|
||||
|
||||
gr.resolve('App.IndexController');
|
||||
gr.resolve(); // $ExpectError
|
||||
@@ -0,0 +1,3 @@
|
||||
import Resolver from "@ember/application/resolver";
|
||||
|
||||
const res = Resolver.create();
|
||||
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"paths": {
|
||||
"@ember/application": ["ember__application"],
|
||||
"@ember/application/*": ["ember__application/*"]
|
||||
},
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"deprecations.d.ts",
|
||||
"globals-resolver.d.ts",
|
||||
"index.d.ts",
|
||||
"instance.d.ts",
|
||||
"resolver.d.ts",
|
||||
"test/application.ts",
|
||||
"test/deprecations.ts",
|
||||
"test/resolver.ts",
|
||||
"test/globals-resolver.ts",
|
||||
"test/application-instance.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {}
|
||||
}
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
// Type definitions for @ember/array 3.0
|
||||
// Project: http://emberjs.com/
|
||||
// Definitions by: Mike North <https://github.com/mike-north>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import Ember from 'ember';
|
||||
|
||||
type EmberArray<T> = Ember.Array<T>;
|
||||
export const EmberArray: typeof Ember.Array;
|
||||
export default EmberArray;
|
||||
export const A: typeof Ember.A;
|
||||
export const isArray: typeof Ember.isArray;
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
type MutableArray<T> = Ember.MutableArray<T>;
|
||||
export const MutableArray: typeof Ember.MutableArray;
|
||||
export default MutableArray;
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
export default class ArrayProxy<T> extends Ember.ArrayProxy<T> { }
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
import { assertType } from './lib/assert';
|
||||
import EmberObject from '@ember/object';
|
||||
import { ArrayPrototypeExtensions } from '@ember/array/types/prototype-extensions';
|
||||
|
||||
declare global {
|
||||
interface Array<T> extends ArrayPrototypeExtensions<T> {}
|
||||
}
|
||||
|
||||
class Person extends EmberObject {
|
||||
name: string;
|
||||
}
|
||||
|
||||
const person = Person.create({ name: 'Joe' });
|
||||
const array = [person];
|
||||
|
||||
assertType<number>(array.get('length'));
|
||||
assertType<Person | undefined>(array.get('firstObject'));
|
||||
assertType<string[]>(array.mapBy('name'));
|
||||
assertType<string[]>(array.map(p => p.get('name')));
|
||||
assertType<Person[]>(array.sortBy('name'));
|
||||
assertType<Person[]>(array.uniq());
|
||||
assertType<Person[]>(array.uniqBy('name'));
|
||||
@@ -0,0 +1,27 @@
|
||||
import { assertType } from './lib/assert';
|
||||
import ArrayProxy from '@ember/array/proxy';
|
||||
import { A } from '@ember/array';
|
||||
|
||||
const pets = ['dog', 'cat', 'fish'];
|
||||
const proxy = ArrayProxy.create({ content: A(pets) });
|
||||
|
||||
proxy.get('firstObject'); // 'dog'
|
||||
proxy.set('content', A(['amoeba', 'paramecium']));
|
||||
proxy.get('firstObject'); // 'amoeba'
|
||||
|
||||
const overridden = ArrayProxy.create({
|
||||
content: A(pets),
|
||||
objectAtContent(idx: number): string {
|
||||
return this.get('content').objectAt(idx)!.toUpperCase();
|
||||
}
|
||||
});
|
||||
|
||||
overridden.get('firstObject'); // 'DOG'
|
||||
|
||||
class MyNewProxy<T> extends ArrayProxy<T> {
|
||||
isNew = true;
|
||||
}
|
||||
|
||||
const x = MyNewProxy.create({ content: A([1, 2, 3]) }) as MyNewProxy<number>;
|
||||
assertType<number | undefined>(x.get('firstObject'));
|
||||
assertType<boolean>(x.isNew);
|
||||
Executable
+56
@@ -0,0 +1,56 @@
|
||||
import { assertType } from './lib/assert';
|
||||
import EmberObject from '@ember/object';
|
||||
import EmberArray, { A } from '@ember/array';
|
||||
import MutableArray from '@ember/array/mutable';
|
||||
|
||||
type Person = typeof Person.prototype;
|
||||
const Person = EmberObject.extend({
|
||||
name: '',
|
||||
isHappy: false
|
||||
});
|
||||
|
||||
const people = A([
|
||||
Person.create({ name: 'Yehuda', isHappy: true }),
|
||||
Person.create({ name: 'Majd', isHappy: false }),
|
||||
]);
|
||||
|
||||
assertType<number>(people.get('length'));
|
||||
assertType<Person>(people.get('lastObject'));
|
||||
assertType<Person>(people.get('firstObject'));
|
||||
assertType<boolean>(people.isAny('isHappy'));
|
||||
assertType<boolean>(people.isAny('isHappy', 'false'));
|
||||
|
||||
const persons1: Person[] = people.filterBy('isHappy');
|
||||
const persons2: MutableArray<Person> = people.filterBy('isHappy');
|
||||
const persons3: Person[] = people.rejectBy('isHappy');
|
||||
const persons4: MutableArray<Person> = people.rejectBy('isHappy');
|
||||
const persons5: Person[] = people.filter((person) => person.get('name') === 'Yehuda');
|
||||
const persons6: MutableArray<Person> = people.filter((person) => person.get('name') === 'Yehuda');
|
||||
|
||||
assertType<typeof people>(people.get('[]'));
|
||||
assertType<Person>(people.get('[]').get('firstObject')); // $ExpectType any
|
||||
|
||||
assertType<EmberArray<boolean>>(people.mapBy('isHappy')); // $ExpectType Array<boolean>
|
||||
assertType<any[]>(people.mapBy('name.length'));
|
||||
|
||||
const last = people.get('lastObject'); // $ExpectType ({ name: string; isHappy: boolean; } & EmberObject & { name: string; isHappy: boolean; }) | undefined
|
||||
if (last) {
|
||||
assertType<string>(last.get('name'));
|
||||
}
|
||||
|
||||
const first = people.get('lastObject');
|
||||
if (first) {
|
||||
assertType<boolean>(first.get('isHappy'));
|
||||
}
|
||||
|
||||
const letters: EmberArray<string> = A(['a', 'b', 'c']);
|
||||
const codes: number[] = letters.map((item, index, enumerable) => {
|
||||
assertType<string>(item);
|
||||
assertType<number>(index);
|
||||
return item.charCodeAt(0);
|
||||
});
|
||||
|
||||
const value = '1,2,3';
|
||||
const filters = A(value.split(','));
|
||||
filters.push('4');
|
||||
filters.sort();
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
/** Static assertion that `value` has type `T` */
|
||||
// Disable tslint here b/c the generic is used to let us do a type coercion and
|
||||
// validate that coercion works for the type value "passed into" the function.
|
||||
// tslint:disable-next-line:no-unnecessary-generics
|
||||
export declare function assertType<T>(value: T): T;
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"paths": {
|
||||
"@ember/array": ["ember__array"],
|
||||
"@ember/array/*": ["ember__array/*"]
|
||||
},
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"mutable.d.ts",
|
||||
"proxy.d.ts",
|
||||
"types/prototype-extensions.d.ts",
|
||||
"test/lib/assert.ts",
|
||||
"test/array.ts",
|
||||
"test/array-ext.ts",
|
||||
"test/array-proxy.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
export interface ArrayPrototypeExtensions<T> extends Ember.MutableArray<T>, Ember.Observable, Ember.Copyable {}
|
||||
@@ -0,0 +1,2 @@
|
||||
import Ember from 'ember';
|
||||
export default class ContainerDebugAdapter extends Ember.ContainerDebugAdapter { }
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
export default class DataAdapter extends Ember.DataAdapter {}
|
||||
@@ -0,0 +1,45 @@
|
||||
import { runInDebug, warn, debug, assert, registerWarnHandler, registerDeprecationHandler } from "@ember/debug";
|
||||
|
||||
/**
|
||||
* @ember/debug tests
|
||||
*/
|
||||
runInDebug(); // $ExpectError
|
||||
runInDebug(() => console.log('Should not show up in prod')); // $ExpectType void
|
||||
|
||||
// Log a warning if we have more than 3 tomsters
|
||||
const tomsterCount = 2;
|
||||
warn('Too many tomsters!'); // $ExpectType void
|
||||
warn('Too many tomsters!', tomsterCount <= 3); // $ExpectType void
|
||||
warn('Too many tomsters!', tomsterCount <= 3, { // $ExpectType void
|
||||
id: 'ember-debug.too-many-tomsters'
|
||||
});
|
||||
|
||||
debug(); // $ExpectError
|
||||
debug('Too many tomsters!'); // $ExpectType void
|
||||
debug('Too many tomsters!', 'foo'); // $ExpectError
|
||||
|
||||
// Test for truthiness
|
||||
const str = 'hello';
|
||||
assert('Must pass a string', typeof str === 'string'); // $ExpectType void
|
||||
|
||||
// Fail unconditionally
|
||||
assert('This code path should never be run'); // $ExpectType void
|
||||
|
||||
// next is not called, so no warnings get the default behavior
|
||||
registerWarnHandler(); // $ExpectError
|
||||
registerWarnHandler(() => {}); // $ExpectType void
|
||||
registerWarnHandler((message, { id }, next) => { // $ExpectType void
|
||||
message; // $ExpectType string
|
||||
id; // $ExpectType string
|
||||
next; // $ExpectType () => void
|
||||
});
|
||||
|
||||
// next is not called, so no warnings get the default behavior
|
||||
registerDeprecationHandler(); // $ExpectError
|
||||
registerDeprecationHandler(() => {}); // $ExpectType void
|
||||
registerDeprecationHandler((message, { id, until }, next) => { // $ExpectType void
|
||||
message; // $ExpectType string
|
||||
id; // $ExpectType string
|
||||
until; // $ExpectType string
|
||||
next; // $ExpectType () => void
|
||||
});
|
||||
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
// Type definitions for @ember/debug 3.0
|
||||
// Project: http://emberjs.com/
|
||||
// Definitions by: Mike North <https://github.com/mike-north>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import Ember from 'ember';
|
||||
export const assert: typeof Ember.assert;
|
||||
export const debug: typeof Ember.debug;
|
||||
export const inspect: typeof Ember.inspect;
|
||||
export const registerDeprecationHandler: typeof Ember.Debug.registerDeprecationHandler;
|
||||
export const registerWarnHandler: typeof Ember.Debug.registerWarnHandler;
|
||||
export const runInDebug: typeof Ember.runInDebug;
|
||||
export const warn: typeof Ember.warn;
|
||||
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"paths": {
|
||||
"@ember/debug": ["ember__debug"],
|
||||
"@ember/debug/*": ["ember__debug/*"]
|
||||
},
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"data-adapter.d.ts",
|
||||
"container-debug-adapter.d.ts",
|
||||
"ember__debug-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": { }
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
import Error from '@ember/error';
|
||||
|
||||
new Error('Fuuuuuuuu'); // $ExpectType Error
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
// Type definitions for @ember/error 3.0
|
||||
// Project: http://emberjs.com/
|
||||
// Definitions by: Mike North <https://github.com/mike-north>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import Ember from 'ember';
|
||||
|
||||
declare const Error: typeof Ember.Error;
|
||||
export default Error;
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"paths": {
|
||||
"@ember/error": ["ember__error"]
|
||||
},
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"ember__error-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
}
|
||||
}
|
||||
Vendored
+38
@@ -0,0 +1,38 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
type ComputedProperty<Get, Set = Get> = Ember.ComputedProperty<Get, Set>;
|
||||
declare const ComputedProperty: typeof Ember.ComputedProperty;
|
||||
export default ComputedProperty;
|
||||
export const alias: typeof Ember.computed.alias;
|
||||
export const and: typeof Ember.computed.and;
|
||||
export const bool: typeof Ember.computed.bool;
|
||||
export const collect: typeof Ember.computed.collect;
|
||||
export const deprecatingAlias: typeof Ember.computed.deprecatingAlias;
|
||||
export const empty: typeof Ember.computed.empty;
|
||||
export const equal: typeof Ember.computed.equal;
|
||||
export const expandProperties: typeof Ember.expandProperties;
|
||||
export const filter: typeof Ember.computed.filter;
|
||||
export const filterBy: typeof Ember.computed.filterBy;
|
||||
export const gt: typeof Ember.computed.gt;
|
||||
export const gte: typeof Ember.computed.gte;
|
||||
export const intersect: typeof Ember.computed.intersect;
|
||||
export const lt: typeof Ember.computed.lt;
|
||||
export const lte: typeof Ember.computed.lte;
|
||||
export const map: typeof Ember.computed.map;
|
||||
export const mapBy: typeof Ember.computed.mapBy;
|
||||
export const match: typeof Ember.computed.match;
|
||||
export const max: typeof Ember.computed.max;
|
||||
export const min: typeof Ember.computed.min;
|
||||
export const none: typeof Ember.computed.none;
|
||||
export const not: typeof Ember.computed.not;
|
||||
export const notEmpty: typeof Ember.computed.notEmpty;
|
||||
export const oneWay: typeof Ember.computed.oneWay;
|
||||
export const or: typeof Ember.computed.or;
|
||||
export const readOnly: typeof Ember.computed.readOnly;
|
||||
export const reads: typeof Ember.computed.reads;
|
||||
export const setDiff: typeof Ember.computed.setDiff;
|
||||
export const sort: typeof Ember.computed.sort;
|
||||
export const sum: typeof Ember.computed.sum;
|
||||
export const union: typeof Ember.computed.union;
|
||||
export const uniq: typeof Ember.computed.uniq;
|
||||
export const uniqBy: typeof Ember.computed.uniqBy;
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
export default class CoreObject extends Ember.CoreObject { }
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
type Evented = Ember.Evented;
|
||||
declare const Evented: typeof Ember.Evented;
|
||||
export default Evented;
|
||||
export const on: typeof Ember.on;
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
export const addListener: typeof Ember.addListener;
|
||||
export const removeListener: typeof Ember.removeListener;
|
||||
export const sendEvent: typeof Ember.sendEvent;
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
// Type definitions for @ember/object 3.0
|
||||
// Project: http://emberjs.com/
|
||||
// Definitions by: Mike North <https://github.com/mike-north>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import Ember from 'ember';
|
||||
declare class EmberObject extends Ember.Object { }
|
||||
export default EmberObject;
|
||||
export const aliasMethod: typeof Ember.aliasMethod;
|
||||
export const computed: typeof Ember.computed;
|
||||
export const defineProperty: typeof Ember.defineProperty;
|
||||
export const get: typeof Ember.get;
|
||||
export const getProperties: typeof Ember.getProperties;
|
||||
export const getWithDefault: typeof Ember.getWithDefault;
|
||||
export const observer: typeof Ember.observer;
|
||||
export const set: typeof Ember.set;
|
||||
export const setProperties: typeof Ember.setProperties;
|
||||
export const trySet: typeof Ember.trySet;
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
export const cacheFor: typeof Ember.cacheFor;
|
||||
export const copy: typeof Ember.copy;
|
||||
export const guidFor: typeof Ember.guidFor;
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
export default class Mixin<T, Base = Ember.Object> extends Ember.Mixin<T, Base> {}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
type Observable = Ember.Observable;
|
||||
declare const Observable: typeof Ember.Observable;
|
||||
export default Observable;
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
export const addObserver: typeof Ember.addObserver;
|
||||
export const removeObserver: typeof Ember.removeObserver;
|
||||
@@ -0,0 +1,5 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
type PromiseProxyMixin<T> = Ember.PromiseProxyMixin<T>;
|
||||
declare const PromiseProxyMixin: typeof Ember.PromiseProxyMixin;
|
||||
export default PromiseProxyMixin;
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
export default class ObjectProxy extends Ember.ObjectProxy { }
|
||||
@@ -0,0 +1,21 @@
|
||||
import { assertType } from './lib/assert';
|
||||
import EmberObject from '@ember/object';
|
||||
|
||||
class Foo extends EmberObject {
|
||||
hello() { return 'world'; }
|
||||
protected bar() { return 'bar'; }
|
||||
private baz() { return 'baz'; }
|
||||
}
|
||||
const f = new Foo();
|
||||
assertType<string>(f.hello());
|
||||
assertType<string>(f.bar()); // $ExpectError
|
||||
assertType<string>(f.baz()); // $ExpectError
|
||||
|
||||
// TODO: enable after TS 3.0 https://github.com/typed-ember/ember-cli-typescript/issues/291
|
||||
// class Foo2 extends EmberObject.extend({
|
||||
// bar: ''
|
||||
// }) {
|
||||
// hello() { return 'world'; }
|
||||
// protected bar() { return 'bar'; } // $ExpectError
|
||||
// private baz() { return 'baz'; }
|
||||
// }
|
||||
@@ -0,0 +1,198 @@
|
||||
import EmberObject, { computed } from '@ember/object';
|
||||
import ComputedProperty, {
|
||||
alias,
|
||||
or,
|
||||
and,
|
||||
filter,
|
||||
equal,
|
||||
empty,
|
||||
filterBy,
|
||||
notEmpty,
|
||||
none,
|
||||
not,
|
||||
min,
|
||||
max,
|
||||
gt,
|
||||
gte,
|
||||
lt,
|
||||
lte,
|
||||
readOnly,
|
||||
reads,
|
||||
setDiff,
|
||||
sort,
|
||||
intersect,
|
||||
mapBy,
|
||||
match,
|
||||
map,
|
||||
oneWay,
|
||||
sum,
|
||||
union,
|
||||
uniqBy,
|
||||
uniq,
|
||||
deprecatingAlias,
|
||||
bool,
|
||||
collect
|
||||
} from '@ember/object/computed';
|
||||
import { assertType } from './lib/assert';
|
||||
|
||||
const Person = EmberObject.extend({
|
||||
firstName: '',
|
||||
lastName: '',
|
||||
age: 0,
|
||||
|
||||
noArgs: computed<string>(() => 'test'),
|
||||
|
||||
fullName: computed<string>('firstName', 'lastName', function() {
|
||||
return `${this.get('firstName')} ${this.get('lastName')}`;
|
||||
}),
|
||||
|
||||
fullNameReadonly: computed<string>('fullName', function() {
|
||||
return this.get('fullName');
|
||||
}).readOnly(),
|
||||
|
||||
fullNameWritable: computed<string>('firstName', 'lastName', {
|
||||
get() {
|
||||
return this.get('fullName');
|
||||
},
|
||||
set(key, value) {
|
||||
const [first, last] = value.split(' ');
|
||||
this.set('firstName', first);
|
||||
this.set('lastName', last);
|
||||
return value;
|
||||
}
|
||||
}),
|
||||
|
||||
fullNameGetOnly: computed<string>('fullName', {
|
||||
get() {
|
||||
return this.get('fullName');
|
||||
}
|
||||
}),
|
||||
|
||||
fullNameSetOnly: computed<string>('firstName', 'lastName', {
|
||||
set(key, value) {
|
||||
const [first, last] = value.split(' ');
|
||||
this.set('firstName', first);
|
||||
this.set('lastName', last);
|
||||
return value;
|
||||
}
|
||||
}),
|
||||
|
||||
combinators: computed<string>(function() {
|
||||
return this.get('firstName');
|
||||
}).property('firstName')
|
||||
.meta({ foo: 'bar' })
|
||||
.volatile()
|
||||
.readOnly(),
|
||||
|
||||
explicitlyDeclared: alias('fullName') as ComputedProperty<string>,
|
||||
});
|
||||
|
||||
const person = Person.create({
|
||||
firstName: 'Fred',
|
||||
lastName: 'Smith',
|
||||
age: 29,
|
||||
});
|
||||
|
||||
assertType<string>(person.firstName);
|
||||
assertType<number>(person.age);
|
||||
assertType<ComputedProperty<string>>(person.noArgs);
|
||||
assertType<ComputedProperty<string>>(person.fullName);
|
||||
assertType<ComputedProperty<string>>(person.fullNameReadonly);
|
||||
assertType<ComputedProperty<string>>(person.fullNameWritable);
|
||||
assertType<ComputedProperty<string>>(person.fullNameGetOnly);
|
||||
assertType<ComputedProperty<string>>(person.fullNameSetOnly);
|
||||
assertType<ComputedProperty<string>>(person.combinators);
|
||||
assertType<ComputedProperty<string>>(person.explicitlyDeclared);
|
||||
|
||||
assertType<string>(person.get('firstName'));
|
||||
assertType<number>(person.get('age'));
|
||||
assertType<string>(person.get('noArgs'));
|
||||
assertType<string>(person.get('fullName'));
|
||||
assertType<string>(person.get('fullNameReadonly'));
|
||||
assertType<string>(person.get('fullNameWritable'));
|
||||
assertType<string>(person.get('fullNameGetOnly'));
|
||||
assertType<string>(person.get('fullNameSetOnly'));
|
||||
assertType<string>(person.get('combinators'));
|
||||
assertType<string>(person.get('explicitlyDeclared'));
|
||||
|
||||
assertType<{ firstName: string, fullName: string, age: number }>(person.getProperties('firstName', 'fullName', 'age'));
|
||||
|
||||
const person2 = Person.create({
|
||||
fullName: 'Fred Smith'
|
||||
});
|
||||
|
||||
assertType<string>(person2.get('firstName'));
|
||||
assertType<string>(person2.get('fullName'));
|
||||
|
||||
const person3 = Person.extend({
|
||||
firstName: 'Fred',
|
||||
fullName: 'Fred Smith'
|
||||
}).create();
|
||||
|
||||
assertType<string>(person3.get('firstName'));
|
||||
assertType<string>(person3.get('fullName'));
|
||||
|
||||
const person4 = Person.extend({
|
||||
firstName: computed(() => 'Fred'),
|
||||
fullName: computed(() => 'Fred Smith')
|
||||
}).create();
|
||||
|
||||
assertType<string>(person4.get('firstName'));
|
||||
assertType<string>(person4.get('fullName'));
|
||||
|
||||
// computed property macros
|
||||
const objectWithComputedProperties = EmberObject.extend({
|
||||
alias: alias('foo'),
|
||||
and: and('foo', 'bar', 'baz', 'qux'),
|
||||
bool: bool('foo'),
|
||||
collect: collect('foo', 'bar', 'baz', 'qux'),
|
||||
deprecatingAlias: deprecatingAlias('foo', {
|
||||
id: 'hamster.deprecate-banana',
|
||||
until: '3.0.0'
|
||||
}),
|
||||
empty: empty('foo'),
|
||||
equalNumber: equal('foo', 1),
|
||||
equalString: equal('foo', 'bar'),
|
||||
equalObject: equal('foo', {}),
|
||||
filter: filter('foo', (item) => item === 'bar'),
|
||||
filterBy1: filterBy('foo', 'bar'),
|
||||
filterBy2: filterBy('foo', 'bar', false),
|
||||
gt: gt('foo', 3),
|
||||
gte: gte('foo', 3),
|
||||
intersect: intersect('foo', 'bar', 'baz', 'qux'),
|
||||
lt: lt('foo', 3),
|
||||
lte: lte('foo', 3),
|
||||
map: map('foo', (item, index) => item.bar),
|
||||
mapBy: mapBy('foo', 'bar'),
|
||||
match: match('foo', /^tom.ter$/),
|
||||
max: max('foo'),
|
||||
min: min('foo'),
|
||||
none: none('foo'),
|
||||
not: not('foo'),
|
||||
notEmpty: notEmpty('foo'),
|
||||
oneWay: oneWay('foo'),
|
||||
or: or('foo', 'bar', 'baz', 'qux'),
|
||||
readOnly: readOnly('foo'),
|
||||
reads: reads('foo'),
|
||||
setDiff: setDiff('foo', 'bar'),
|
||||
sort1: sort('foo', 'bar'),
|
||||
sort2: sort('foo', (itemA, itemB) => {
|
||||
if (itemA < itemB) {
|
||||
return -1;
|
||||
} else if (itemA > itemB) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}),
|
||||
sum: sum('foo'),
|
||||
union: union('foo', 'bar', 'baz', 'qux'),
|
||||
uniq: uniq('foo'),
|
||||
uniqBy: uniqBy('foo', 'bar')
|
||||
});
|
||||
|
||||
const component2 = EmberObject.extend({
|
||||
isAnimal: or('isDog', 'isCat')
|
||||
}).create();
|
||||
|
||||
assertType<boolean>(component2.get('isAnimal'));
|
||||
@@ -0,0 +1,198 @@
|
||||
import Ember from 'ember';
|
||||
import { assertType } from './lib/assert';
|
||||
|
||||
/** Newable tests */
|
||||
const co1 = new Ember.CoreObject();
|
||||
|
||||
// TODO: Enable in TS 3.0 see: https://github.com/typed-ember/ember-cli-typescript/issues/291
|
||||
// co1.concatenatedProperties; // $ExpectType string[]
|
||||
co1.isDestroyed; // $ExpectType boolean
|
||||
co1.isDestroying; // $ExpectType boolean
|
||||
co1.destroy(); // $ExpectType CoreObject
|
||||
co1.toString(); // $ExpectType string
|
||||
|
||||
/** .create tests */
|
||||
const co2 = Ember.CoreObject.create();
|
||||
// TODO: Enable in TS 3.0 see: https://github.com/typed-ember/ember-cli-typescript/issues/291
|
||||
// co2.concatenatedProperties; // $ExpectType string[]
|
||||
co2.isDestroyed; // $ExpectType boolean
|
||||
co2.isDestroying; // $ExpectType boolean
|
||||
co2.destroy(); // $ExpectType CoreObject
|
||||
co2.toString(); // $ExpectType string
|
||||
|
||||
/** .create tests w/ initial instance data passed in */
|
||||
const co3 = Ember.CoreObject.create({ foo: '123', bar: 456 });
|
||||
|
||||
co3.foo; // $ExpectType string
|
||||
co3.bar; // $ExpectType number
|
||||
|
||||
/** .extend with a zero-argument .create() */
|
||||
const co4 = Ember.CoreObject.extend({
|
||||
foo: '123',
|
||||
bar: 456,
|
||||
baz(): [string, number] {
|
||||
return [this.foo, this.bar];
|
||||
}
|
||||
}).create();
|
||||
|
||||
co4.foo; // $ExpectType string
|
||||
co4.bar; // $ExpectType number
|
||||
co4.baz; // $ExpectType () => [string, number]
|
||||
|
||||
/** .extend with inconsistent arguments passed into .create() */
|
||||
const class05 = Ember.CoreObject.extend({
|
||||
foo: '123' as (string | boolean),
|
||||
bar: 456,
|
||||
baz() {
|
||||
return [this.foo, this.bar];
|
||||
}
|
||||
});
|
||||
const c05 = class05.create({ foo: 99 }); // $ExpectError
|
||||
const c05b = class05.create({ foo: true });
|
||||
const c05c = class05.create({ foo: 'abc' });
|
||||
assertType<string>(c05b.foo); // $ExpectError
|
||||
assertType<boolean>(c05c.foo); // $ExpectError
|
||||
|
||||
/** two .extend arguments with a zero-argument .create() */
|
||||
const co6 = Ember.CoreObject.extend({
|
||||
foo: '123',
|
||||
bar: 456,
|
||||
baz() {
|
||||
return [this.foo, this.bar];
|
||||
},
|
||||
func1() {
|
||||
// this includes stuff from CoreObject
|
||||
this.init; // $ExpectType () => void
|
||||
// this includes stuff from this extend-arg
|
||||
this.foo; // $ExpectType string
|
||||
// this does not include stuff from later extend args
|
||||
this.bee; // $ExpectError
|
||||
}
|
||||
}, {
|
||||
foo: 99,
|
||||
bee: 'honey',
|
||||
func2() {
|
||||
// this includes stuff from CoreObject
|
||||
this.init; // $ExpectType () => void
|
||||
// this includes stuff from this extend-arg
|
||||
// TODO: switch to "$ExpectType number" in TS 3.0 see: https://github.com/typed-ember/ember-cli-typescript/issues/291
|
||||
this.foo; // $ExpectType string & number
|
||||
// this includes stuff from earlier extend-args
|
||||
this.bar; // $ExpectType number
|
||||
}
|
||||
}).create();
|
||||
|
||||
// TODO: enable in TS 3.0 see: https://github.com/typed-ember/ember-cli-typescript/issues/291
|
||||
// assertType<string>(co6.foo); // $ExpectError
|
||||
assertType<number>(co6.bar); // $ExpectType number
|
||||
assertType<() => Array<string | number>>(co6.baz); // $ExpectType () => (string | number)[]
|
||||
|
||||
/** three .extend arguments with a zero-argument .create() */
|
||||
const co7 = Ember.CoreObject.extend({
|
||||
foo: '123',
|
||||
bar: 456,
|
||||
baz() {
|
||||
return [this.foo, this.bar];
|
||||
},
|
||||
func1() {
|
||||
// this includes stuff from CoreObject
|
||||
this.init; // $ExpectType () => void
|
||||
// this includes stuff from this extend-arg
|
||||
this.foo; // $ExpectType string
|
||||
// this does not include stuff from later extend args
|
||||
this.bee; // $ExpectError
|
||||
}
|
||||
}, {
|
||||
foo: 99,
|
||||
bee: 'honey',
|
||||
func2() {
|
||||
// this includes stuff from CoreObject
|
||||
this.init; // $ExpectType () => void
|
||||
// this includes stuff from this extend-arg
|
||||
// TODO: switch to "$ExpectType number" in TS 3.0 see: https://github.com/typed-ember/ember-cli-typescript/issues/291
|
||||
this.foo; // $ExpectType string & number
|
||||
// this includes stuff from earlier extend-args
|
||||
this.bar; // $ExpectType number
|
||||
}
|
||||
}, {
|
||||
foo: '99',
|
||||
money: 'in the banana stand',
|
||||
func3() {
|
||||
// this includes stuff from CoreObject
|
||||
this.init; // $ExpectType () => void
|
||||
// this includes stuff from this extend-arg
|
||||
this.money; // $ExpectType string
|
||||
// this includes stuff from earlier extend-args
|
||||
this.bee; // $ExpectType string
|
||||
this.bar; // $ExpectType number
|
||||
}
|
||||
}).create();
|
||||
// TODO: enable in TS 3.0 see: https://github.com/typed-ember/ember-cli-typescript/issues/291
|
||||
// assertType<number>(co7.foo); // $ExpectError
|
||||
assertType<number>(co7.bar); // $ExpectType number
|
||||
assertType<string>(co7.money); // $ExpectType string
|
||||
assertType<() => Array<string | number>>(co7.baz); // $ExpectType () => (string | number)[]
|
||||
|
||||
/** four .extend arguments with a zero-argument .create() */
|
||||
const co8 = Ember.CoreObject.extend({
|
||||
foo: '123',
|
||||
bar: 456,
|
||||
baz() {
|
||||
return [this.foo, this.bar];
|
||||
},
|
||||
func1() {
|
||||
// this includes stuff from CoreObject
|
||||
this.init; // $ExpectType () => void
|
||||
// this includes stuff from this extend-arg
|
||||
this.foo; // $ExpectType string
|
||||
// this does not include stuff from later extend args
|
||||
this.bee; // $ExpectError
|
||||
}
|
||||
}, {
|
||||
foo: 99,
|
||||
bee: 'honey',
|
||||
func2() {
|
||||
// this includes stuff from CoreObject
|
||||
this.init; // $ExpectType () => void
|
||||
// this includes stuff from this extend-arg
|
||||
// TODO: switch to "$ExpectType number" in TS 3.0 see: https://github.com/typed-ember/ember-cli-typescript/issues/291
|
||||
this.foo; // $ExpectType string & number
|
||||
// this includes stuff from earlier extend-args
|
||||
this.bar; // $ExpectType number
|
||||
// this does not include stuff from later extend args
|
||||
this.money; // $ExpectError
|
||||
}
|
||||
}, {
|
||||
foo: '99',
|
||||
money: 'in the banana stand',
|
||||
func3() {
|
||||
// this includes stuff from CoreObject
|
||||
this.init; // $ExpectType () => void
|
||||
// this includes stuff from this extend-arg
|
||||
this.money; // $ExpectType string
|
||||
// this includes stuff from earlier extend-args
|
||||
this.bee; // $ExpectType string
|
||||
this.bar; // $ExpectType number
|
||||
// this does not include stuff from later extend args
|
||||
this.neighborhood; // $ExpectError
|
||||
}
|
||||
}, {
|
||||
foo: '99',
|
||||
neighborhood: 'sudden valley',
|
||||
func4() {
|
||||
// this includes stuff from CoreObject
|
||||
this.init; // $ExpectType () => void
|
||||
// this includes stuff from this extend-arg
|
||||
this.neighborhood; // $ExpectType string
|
||||
// this includes stuff from earlier extend-args
|
||||
this.bee; // $ExpectType string
|
||||
this.bar; // $ExpectType number
|
||||
this.money; // $ExpectType string
|
||||
}
|
||||
}).create();
|
||||
|
||||
// TODO: enable in TS 3.0 see: https://github.com/typed-ember/ember-cli-typescript/issues/291
|
||||
// assertType<number>(co8.foo); // $ExpectError
|
||||
assertType<number>(co8.bar); // $ExpectType number
|
||||
assertType<string>(co8.money); // $ExpectType string
|
||||
assertType<() => Array<string | number>>(co8.baz); // $ExpectType () => (string | number)[]
|
||||
@@ -0,0 +1,9 @@
|
||||
import { assertType } from './lib/assert';
|
||||
import Ember from 'ember';
|
||||
import { PersonWithNumberName, Person } from './create';
|
||||
|
||||
Person.create({ firstName: 99 }); // $ExpectError
|
||||
Person.create({}, { firstName: 99 }); // $ExpectError
|
||||
Person.create({}, {}, { firstName: 99 }); // $ExpectError
|
||||
|
||||
const p4 = new PersonWithNumberName();
|
||||
@@ -0,0 +1,54 @@
|
||||
import { assertType } from './lib/assert';
|
||||
import EmberObject, { computed } from '@ember/object';
|
||||
import ComputedProperty from '@ember/object/computed';
|
||||
|
||||
/**
|
||||
* Zero-argument case
|
||||
*/
|
||||
const o = EmberObject.create();
|
||||
// create returns an object
|
||||
assertType<object>(o);
|
||||
// object returned by create type-checks as an instance of Ember.Object
|
||||
assertType<boolean>(o.isDestroyed); // from instance
|
||||
assertType<boolean>(o.isDestroying); // from instance
|
||||
assertType<(key: keyof EmberObject) => any>(o.get); // from prototype
|
||||
|
||||
/**
|
||||
* One-argument case
|
||||
*/
|
||||
const o1 = EmberObject.create({x: 9, y: 'hello', z: false});
|
||||
assertType<number>(o1.x);
|
||||
assertType<string>(o1.y);
|
||||
o1.y; // $ExpectType string
|
||||
o1.z; // $ExpectType boolean
|
||||
|
||||
const obj = EmberObject.create({ a: 1 }, { b: 2 }, { c: 3 });
|
||||
assertType<number>(obj.b);
|
||||
assertType<number>(obj.a);
|
||||
assertType<number>(obj.c);
|
||||
|
||||
export class Person extends EmberObject {
|
||||
fullName = computed('firstName', 'lastName', function() {
|
||||
return [this.firstName + this.lastName].join(' ');
|
||||
});
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
age: number;
|
||||
}
|
||||
const p = new Person();
|
||||
|
||||
assertType<string>(p.firstName);
|
||||
assertType<ComputedProperty<string>>(p.fullName);
|
||||
assertType<string>(p.get('fullName'));
|
||||
|
||||
const p2 = Person.create({ firstName: 'string' });
|
||||
const p2b = Person.create({}, { firstName: 'string' });
|
||||
const p2c = Person.create({}, {}, { firstName: 'string' });
|
||||
|
||||
export class PersonWithNumberName extends Person.extend({
|
||||
fullName: 6
|
||||
}) {}
|
||||
|
||||
const p4 = new PersonWithNumberName();
|
||||
assertType<string>(p4.firstName);
|
||||
assertType<number>(p4.fullName);
|
||||
Executable
+20
@@ -0,0 +1,20 @@
|
||||
import { assertType } from './lib/assert';
|
||||
import EmberObject from '@ember/object';
|
||||
|
||||
const ExtendClass = EmberObject.extend({
|
||||
foo: 'hello'
|
||||
});
|
||||
|
||||
class ES6Class extends EmberObject {
|
||||
bar: string;
|
||||
}
|
||||
|
||||
const testObject = null;
|
||||
|
||||
if (ExtendClass.detectInstance(testObject)) {
|
||||
assertType<string>(testObject.foo);
|
||||
}
|
||||
|
||||
if (ES6Class.detectInstance(testObject)) {
|
||||
assertType<string>(testObject.bar);
|
||||
}
|
||||
Executable
+20
@@ -0,0 +1,20 @@
|
||||
import { assertType } from './lib/assert';
|
||||
import EmberObject from '@ember/object';
|
||||
|
||||
const ExtendClass = EmberObject.extend({
|
||||
foo: 'hello'
|
||||
});
|
||||
|
||||
class ES6Class extends EmberObject {
|
||||
bar: string;
|
||||
}
|
||||
|
||||
const TestClass = EmberObject;
|
||||
|
||||
if (ExtendClass.detect(TestClass)) {
|
||||
assertType<string>(TestClass.create().foo);
|
||||
}
|
||||
|
||||
if (ES6Class.detect(TestClass)) {
|
||||
assertType<string>(TestClass.create().bar);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import EmberObject, { observer } from '@ember/object';
|
||||
import { sendEvent, addListener, removeListener } from '@ember/object/events';
|
||||
import Evented, { on } from '@ember/object/evented';
|
||||
|
||||
function testOn() {
|
||||
const Job = EmberObject.extend({
|
||||
logCompleted: on('completed', () => {
|
||||
console.log('Job completed!');
|
||||
})
|
||||
});
|
||||
|
||||
const job = Job.create();
|
||||
|
||||
sendEvent(job, 'completed'); // Logs 'Job completed!'
|
||||
}
|
||||
|
||||
function testEvented() {
|
||||
const Person = EmberObject.extend(Evented, {
|
||||
greet() {
|
||||
this.trigger('greet');
|
||||
}
|
||||
});
|
||||
|
||||
const person = Person.create();
|
||||
|
||||
person.on('greet', () => {
|
||||
console.log('Our person has greeted');
|
||||
});
|
||||
|
||||
person.on('greet', () => {
|
||||
console.log('Our person has greeted');
|
||||
}).one('greet', () => {
|
||||
console.log('Offer one-time special');
|
||||
}).off('event', {}, () => {});
|
||||
|
||||
person.greet();
|
||||
}
|
||||
|
||||
function testObserver() {
|
||||
EmberObject.extend({
|
||||
// TODO: enable after https://github.com/typed-ember/ember-cli-typescript/issues/290
|
||||
// valueObserver: observer('value', () => {
|
||||
// // Executes whenever the "value" property changes
|
||||
// })
|
||||
});
|
||||
}
|
||||
|
||||
function testListener() {
|
||||
EmberObject.extend({
|
||||
init() {
|
||||
addListener(this, 'willDestroy', this, 'willDestroyListener');
|
||||
addListener(this, 'willDestroy', this, 'willDestroyListener', true);
|
||||
addListener(this, 'willDestroy', this, this.willDestroyListener);
|
||||
addListener(this, 'willDestroy', this, this.willDestroyListener, true);
|
||||
removeListener(this, 'willDestroy', this, 'willDestroyListener');
|
||||
removeListener(this, 'willDestroy', this, this.willDestroyListener);
|
||||
},
|
||||
willDestroyListener() {
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import EmberObject from '@ember/object';
|
||||
import { assertType } from './lib/assert';
|
||||
|
||||
const Person = EmberObject.extend({
|
||||
firstName: '',
|
||||
lastName: '',
|
||||
|
||||
getFullName() {
|
||||
return `${this.firstName} ${this.lastName}`;
|
||||
},
|
||||
getFullName2(): string {
|
||||
return `${this.get('firstName')} ${this.get('lastName')}`;
|
||||
}
|
||||
});
|
||||
|
||||
assertType<string>(Person.prototype.firstName);
|
||||
assertType<() => string>(Person.prototype.getFullName);
|
||||
|
||||
const person = Person.create({
|
||||
firstName: 'Joe',
|
||||
lastName: 'Blow',
|
||||
extra: 42
|
||||
});
|
||||
|
||||
assertType<string>(person.getFullName());
|
||||
assertType<number>(person.extra);
|
||||
|
||||
class ES6Person extends EmberObject {
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
|
||||
get fullName() {
|
||||
return `${this.firstName} ${this.lastName}`;
|
||||
}
|
||||
get fullName2(): string {
|
||||
return `${this.get('firstName')} ${this.get('lastName')}`;
|
||||
}
|
||||
}
|
||||
|
||||
assertType<string>(ES6Person.prototype.firstName);
|
||||
assertType<string>(ES6Person.prototype.fullName);
|
||||
|
||||
const es6Person = ES6Person.create({
|
||||
firstName: 'Joe',
|
||||
lastName: 'Blow',
|
||||
extra: 42
|
||||
});
|
||||
|
||||
assertType<string>(es6Person.fullName);
|
||||
assertType<number>(es6Person.extra);
|
||||
|
||||
class PersonWithStatics extends EmberObject {
|
||||
static isPerson = true;
|
||||
}
|
||||
const PersonWithStatics2 = PersonWithStatics.extend({});
|
||||
class PersonWithStatics3 extends PersonWithStatics {}
|
||||
class PersonWithStatics4 extends PersonWithStatics2 {}
|
||||
assertType<boolean>(PersonWithStatics.isPerson);
|
||||
assertType<boolean>(PersonWithStatics2.isPerson);
|
||||
assertType<boolean>(PersonWithStatics3.isPerson);
|
||||
assertType<boolean>(PersonWithStatics4.isPerson);
|
||||
@@ -0,0 +1,5 @@
|
||||
/** Static assertion that `value` has type `T` */
|
||||
// Disable tslint here b/c the generic is used to let us do a type coercion and
|
||||
// validate that coercion works for the type value "passed into" the function.
|
||||
// tslint:disable-next-line:no-unnecessary-generics
|
||||
export declare function assertType<T>(value: T): T;
|
||||
@@ -0,0 +1,75 @@
|
||||
import EmberObject, { computed } from "@ember/object";
|
||||
|
||||
const LifetimeHooks = EmberObject.extend({
|
||||
resource: null as {} | null,
|
||||
|
||||
init() {
|
||||
this._super();
|
||||
this.resource = {};
|
||||
},
|
||||
|
||||
willDestroy() {
|
||||
delete this.resource;
|
||||
this._super();
|
||||
}
|
||||
});
|
||||
|
||||
class MyObject30 extends EmberObject {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
class MyObject31 extends EmberObject {
|
||||
constructor(properties: object) {
|
||||
super(properties);
|
||||
}
|
||||
}
|
||||
|
||||
class Foo extends EmberObject {
|
||||
a = computed({
|
||||
get() { return ''; },
|
||||
set(key: string, newVal: string) { return ''; }
|
||||
});
|
||||
b = 5;
|
||||
baz() {
|
||||
const y = this.b; // $ExpectType number
|
||||
const z = this.a; // $ExpectType ComputedProperty<string, string>
|
||||
this.b = 10;
|
||||
this.get('b').toFixed(4); // $ExpectType string
|
||||
this.set('a', 'abc').split(','); // $ExpectType string[]
|
||||
this.set('b', 10).toFixed(4); // $ExpectType string
|
||||
|
||||
this.setProperties({ b: 11 });
|
||||
// this.setProperties({ b: '11' }); // $ExpectError
|
||||
this.setProperties({
|
||||
a: 'def',
|
||||
b: 11
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: enable after TS 3.0 https://github.com/typed-ember/ember-cli-typescript/issues/291
|
||||
// class Foo extends EmberObject.extend({
|
||||
// a: computed({
|
||||
// get() { return ''; },
|
||||
// set(key: string, newVal: string) { return ''; }
|
||||
// })
|
||||
// }) {
|
||||
// b = 5;
|
||||
// baz() {
|
||||
// const y = this.b; // $ExpectType number
|
||||
// const z = this.a; // $ExpectType ComputedProperty<string, string>
|
||||
// this.b = 10;
|
||||
// this.get('b').toFixed(4); // $ExpectType string
|
||||
// this.set('a', 'abc').split(','); // $ExpectType string[]
|
||||
// this.set('b', 10).toFixed(4); // $ExpectType string
|
||||
|
||||
// this.setProperties({ b: 11 });
|
||||
// // this.setProperties({ b: '11' }); // $ExpectError
|
||||
// this.setProperties({
|
||||
// a: 'def',
|
||||
// b: 11
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
@@ -0,0 +1,114 @@
|
||||
import { assertType } from './lib/assert';
|
||||
import EmberObject, { computed, getWithDefault, getProperties, get, setProperties, set } from '@ember/object';
|
||||
import { removeObserver, addObserver } from '@ember/object/observers';
|
||||
|
||||
class MyComponent extends EmberObject {
|
||||
foo = 'bar';
|
||||
|
||||
init() {
|
||||
this._super.apply(this, arguments);
|
||||
this.addObserver('foo', this, 'fooDidChange');
|
||||
this.addObserver('foo', this, this.fooDidChange);
|
||||
addObserver(this, 'foo', this, 'fooDidChange');
|
||||
addObserver(this, 'foo', this, this.fooDidChange);
|
||||
this.removeObserver('foo', this, 'fooDidChange');
|
||||
this.removeObserver('foo', this, this.fooDidChange);
|
||||
removeObserver(this, 'foo', this, 'fooDidChange');
|
||||
removeObserver(this, 'foo', this, this.fooDidChange);
|
||||
const lambda = () => {
|
||||
this.fooDidChange(this, 'foo');
|
||||
};
|
||||
this.addObserver('foo', lambda);
|
||||
this.removeObserver('foo', lambda);
|
||||
addObserver(this, 'foo', lambda);
|
||||
removeObserver(this, 'foo', lambda);
|
||||
}
|
||||
|
||||
fooDidChange(sender: this, key: keyof this) {
|
||||
// your code
|
||||
}
|
||||
}
|
||||
|
||||
const myComponent = MyComponent.create();
|
||||
myComponent.addObserver('foo', null, () => {});
|
||||
myComponent.set('foo', 'baz');
|
||||
|
||||
const person = EmberObject.create({
|
||||
name: 'Fred',
|
||||
age: 29,
|
||||
capitalized: computed<string>(function() {
|
||||
return this.get('name').toUpperCase();
|
||||
})
|
||||
});
|
||||
|
||||
const pojo = { name: 'Fred', age: 29 };
|
||||
|
||||
function testGet() {
|
||||
assertType<string>(get(person, 'name'));
|
||||
assertType<number>(get(person, 'age'));
|
||||
assertType<string>(get(person, 'capitalized'));
|
||||
assertType<string>(person.get('name'));
|
||||
assertType<number>(person.get('age'));
|
||||
assertType<string>(person.get('capitalized'));
|
||||
assertType<string>(get(pojo, 'name'));
|
||||
}
|
||||
|
||||
function testGetProperties() {
|
||||
assertType<{ name: string }>(getProperties(person, 'name'));
|
||||
assertType<{ name: string, age: number }>(getProperties(person, 'name', 'age'));
|
||||
assertType<{ name: string, age: number }>(getProperties(person, [ 'name', 'age' ]));
|
||||
assertType<{ name: string, age: number, capitalized: string }>(getProperties(person, 'name', 'age', 'capitalized'));
|
||||
assertType<{ name: string }>(person.getProperties('name'));
|
||||
assertType<{ name: string, age: number }>(person.getProperties('name', 'age'));
|
||||
assertType<{ name: string, age: number }>(person.getProperties([ 'name', 'age' ]));
|
||||
assertType<{ name: string, age: number, capitalized: string }>(person.getProperties('name', 'age', 'capitalized'));
|
||||
assertType<{ name: string, age: number }>(getProperties(pojo, 'name', 'age'));
|
||||
}
|
||||
|
||||
function testGetWithDefault() {
|
||||
assertType<string>(getWithDefault(person, 'name', 'Joe'));
|
||||
assertType<number>(getWithDefault(person, 'age', 20));
|
||||
assertType<string>(getWithDefault(person, 'capitalized', 'JOE'));
|
||||
assertType<string>(person.getWithDefault('name', 'Joe'));
|
||||
assertType<number>(person.getWithDefault('age', 20));
|
||||
assertType<string>(person.getWithDefault('capitalized', 'JOE'));
|
||||
assertType<string>(getWithDefault(pojo, 'name', 'JOE'));
|
||||
}
|
||||
|
||||
function testSet() {
|
||||
assertType<string>(set(person, 'name', 'Joe'));
|
||||
assertType<number>(set(person, 'age', 35));
|
||||
assertType<string>(set(person, 'capitalized', 'JOE'));
|
||||
assertType<string>(person.set('name', 'Joe'));
|
||||
assertType<number>(person.set('age', 35));
|
||||
assertType<string>(person.set('capitalized', 'JOE'));
|
||||
assertType<string>(set(pojo, 'name', 'Joe'));
|
||||
}
|
||||
|
||||
function testSetProperties() {
|
||||
assertType<{ name: string }>(setProperties(person, { name: 'Joe' }));
|
||||
assertType<{ name: string, age: number }>(setProperties(person, { name: 'Joe', age: 35 }));
|
||||
assertType<{ name: string, capitalized: string }>(setProperties(person, { name: 'Joe', capitalized: 'JOE' }));
|
||||
assertType<{ name: string }>(person.setProperties({ name: 'Joe' }));
|
||||
assertType<{ name: string, age: number }>(person.setProperties({ name: 'Joe', age: 35 }));
|
||||
assertType<{ name: string, capitalized: string }>(person.setProperties({ name: 'Joe', capitalized: 'JOE' }));
|
||||
assertType<{ name: string, age: number }>(setProperties(pojo, { name: 'Joe', age: 35 }));
|
||||
}
|
||||
|
||||
function testDynamic() {
|
||||
const obj: any = {};
|
||||
const dynamicKey: string = 'dummy'; // tslint:disable-line:no-inferrable-types
|
||||
|
||||
assertType<any>(get(obj, 'dummy'));
|
||||
assertType<any>(get(obj, dynamicKey));
|
||||
assertType<string>(getWithDefault(obj, 'dummy', 'default'));
|
||||
assertType<string>(getWithDefault(obj, dynamicKey, 'default'));
|
||||
assertType<{ dummy: any }>(getProperties(obj, 'dummy'));
|
||||
assertType<{ dummy: any }>(getProperties(obj, [ 'dummy' ]));
|
||||
assertType<object>(getProperties(obj, dynamicKey));
|
||||
assertType<object>(getProperties(obj, [ dynamicKey ]));
|
||||
assertType<string>(set(obj, 'dummy', 'value'));
|
||||
assertType<string>(set(obj, dynamicKey, 'value'));
|
||||
assertType<{ dummy: string }>(setProperties(obj, { dummy: 'value '}));
|
||||
assertType<object>(setProperties(obj, { [dynamicKey]: 'value' }));
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import { assertType } from "./lib/assert";
|
||||
import EmberObject from "@ember/object";
|
||||
import Mixin from "@ember/object/mixin";
|
||||
|
||||
type Person = typeof Person.prototype;
|
||||
const Person = EmberObject.extend({
|
||||
name: '',
|
||||
sayHello() {
|
||||
alert(`Hello. My name is ${this.get('name')}`);
|
||||
}
|
||||
});
|
||||
|
||||
assertType<Person>(Person.reopen());
|
||||
|
||||
assertType<string>(Person.create().name);
|
||||
// tslint:disable-next-line no-void-expression
|
||||
assertType<void>(Person.create().sayHello());
|
||||
|
||||
const Person2 = Person.reopenClass({
|
||||
species: 'Homo sapiens',
|
||||
|
||||
createPerson(name: string): Person {
|
||||
return Person.create({ name });
|
||||
}
|
||||
});
|
||||
|
||||
assertType<string>(Person2.create().name);
|
||||
// tslint:disable-next-line no-void-expression
|
||||
assertType<void>(Person2.create().sayHello());
|
||||
assertType<string>(Person2.species);
|
||||
|
||||
const tom = Person2.create({
|
||||
name: 'Tom Dale'
|
||||
});
|
||||
|
||||
const badTom = Person2.create({ name: 99 }); // $ExpectError
|
||||
|
||||
const yehuda = Person2.createPerson('Yehuda Katz');
|
||||
|
||||
tom.sayHello(); // "Hello. My name is Tom Dale"
|
||||
yehuda.sayHello(); // "Hello. My name is Yehuda Katz"
|
||||
alert(Person2.species); // "Homo sapiens"
|
||||
|
||||
const Person3 = Person2.reopen({
|
||||
goodbyeMessage: 'goodbye',
|
||||
|
||||
sayGoodbye() {
|
||||
alert(`${this.get('goodbyeMessage')}, ${this.get('name')}`);
|
||||
}
|
||||
});
|
||||
|
||||
const person3 = Person3.create();
|
||||
person3.get('name');
|
||||
person3.get('goodbyeMessage');
|
||||
person3.sayHello();
|
||||
person3.sayGoodbye();
|
||||
|
||||
interface AutoResizeMixin { resizable: true; }
|
||||
declare const AutoResizeMixin: Mixin<AutoResizeMixin>;
|
||||
|
||||
const ResizableTextArea = EmberObject.reopen(AutoResizeMixin, {
|
||||
scaling: 1.0
|
||||
});
|
||||
const text = ResizableTextArea.create();
|
||||
// TODO fix upstream
|
||||
// assertType<boolean>(text.resizable);
|
||||
assertType<number>(text.scaling);
|
||||
|
||||
const Reopened = EmberObject.reopenClass({ a: 1 }, { b: 2 }, { c: 3 });
|
||||
assertType<number>(Reopened.a);
|
||||
assertType<number>(Reopened.b);
|
||||
assertType<number>(Reopened.c);
|
||||
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"paths": {
|
||||
"@ember/object": ["ember__object"],
|
||||
"@ember/object/*": ["ember__object/*"]
|
||||
},
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"computed.d.ts",
|
||||
"core.d.ts",
|
||||
"evented.d.ts",
|
||||
"events.d.ts",
|
||||
"index.d.ts",
|
||||
"internals.d.ts",
|
||||
"mixin.d.ts",
|
||||
"observable.d.ts",
|
||||
"observers.d.ts",
|
||||
"promise-proxy-mixin.d.ts",
|
||||
"proxy.d.ts",
|
||||
"test/lib/assert.ts",
|
||||
"test/access-modifier.ts",
|
||||
"test/core.ts",
|
||||
"test/computed.ts",
|
||||
"test/create.ts",
|
||||
"test/create-negative.ts",
|
||||
"test/detect.ts",
|
||||
"test/detect-instance.ts",
|
||||
"test/event.ts",
|
||||
"test/extend.ts",
|
||||
"test/object.ts",
|
||||
"test/observable.ts",
|
||||
"test/reopen.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": { }
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { assign, merge } from '@ember/polyfills';
|
||||
|
||||
(() => { /* assign */
|
||||
assign({}, { a: 'b'});
|
||||
assign({}, { a: 'b'}).a; // $ExpectType string
|
||||
assign({ a: 6 }, { a: 'b'}).a; // $ExpectType string
|
||||
assign({ a: 6 }, {}).a; // $ExpectType number
|
||||
assign({ b: 6 }, {}).a; // $ExpectError
|
||||
assign({}, { b: 6 }, {}).b; // $ExpectType number
|
||||
assign({ a: 'hello' }, { b: 6 }, {}).a; // $ExpectType string
|
||||
assign({ a: 'hello' }, { b: 6 }, { a: true }).a; // $ExpectType boolean
|
||||
assign({ a: 'hello' }, '', { a: true }).a; // $ExpectError
|
||||
assign({ d: ['gobias industries'] }, { a: 'hello' }, { b: 6 }, { a: true }).d; // $ExpectType string[]
|
||||
})();
|
||||
|
||||
(() => { /* merge */
|
||||
merge({}, { a: 'b'});
|
||||
merge({}, { a: 'b'}).a; // $ExpectType string
|
||||
merge({ a: 6 }, { a: 'b'}).a; // $ExpectType string
|
||||
merge({ a: 6 }, {}).a; // $ExpectType number
|
||||
merge({ b: 6 }, {}).a; // $ExpectError
|
||||
})();
|
||||
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
// Type definitions for @ember/polyfills 3.0
|
||||
// Project: http://emberjs.com/
|
||||
// Definitions by: Mike North <https://github.com/mike-north>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import { Mix, Mix3, Mix4 } from './types';
|
||||
|
||||
/**
|
||||
* Copy properties from a source object to a target object.
|
||||
* @deprecated Use Object.assign
|
||||
*/
|
||||
export function assign<T extends object, U extends object>(target: T, source: U): Mix<T, U>;
|
||||
export function assign<T extends object, U extends object, V extends object>(target: T, source1: U, source2: V): Mix3<T, U, V>;
|
||||
export function assign<T extends object, U extends object, V extends object, W extends object>(target: T, source1: U, source2: V, source3: W): Mix4<T, U, V, W>;
|
||||
|
||||
/**
|
||||
* Merge the contents of two objects together into the first object.
|
||||
* @deprecated Use Object.assign
|
||||
*/
|
||||
export function merge<T extends object, U extends object>(original: T, updates: U): Mix<T, U>;
|
||||
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"paths": {
|
||||
"@ember/polyfills": ["ember__polyfills"],
|
||||
"@ember/polyfills/*": ["ember__polyfills/*"]
|
||||
},
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"types.d.ts",
|
||||
"ember__polyfills-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {}
|
||||
}
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
export type Mix<A, B> = B & Pick<A, Exclude<keyof A, keyof B>>;
|
||||
export type Mix3<A, B, C> = Mix<Mix<A, B>, C>;
|
||||
export type Mix4<A, B, C, D> = Mix3<Mix<A, B>, C, D>;
|
||||
export default Mix;
|
||||
@@ -0,0 +1,203 @@
|
||||
import Ember from 'ember';
|
||||
import RSVP from 'rsvp';
|
||||
import { run } from '@ember/runloop';
|
||||
|
||||
Ember.run.queues; // $ExpectType EmberRunQueues[]
|
||||
const queues: string[] = Ember.run.queues;
|
||||
|
||||
function testRun() {
|
||||
run(() => { // $ExpectType number
|
||||
// code to be executed within a RunLoop
|
||||
return 123;
|
||||
});
|
||||
|
||||
function destroyApp(application: Ember.Application) {
|
||||
Ember.run(application, 'destroy');
|
||||
run(application, function() {
|
||||
this.destroy();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function testBind() {
|
||||
Ember.Component.extend({
|
||||
init() {
|
||||
const bound = Ember.run.bind(this, this.setupEditor);
|
||||
bound();
|
||||
},
|
||||
|
||||
editor: null as string | null,
|
||||
|
||||
setupEditor(editor: string) {
|
||||
this.set('editor', editor);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function testCancel() {
|
||||
const myContext = {};
|
||||
|
||||
const runNext = run.next(myContext, () => {
|
||||
// will not be executed
|
||||
});
|
||||
|
||||
run.cancel(runNext);
|
||||
|
||||
const runLater = run.later(myContext, () => {
|
||||
// will not be executed
|
||||
}, 500);
|
||||
|
||||
run.cancel(runLater);
|
||||
|
||||
const runScheduleOnce = run.scheduleOnce('afterRender', myContext, () => {
|
||||
// will not be executed
|
||||
});
|
||||
|
||||
run.cancel(runScheduleOnce);
|
||||
|
||||
const runOnce = run.once(myContext, () => {
|
||||
// will not be executed
|
||||
});
|
||||
|
||||
run.cancel(runOnce);
|
||||
|
||||
const throttle = run.throttle(myContext, () => {
|
||||
// will not be executed
|
||||
}, 1, false);
|
||||
|
||||
run.cancel(throttle);
|
||||
|
||||
const debounce = run.debounce(myContext, () => {
|
||||
// will not be executed
|
||||
}, 1);
|
||||
|
||||
run.cancel(debounce);
|
||||
|
||||
const debounceImmediate = run.debounce(myContext, () => {
|
||||
// will be executed since we passed in true (immediate)
|
||||
}, 100, true);
|
||||
|
||||
// the 100ms delay until this method can be called again will be canceled
|
||||
run.cancel(debounceImmediate);
|
||||
}
|
||||
|
||||
function testDebounce() {
|
||||
function runIt() {
|
||||
}
|
||||
|
||||
const myContext = { name: 'debounce' };
|
||||
|
||||
run.debounce(runIt, 150);
|
||||
run.debounce(myContext, runIt, 150);
|
||||
run.debounce(myContext, runIt, 150, true);
|
||||
|
||||
Ember.Component.extend({
|
||||
searchValue: 'test',
|
||||
fetchResults(value: string) {},
|
||||
|
||||
actions: {
|
||||
handleTyping() {
|
||||
// the fetchResults function is passed into the component from its parent
|
||||
Ember.run.debounce(this, this.get('fetchResults'), this.get('searchValue'), 250);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function testBegin() {
|
||||
run.begin();
|
||||
// code to be executed within a RunLoop
|
||||
run.end();
|
||||
}
|
||||
|
||||
function testJoin() {
|
||||
run.join(() => {
|
||||
// creates a new run-loop
|
||||
});
|
||||
|
||||
run(() => {
|
||||
// creates a new run-loop
|
||||
run.join(() => {
|
||||
// joins with the existing run-loop, and queues for invocation on
|
||||
// the existing run-loops action queue.
|
||||
});
|
||||
});
|
||||
|
||||
new RSVP.Promise((resolve) => {
|
||||
Ember.run.later(() => {
|
||||
resolve({ msg: 'Hold Your Horses' });
|
||||
}, 3000);
|
||||
});
|
||||
}
|
||||
|
||||
function testLater() {
|
||||
const myContext = {};
|
||||
run.later(myContext, () => {
|
||||
// code here will execute within a RunLoop in about 500ms with this == myContext
|
||||
}, 500);
|
||||
}
|
||||
|
||||
function testNext() {
|
||||
const myContext = {};
|
||||
run.next(myContext, () => {
|
||||
// code to be executed in the next run loop,
|
||||
// which will be scheduled after the current one
|
||||
});
|
||||
}
|
||||
|
||||
function testOnce() {
|
||||
Ember.Component.extend({
|
||||
init() {
|
||||
Ember.run.once(this, 'processFullName');
|
||||
},
|
||||
|
||||
processFullName() {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function testSchedule() {
|
||||
Ember.Component.extend({
|
||||
init() {
|
||||
run.schedule('sync', this, () => {
|
||||
// this will be executed in the first RunLoop queue, when bindings are synced
|
||||
console.log('scheduled on sync queue');
|
||||
});
|
||||
|
||||
run.schedule('actions', this, () => {
|
||||
// this will be executed in the 'actions' queue, after bindings have synced.
|
||||
console.log('scheduled on actions queue');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Ember.run.schedule('actions', () => {
|
||||
// Do more things
|
||||
});
|
||||
}
|
||||
|
||||
function testScheduleOnce() {
|
||||
function sayHi() {
|
||||
console.log('hi');
|
||||
}
|
||||
|
||||
const myContext = {};
|
||||
run(() => {
|
||||
run.scheduleOnce('afterRender', myContext, sayHi);
|
||||
run.scheduleOnce('afterRender', myContext, sayHi);
|
||||
// sayHi will only be executed once, in the afterRender queue of the RunLoop
|
||||
});
|
||||
run.scheduleOnce('actions', myContext, () => {
|
||||
console.log('Closure');
|
||||
});
|
||||
}
|
||||
|
||||
function testThrottle() {
|
||||
function runIt() {
|
||||
}
|
||||
|
||||
const myContext = { name: 'throttle' };
|
||||
|
||||
run.throttle(runIt, 150);
|
||||
run.throttle(myContext, runIt, 150);
|
||||
}
|
||||
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
// Type definitions for @ember/runloop 3.0
|
||||
// Project: http://emberjs.com/
|
||||
// Definitions by: Mike North <https://github.com/mike-north>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import Ember from 'ember';
|
||||
|
||||
export const begin: typeof Ember.run.begin;
|
||||
export const bind: typeof Ember.run.bind;
|
||||
export const cancel: typeof Ember.run.cancel;
|
||||
export const debounce: typeof Ember.run.debounce;
|
||||
export const end: typeof Ember.run.end;
|
||||
export const join: typeof Ember.run.join;
|
||||
export const later: typeof Ember.run.later;
|
||||
export const next: typeof Ember.run.next;
|
||||
export const once: typeof Ember.run.once;
|
||||
export const run: typeof Ember.run;
|
||||
export const schedule: typeof Ember.run.schedule;
|
||||
export const scheduleOnce: typeof Ember.run.scheduleOnce;
|
||||
export const throttle: typeof Ember.run.throttle;
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"paths": {
|
||||
"@ember/runloop": ["ember__runloop"]
|
||||
},
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"ember__runloop-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": { }
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { dasherize, camelize, capitalize, classify, decamelize, htmlSafe, loc, underscore, w } from '@ember/string';
|
||||
|
||||
dasherize(); // $ExpectError
|
||||
dasherize('blue man group'); // $ExpectType string
|
||||
dasherize('', ''); // $ExpectError
|
||||
|
||||
camelize(); // $ExpectError
|
||||
camelize('blue man group'); // $ExpectType string
|
||||
camelize('', ''); // $ExpectError
|
||||
|
||||
decamelize(); // $ExpectError
|
||||
decamelize('blue man group'); // $ExpectType string
|
||||
decamelize('', ''); // $ExpectError
|
||||
|
||||
underscore(); // $ExpectError
|
||||
underscore('blue man group'); // $ExpectType string
|
||||
underscore('', ''); // $ExpectError
|
||||
|
||||
w(); // $ExpectError
|
||||
w('blue man group'); // $ExpectType string[]
|
||||
w('', ''); // $ExpectError
|
||||
|
||||
classify(); // $ExpectError
|
||||
classify('blue man group'); // $ExpectType string
|
||||
classify('', ''); // $ExpectError
|
||||
|
||||
capitalize(); // $ExpectError
|
||||
capitalize('blue man group'); // $ExpectType string
|
||||
capitalize('', ''); // $ExpectError
|
||||
|
||||
loc(); // $ExpectError
|
||||
loc("_Hello World"); // $ExpectType string
|
||||
loc("_Hello %@ %@", ["John", "Smith"]); // $ExpectType string
|
||||
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
// Type definitions for @ember/string 3.0
|
||||
// Project: http://emberjs.com/
|
||||
// Definitions by: Mike North <https://github.com/mike-north>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import { SafeString } from 'handlebars';
|
||||
|
||||
export function camelize(str: string): string;
|
||||
export function capitalize(str: string): string;
|
||||
export function classify(str: string): string;
|
||||
export function dasherize(str: string): string;
|
||||
export function decamelize(str: string): string;
|
||||
export function htmlSafe(str: string): Handlebars.SafeString;
|
||||
export function isHTMLSafe(str: string): boolean;
|
||||
export function loc(template: string, args?: string[]): string;
|
||||
export function underscore(str: string): string;
|
||||
export function w(str: string): string[];
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"paths": {
|
||||
"@ember/string": ["ember__string"]
|
||||
},
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"ember__string-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {}
|
||||
}
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
import Ember from 'ember';
|
||||
export default class TestAdapter extends Ember.Test.Adapter { }
|
||||
@@ -0,0 +1,39 @@
|
||||
import { registerWaiter, registerHelper, registerAsyncHelper } from '@ember/test';
|
||||
import TestAdapter from '@ember/test/adapter';
|
||||
|
||||
const pending = 0;
|
||||
registerWaiter(() => pending !== 0);
|
||||
|
||||
declare const MyDb: {
|
||||
hasPendingTransactions(): boolean;
|
||||
};
|
||||
|
||||
registerWaiter(MyDb, MyDb.hasPendingTransactions);
|
||||
registerWaiter(); // $ExpectError
|
||||
|
||||
registerHelper('boot', app => {
|
||||
app.advanceReadiness(); // $ExpectType void
|
||||
app.deferReadiness(); // $ExpectType void
|
||||
app.register('foo', class {}); // $ExpectType void
|
||||
app.register('foo'); // $ExpectError
|
||||
app.register(); // $ExpectError
|
||||
});
|
||||
|
||||
registerAsyncHelper('boot', app => {
|
||||
app.advanceReadiness();
|
||||
app.deferReadiness();
|
||||
app.register('foo', class {});
|
||||
});
|
||||
|
||||
registerAsyncHelper('waitForPromise', (app, promise) => {
|
||||
app.advanceReadiness();
|
||||
app.deferReadiness();
|
||||
app.register('foo', class {});
|
||||
return new Promise(() => {
|
||||
const adapter = new TestAdapter();
|
||||
adapter.asyncStart();
|
||||
return promise.then(() => {
|
||||
adapter.asyncEnd();
|
||||
});
|
||||
});
|
||||
});
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user