當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript object.computed函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。