• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript object.computed函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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 || {});
  }
开发者ID:NullVoxPopuli,项目名称:emberclear,代码行数:7,代码来源:component.ts


示例2: displayName

  @computed('name', 'publicKeyAsHex')
  get displayName() {
    const name = this.name;
    const shortKey = this.publicKeyAsHex.substring(0, 8);

    return `${name} (${shortKey})`;
  }
开发者ID:NullVoxPopuli,项目名称:emberclear,代码行数:7,代码来源:model.ts


示例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';
  }
开发者ID:NullVoxPopuli,项目名称:emberclear,代码行数:10,代码来源:component.ts


示例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({
//.........这里部分代码省略.........
开发者ID:code0100fun,项目名称:data,代码行数:101,代码来源:attr.ts


示例5: publicKeyAsHex

 @computed('publicKey')
 get publicKeyAsHex() {
   return toHex(this.publicKey);
 }
开发者ID:NullVoxPopuli,项目名称:emberclear,代码行数:4,代码来源:model.ts


示例6: fullName

 @computed("firstName", "lastName")
 get fullName() {
     return `${this.firstName} ${this.lastName}`;
 }
开发者ID:CNBoland,项目名称:DefinitelyTyped,代码行数:4,代码来源:octane.ts


示例7: customMacro

function customMacro(message: string) {
    return computed(() => {
        return [message, message];
    });
}
开发者ID:csrakowski,项目名称:DefinitelyTyped,代码行数:5,代码来源:octane.ts


示例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,
  }),
});
开发者ID:AlexGalays,项目名称:DefinitelyTyped,代码行数:31,代码来源:component.ts


示例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(' ');
开发者ID:AlexGalays,项目名称:DefinitelyTyped,代码行数:31,代码来源:computed.ts



注:本文中的@ember/object.computed函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript object.extend函数代码示例发布时间:2022-05-28
下一篇:
TypeScript instrumentation.flaggedInstrument函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap