当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript mixin.create函数代码示例

本文整理汇总了TypeScript中@ember/object/mixin.create函数的典型用法代码示例。如果您正苦于以下问题:TypeScript create函数的具体用法?TypeScript create怎么用?TypeScript create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了create函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: afterModel

import Mixin from '@ember/object/mixin';
import { subscribe, unsubscribe } from '../services/realtime-listener';
import DS from 'ember-data';

// TODO make sure realtime works on findAll
//      handle includes
export default Mixin.create({
    afterModel(model:DS.Model) {
        subscribe(this, model);
        return this._super(model);
    },
    deactivate() {
        unsubscribe(this);
        return this._super();
    }
});
开发者ID:firebase,项目名称:emberfire,代码行数:16,代码来源:realtime-route.ts

示例2: get

export default Mixin.create({
  /**
   * The AJAX service to send requests through
   *
   * @property {AjaxService} ajaxService
   * @public
   */
  ajaxService: service('ajax'),

  /**
   * @property {string} host
   * @public
   */
  host: alias('ajaxService.host'),

  /**
   * @property {string} namespace
   * @public
   */
  namespace: alias('ajaxService.namespace'),

  /**
   * @property {object} headers
   * @public
   */
  headers: alias('ajaxService.headers'),

  ajax(url: string, _method: string, _options: object) {
    // @ts-ignore
    const augmentedOptions: object = this.ajaxOptions(...arguments);

    return get(this, 'ajaxService').request(url, augmentedOptions);
  }
});
开发者ID:knownasilya,项目名称:ember-ajax,代码行数:34,代码来源:ajax-support.ts

示例3: readOnly

const ResizeAwareMixin = Mixin.create({
  resizeDebouncedEventsEnabled: true,
  resizeEventsEnabled: true,

  screenHeight: readOnly('resizeService.screenHeight'),
  screenWidth: readOnly('resizeService.screenWidth'),

  _oldViewHeight: null as number | null,
  _oldViewHeightDebounced: null as number | null,
  _oldViewWidth: null as number | null,
  _oldViewWidthDebounced: null as number | null,
  resizeHeightSensitive: true,
  resizeWidthSensitive: true,

  didInsertElement() {
    this._super(...arguments);
    const resizeService: ResizeService = (this as any).get('resizeService');
    if (this.get('resizeEventsEnabled')) {
      resizeService.on('didResize', this, this._handleResizeEvent);
    }
    if (this.get('resizeDebouncedEventsEnabled')) {
      resizeService.on('debouncedDidResize', this, this._handleDebouncedResizeEvent);
    }
  },

  willDestroyElement() {
    this._super(...arguments);
    const resizeService: ResizeService = (this as any).get('resizeService');
    if (this.get('resizeEventsEnabled')) {
      resizeService.off('didResize', this, this._handleResizeEvent);
    }
    if (this.get('resizeDebouncedEventsEnabled')) {
      resizeService.off('debouncedDidResize', this, this._handleDebouncedResizeEvent);
    }
  },

  // tslint:disable-next-line:no-empty
  didResize(_width: number, _height: number, _evt: UIEvent) {}, // Overridden in subclass
  // tslint:disable-next-line:no-empty
  debouncedDidResize(_width: number, _height: number, _evt: UIEvent) {}, // Overridden in subclass

  _getComponentSize(this: any) {
    return this.element.getClientRects()[0];
  },

  _handleResizeEvent(evt: UIEvent) {
    const w = floor(this._getComponentSize().width);
    const h = floor(this._getComponentSize().height);
    if (
      (this.get('resizeWidthSensitive') && this.get('_oldViewWidth') !== w) ||
      (this.get('resizeHeightSensitive') && this.get('_oldViewHeight') !== h)
    ) {
      this.didResize(w, h, evt);
      this.setProperties({
        _oldViewHeight: h,
        _oldViewWidth: w,
      });
    }
  },

  _handleDebouncedResizeEvent(evt: UIEvent) {
    const w = floor(this._getComponentSize().width);
    const h = floor(this._getComponentSize().height);
    if (
      (this.get('resizeWidthSensitive') && this.get('_oldViewWidthDebounced') !== w) ||
      (this.get('resizeHeightSensitive') && this.get('_oldViewHeightDebounced') !== h)
    ) {
      this.debouncedDidResize(w, h, evt);
      this.setProperties({
        _oldViewHeightDebounced: h,
        _oldViewWidthDebounced: w,
      });
    }
  },
});
开发者ID:mike-north,项目名称:ember-resize,代码行数:75,代码来源:resize-aware.ts

示例4: normalizeErrorResponse

export default Mixin.create({
  /**
   * Normalize the error from the server into the same format
   *
   * The format we normalize to is based on the JSON API specification.  The
   * return value should be an array of objects that match the format they
   * describe. More details about the object format can be found
   * [here](http://jsonapi.org/format/#error-objects)
   *
   * The basics of the format are as follows:
   *
   * ```javascript
   * [
   *   {
   *     status: 'The status code for the error',
   *     title: 'The human-readable title of the error'
   *     detail: 'The human-readable details of the error'
   *   }
   * ]
   * ```
   *
   * In cases where the server returns an array, then there should be one item
   * in the array for each of the payload.  If your server returns a JSON API
   * formatted payload already, it will just be returned directly.
   *
   * If your server returns something other than a JSON API format, it's
   * suggested that you override this method to convert your own errors into the
   * one described above.
   */
  normalizeErrorResponse(
    status: number,
    _headers: Headers,
    payload?: Payload
  ): JsonApiErrorObject[] {
    payload = isNone(payload) ? {} : payload;

    if (isJsonApiErrorResponse(payload)) {
      return payload.errors.map(function(error) {
        if (isObject(error)) {
          const ret = assign({}, error);
          ret.status = `${error.status}`;
          return ret;
        } else {
          return {
            status: `${status}`,
            title: error
          };
        }
      });
    } else if (isJsonApiErrorObjectArray(payload)) {
      return payload.map(function(error) {
        if (isObject(error)) {
          return {
            status: `${status}`,
            title: error.title || 'The backend responded with an error',
            detail: error
          };
        } else {
          return {
            status: `${status}`,
            title: `${error}`
          };
        }
      });
    } else if (isString(payload)) {
      return [
        {
          status: `${status}`,
          title: payload
        }
      ];
    } else {
      return [
        {
          status: `${status}`,
          title: payload.title || 'The backend responded with an error',
          detail: payload
        }
      ];
    }
  }
});
开发者ID:knownasilya,项目名称:ember-ajax,代码行数:82,代码来源:normalize-error-response.ts

示例5: resolve

export default Mixin.create({
  /**
   * The default value for the request `contentType`
   *
   * For now, defaults to the same value that jQuery would assign.  In the
   * future, the default value will be for JSON requests.
   * @property {string} contentType
   * @public
   */
  contentType: 'application/x-www-form-urlencoded; charset=UTF-8',

  /**
   * Headers to include on the request
   *
   * Some APIs require HTTP headers, e.g. to provide an API key. Arbitrary
   * headers can be set as key/value pairs on the `RESTAdapter`'s `headers`
   * object and Ember Data will send them along with each ajax request.
   *
   * ```javascript
   * // app/services/ajax.js
   * import AjaxService from 'ember-ajax/services/ajax';
   *
   * export default AjaxService.extend({
   *   headers: {
   *     'API_KEY': 'secret key',
   *     'ANOTHER_HEADER': 'Some header value'
   *   }
   * });
   * ```
   *
   * `headers` can also be used as a computed property to support dynamic
   * headers.
   *
   * ```javascript
   * // app/services/ajax.js
   * import Ember from 'ember';
   * import AjaxService from 'ember-ajax/services/ajax';
   *
   * const {
   *   computed,
   *   get,
   *   inject: { service }
   * } = Ember;
   *
   * export default AjaxService.extend({
   *   session: service(),
   *   headers: computed('session.authToken', function() {
   *     return {
   *       'API_KEY': get(this, 'session.authToken'),
   *       'ANOTHER_HEADER': 'Some header value'
   *     };
   *   })
   * });
   * ```
   *
   * In some cases, your dynamic headers may require data from some object
   * outside of Ember's observer system (for example `document.cookie`). You
   * can use the `volatile` function to set the property into a non-cached mode
   * causing the headers to be recomputed with every request.
   *
   * ```javascript
   * // app/services/ajax.js
   * import Ember from 'ember';
   * import AjaxService from 'ember-ajax/services/ajax';
   *
   * const {
   *   computed,
   *   get,
   *   inject: { service }
   * } = Ember;
   *
   * export default AjaxService.extend({
   *   session: service(),
   *   headers: computed('session.authToken', function() {
   *     return {
   *       'API_KEY': get(document.cookie.match(/apiKey\=([^;]*)/), '1'),
   *       'ANOTHER_HEADER': 'Some header value'
   *     };
   *   }).volatile()
   * });
   * ```
   *
   * @property {Headers} headers
   * @public
   */
  headers: undefined,

  /**
   * @property {string} host
   * @public
   */
  host: undefined,

  /**
   * @property {string} namespace
   * @public
   */
  namespace: undefined,

  /**
//.........这里部分代码省略.........
开发者ID:knownasilya,项目名称:ember-ajax,代码行数:101,代码来源:ajax-request.ts


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