本文整理汇总了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();
}
});
示例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);
}
});
示例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,
});
}
},
});
示例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
}
];
}
}
});
示例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,
/**
//.........这里部分代码省略.........