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


TypeScript helper.helper函數代碼示例

本文整理匯總了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);
開發者ID:NullVoxPopuli,項目名稱:emberclear,代碼行數:7,代碼來源:first-8.ts

示例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);
開發者ID:NullVoxPopuli,項目名稱:emberclear,代碼行數:7,代碼來源:or.ts

示例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);
開發者ID:alyiwang,項目名稱:WhereHows,代碼行數:16,代碼來源:split-text.ts

示例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);
開發者ID:NullVoxPopuli,項目名稱:emberclear,代碼行數:8,代碼來源:is-present.ts

示例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);
開發者ID:AlexGalays,項目名稱:DefinitelyTyped,代碼行數:29,代碼來源:helper.ts

示例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);
開發者ID:NullVoxPopuli,項目名稱:emberclear,代碼行數:8,代碼來源:and.ts

示例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);
開發者ID:NullVoxPopuli,項目名稱:emberclear,代碼行數:17,代碼來源:prevent-default.ts

示例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);
開發者ID:NullVoxPopuli,項目名稱:emberclear,代碼行數:8,代碼來源:html-safe.ts

示例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);
開發者ID:NullVoxPopuli,項目名稱:emberclear,代碼行數:7,代碼來源:mult.ts

示例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);
開發者ID:NullVoxPopuli,項目名稱:emberclear,代碼行數:30,代碼來源:toggle.ts


注:本文中的@ember/component/helper.helper函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。