本文整理汇总了TypeScript中@ember/component/helper.helper函数的典型用法代码示例。如果您正苦于以下问题:TypeScript helper函数的具体用法?TypeScript helper怎么用?TypeScript helper使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了helper函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: first8
import { helper as buildHelper } from '@ember/component/helper';
export function first8(params: any[] /*, hash*/) {
return params[0].substring(0, 8);
}
export const helper = buildHelper(first8);
示例2: or
import { helper as buildHelper } from '@ember/component/helper';
export function or(params: any[] /*, hash*/) {
return params[0] || params[1];
}
export const helper = buildHelper(or);
示例3: splitText
import { helper } from '@ember/component/helper';
export function splitText([string = '', maxLen = 20, separator = '...']: [string, number?, string?]): string {
const { length: strLen } = string;
const { length: sepLen } = separator;
if (strLen > maxLen) {
const splitLen = Math.floor((maxLen - sepLen) / 2);
return `${string.substr(0, splitLen).trim()}${separator}${string.substr(-splitLen).trim()}`;
}
return string;
}
export default helper(splitText);
示例4: isPresent
import { helper as buildHelper } from '@ember/component/helper';
import { isPresent as eIsPresent } from '@ember/utils';
export function isPresent(params: any[] /*, hash*/) {
return eIsPresent(params[0]);
}
export const helper = buildHelper(isPresent);
示例5: function
class SessionService extends Ember.Service {
currentUser: User;
}
const CurrentUserEmailHelper = Ember.Helper.extend({
session: Ember.inject.service() as Ember.ComputedProperty<SessionService>,
onNewUser: Ember.observer('session.currentUser', function(this: Ember.Helper) {
this.recompute();
}),
compute(): string {
return this.get('session')
.get('currentUser')
.get('email');
},
});
import { helper } from '@ember/component/helper';
function typedHelp(/*params, hash*/) {
return 'my type of help';
}
export default helper(typedHelp);
function arrayNumHelp(/*params, hash*/) {
return [1, 2, 3];
}
helper(arrayNumHelp);
示例6: and
// https://github.com/DockYard/ember-composable-helpers/blob/master/addon/helpers/toggle.js
import { helper as buildHelper } from '@ember/component/helper';
export function and(params: any[] /*, hash*/) {
return params[0] && params[1];
}
export const helper = buildHelper(and);
示例7: preventDefault
import { helper as buildHelper } from '@ember/component/helper';
type PositionalArgs = [(...args: any) => void];
export function preventDefault([fn]: PositionalArgs /*, hash*/) {
return (...args: any[]) => {
const firstArg = args[0];
if (firstArg && firstArg.preventDefault) {
firstArg.preventDefault();
}
return fn(...args);
};
}
export const helper = buildHelper(preventDefault);
示例8: htmlSafe
import { helper as buildHelper } from '@ember/component/helper';
import { htmlSafe as makeSafe } from '@ember/string';
export function htmlSafe(params: any[] /*, hash*/) {
return makeSafe(params[0]);
}
export const helper = buildHelper(htmlSafe);
示例9: mult
import { helper as buildHelper } from '@ember/component/helper';
export function mult(params: any[] /*, hash*/) {
return params[0] * params[1];
}
export const helper = buildHelper(mult);
示例10: nextIndex
import { helper as buildHelper } from '@ember/component/helper';
import { get, set } from '@ember/object';
import { isPresent } from '@ember/utils';
function nextIndex(length: number, currentIdx: number) {
if (currentIdx === -1 || currentIdx + 1 === length) {
return 0;
}
return currentIdx + 1;
}
type PositionalArguments = [string, any, ...any[]];
export function toggle([prop, obj, ...values]: PositionalArguments) {
return function() {
let currentValue = get(obj, prop);
if (isPresent(values)) {
let currentIdx = values.indexOf(currentValue);
let nextIdx = nextIndex(get(values, 'length'), currentIdx);
return set(obj, prop, values[nextIdx]);
}
return set(obj, prop, !currentValue);
};
}
export const helper = buildHelper(toggle);