本文整理汇总了TypeScript中@ember/-internals/metal.computed函数的典型用法代码示例。如果您正苦于以下问题:TypeScript computed函数的具体用法?TypeScript computed怎么用?TypeScript computed使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了computed函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: computed
/**
The `type` attribute of the input element.
@property type
@type String
@default "text"
@public
*/
type: computed({
get(): string {
return 'text';
},
set(_key: string, value: string) {
let type = 'text';
if (canSetTypeOfInput(value)) {
type = value;
}
return type;
},
}),
/**
The `size` of the text field in characters.
@property size
@type String
@default null
@public
示例2: computed
/**
Accessed as a classname binding to apply the `LinkComponent`'s `disabledClass`
CSS `class` to the element when the link is disabled.
When `true` interactions with the element will not trigger route changes.
@property disabled
@private
*/
disabled: computed({
get(_key: string): boolean {
// always returns false for `get` because (due to the `set` just below)
// the cached return value from the set will prevent this getter from _ever_
// being called after a set has occured
return false;
},
set(_key: string, value: any): boolean {
(this as any)._isDisabled = value;
return value ? get(this, 'disabledClass') : false;
},
}),
_isActive(routerState: any) {
if (get(this, 'loading')) {
return false;
}
let currentWhen = get(this, 'current-when');
if (typeof currentWhen === 'boolean') {
示例3: init
@for Ember.Templates.helpers
@param {Hash} options
@public
*/
Input = Component.extend({
tagName: '',
init() {
if (DEBUG) {
this[DISABLE_TAGLESS_EVENT_CHECK] = true;
}
this._super(...arguments);
},
isCheckbox: computed('type', function(this: { type?: unknown }) {
return this.type === 'checkbox';
}),
__injectEvents(target: any) {
let eventDispatcher = getOwner(this).lookup<any | undefined>('event_dispatcher:main');
let events: Dict<string> = (eventDispatcher && eventDispatcher._finalEvents) || {};
Object.values(events).forEach(key => {
if (this[key]) {
target[key] = this[key];
}
});
},
});
Input.toString = () => '@ember/component/input';