mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 06:47:03 +00:00
[ember] refactor @ember/component types into their own package (#28845)
* [ember] failing test - relax ObserverMethod property name arg * [ember] relax ObserverMethod property name arg * [ember] @ember/component types refactored into their own package
This commit is contained in:
committed by
Ryan Cavanaugh
parent
a87e9d3ab8
commit
856deff048
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
export default class Checkbox extends Ember.Checkbox { }
|
||||
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
export default class Helper extends Ember.Helper { }
|
||||
/**
|
||||
* In many cases, the ceremony of a full `Helper` class is not required.
|
||||
* The `helper` method create pure-function helpers without instances. For
|
||||
* example:
|
||||
* ```app/helpers/format-currency.js
|
||||
* import { helper } from '@ember/component/helper';
|
||||
* export default helper(function(params, hash) {
|
||||
* let cents = params[0];
|
||||
* let currency = hash.currency;
|
||||
* return `${currency}${cents * 0.01}`;
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function helper(helperFn: (params: any[], hash?: any) => any): any;
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
// Type definitions for @ember/component 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 Component extends Ember.Component { }
|
||||
@@ -0,0 +1,123 @@
|
||||
import Component from '@ember/component';
|
||||
import Object, { computed, get } from '@ember/object';
|
||||
import hbs from 'htmlbars-inline-precompile';
|
||||
import { assertType } from "./lib/assert";
|
||||
|
||||
Component.extend({
|
||||
layout: hbs`
|
||||
<div>
|
||||
{{yield}}
|
||||
</div>
|
||||
`,
|
||||
});
|
||||
|
||||
Component.extend({
|
||||
layout: 'my-layout',
|
||||
});
|
||||
|
||||
const MyComponent = Component.extend();
|
||||
assertType<string | string[]>(get(MyComponent, 'positionalParams'));
|
||||
|
||||
const component1 = Component.extend({
|
||||
actions: {
|
||||
hello(name: string) {
|
||||
console.log('Hello', name);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Component.extend({
|
||||
name: '',
|
||||
hello(name: string) {
|
||||
this.set('name', name);
|
||||
},
|
||||
});
|
||||
|
||||
Component.extend({
|
||||
tagName: 'em',
|
||||
});
|
||||
|
||||
Component.extend({
|
||||
classNames: ['my-class', 'my-other-class'],
|
||||
});
|
||||
|
||||
Component.extend({
|
||||
classNameBindings: ['propertyA', 'propertyB'],
|
||||
propertyA: 'from-a',
|
||||
propertyB: computed(function() {
|
||||
if (!this.get('propertyA')) {
|
||||
return 'from-b';
|
||||
}
|
||||
}),
|
||||
});
|
||||
|
||||
Component.extend({
|
||||
classNameBindings: ['hovered'],
|
||||
hovered: true,
|
||||
});
|
||||
|
||||
Component.extend({
|
||||
classNameBindings: ['messages.empty'],
|
||||
messages: Object.create({
|
||||
empty: true,
|
||||
}),
|
||||
});
|
||||
|
||||
Component.extend({
|
||||
classNameBindings: ['isEnabled:enabled:disabled'],
|
||||
isEnabled: true,
|
||||
});
|
||||
|
||||
Component.extend({
|
||||
classNameBindings: ['isEnabled::disabled'],
|
||||
isEnabled: true,
|
||||
});
|
||||
|
||||
Component.extend({
|
||||
tagName: 'a',
|
||||
attributeBindings: ['href'],
|
||||
href: 'http://google.com',
|
||||
});
|
||||
|
||||
Component.extend({
|
||||
tagName: 'a',
|
||||
attributeBindings: ['url:href'],
|
||||
url: 'http://google.com',
|
||||
});
|
||||
|
||||
Component.extend({
|
||||
tagName: 'use',
|
||||
attributeBindings: ['xlinkHref:xlink:href'],
|
||||
xlinkHref: '#triangle',
|
||||
});
|
||||
|
||||
Component.extend({
|
||||
tagName: 'input',
|
||||
attributeBindings: ['disabled'],
|
||||
disabled: false,
|
||||
});
|
||||
|
||||
Component.extend({
|
||||
tagName: 'input',
|
||||
attributeBindings: ['disabled'],
|
||||
disabled: computed(() => {
|
||||
if ('someLogic') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}),
|
||||
});
|
||||
|
||||
Component.extend({
|
||||
tagName: 'form',
|
||||
attributeBindings: ['novalidate'],
|
||||
novalidate: null,
|
||||
});
|
||||
|
||||
Component.extend({
|
||||
click(event: object) {
|
||||
// will be called when an instance's
|
||||
// rendered element is clicked
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
import { assertType } from './lib/assert';
|
||||
import Helper, { helper } from '@ember/component/helper';
|
||||
|
||||
class Timestamp extends Helper {
|
||||
timer?: ReturnType<typeof setInterval>;
|
||||
now = new Date();
|
||||
init() {
|
||||
super.init();
|
||||
this.timer = setInterval(() => {
|
||||
this.set('now', new Date());
|
||||
this.recompute();
|
||||
}, 100);
|
||||
}
|
||||
willDestroy() {
|
||||
clearInterval(this.timer);
|
||||
}
|
||||
}
|
||||
|
||||
const addHelper = helper(function add([a, b]: number[]) {
|
||||
return a + b;
|
||||
});
|
||||
|
||||
const dasherizeHelper = helper(function dasherize([str]: string[], { delim = '-'}) {
|
||||
return str.split(/[\s\n\_\.]+/g).join(delim);
|
||||
});
|
||||
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;
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
export default class TextArea extends Ember.TextArea { }
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import Ember from 'ember';
|
||||
|
||||
export default class TextField extends Ember.TextField { }
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"paths": {
|
||||
"@ember/component": ["ember__component"],
|
||||
"@ember/component/*": ["ember__component/*"]
|
||||
},
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"checkbox.d.ts",
|
||||
"text-area.d.ts",
|
||||
"text-field.d.ts",
|
||||
"helper.d.ts",
|
||||
"test/lib/assert.ts",
|
||||
"test/component.ts",
|
||||
"test/helper.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {}
|
||||
}
|
||||
Reference in New Issue
Block a user