本文整理汇总了TypeScript中@ember/object.computed函数的典型用法代码示例。如果您正苦于以下问题:TypeScript computed函数的具体用法?TypeScript computed怎么用?TypeScript computed使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了computed函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: qrCode
@computed()
@monitor
get qrCode() {
const { data } = this.args;
return convertObjectToQRCodeDataURL(data || {});
}
示例2: displayName
@computed('name', 'publicKeyAsHex')
get displayName() {
const name = this.name;
const shortKey = this.publicKeyAsHex.substring(0, 8);
return `${name} (${shortKey})`;
}
示例3: alignment
@computed('settings.useLeftRightJustificationForMessages', 'hasSender')
get alignment() {
if (!this.settings.useLeftRightJustificationForMessages) return '';
if (this.hasSender && this.sender!.id !== this.currentUser.id) {
return 'justify-received';
}
return 'justify-sent';
}
示例4: defaultValue
/**
`DS.attr` defines an attribute on a [DS.Model](/api/data/classes/DS.Model.html).
By default, attributes are passed through as-is, however you can specify an
optional type to have the value automatically transformed.
Ember Data ships with four basic transform types: `string`, `number`,
`boolean` and `date`. You can define your own transforms by subclassing
[DS.Transform](/api/data/classes/DS.Transform.html).
Note that you cannot use `attr` to define an attribute of `id`.
`DS.attr` takes an optional hash as a second parameter, currently
supported options are:
- `defaultValue`: Pass a string or a function to be called to set the attribute
to a default value if none is supplied.
Example
```app/models/user.js
import DS from 'ember-data';
export default DS.Model.extend({
username: DS.attr('string'),
email: DS.attr('string'),
verified: DS.attr('boolean', { defaultValue: false })
});
```
Default value can also be a function. This is useful it you want to return
a new object for each attribute.
```app/models/user.js
import DS from 'ember-data';
export default DS.Model.extend({
username: DS.attr('string'),
email: DS.attr('string'),
settings: DS.attr({
defaultValue() {
return {};
}
})
});
```
The `options` hash is passed as second argument to a transforms'
`serialize` and `deserialize` method. This allows to configure a
transformation and adapt the corresponding value, based on the config:
```app/models/post.js
import DS from 'ember-data';
export default DS.Model.extend({
text: DS.attr('text', {
uppercase: true
})
});
```
```app/transforms/text.js
import DS from 'ember-data';
export default DS.Transform.extend({
serialize(value, options) {
if (options.uppercase) {
return value.toUpperCase();
}
return value;
},
deserialize(value) {
return value;
}
})
```
@namespace
@method attr
@for DS
@param {String|Object} type the attribute type
@param {Object} options a hash of options
@return {Attribute}
*/
export default function attr(type?: string | AttrOptions, options?: AttrOptions) {
if (typeof type === 'object') {
options = type;
type = undefined;
} else {
options = options || {};
}
let meta = {
type: type,
isAttribute: true,
kind: 'attribute',
options: options,
};
return computed({
//.........这里部分代码省略.........
示例5: publicKeyAsHex
@computed('publicKey')
get publicKeyAsHex() {
return toHex(this.publicKey);
}
示例6: fullName
@computed("firstName", "lastName")
get fullName() {
return `${this.firstName} ${this.lastName}`;
}
示例7: customMacro
function customMacro(message: string) {
return computed(() => {
return [message, message];
});
}
示例8: computed
});
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,
}),
});
示例9: function
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(' ');