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


TypeScript debug.warn函數代碼示例

本文整理匯總了TypeScript中@ember/debug.warn函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript warn函數的具體用法?TypeScript warn怎麽用?TypeScript warn使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了warn函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: makeClosureAction

function makeClosureAction(
  context: any,
  target: any,
  action: any,
  processArgs: any,
  debugKey: any
) {
  let self: any;
  let fn: any;

  assert(
    `Action passed is null or undefined in (action) from ${target}.`,
    action !== undefined && action !== null
  );

  if (typeof action[INVOKE] === 'function') {
    self = action;
    fn = action[INVOKE];
  } else {
    let typeofAction = typeof action;

    if (typeofAction === 'string') {
      self = target;
      fn = target.actions && target.actions[action];

      assert(`An action named '${action}' was not found in ${target}`, fn);
    } else if (typeofAction === 'function') {
      if (EMBER_NATIVE_DECORATOR_SUPPORT) {
        warn(
          `You passed a method, ${debugKey}, to the {{action}} helper which was not decorated with the '@action' decorator. All actions should be decorated with the '@action' decorator.`,
          target[debugKey] !== action || action[ACTION_METHOD] === true,
          {
            id: 'action-without-decorator',
          }
        );
      }

      self = context;
      fn = action;
    } else {
      // tslint:disable-next-line:max-line-length
      assert(
        `An action could not be made for \`${debugKey ||
          action}\` in ${target}. Please confirm that you are using either a quoted action name (i.e. \`(action '${debugKey ||
          'myAction'}')\`) or a function available in ${target}.`,
        false
      );
    }
  }

  return (...args: any[]) => {
    let payload = { target: self, args, label: '@glimmer/closure-action' };
    return flaggedInstrument('interaction.ember-action', payload, () => {
      return join(self, fn, ...processArgs(args));
    });
  };
}
開發者ID:habdelra,項目名稱:ember.js,代碼行數:57,代碼來源:action.ts

示例2: addArg

 function addArg(property: string) {
   warn(
     `Dependent keys containing @each only work one level deep. ` +
       `You used the key "${property}" which is invalid. ` +
       `Please create an intermediary computed property.`,
     DEEP_EACH_REGEX.test(property) === false,
     { id: 'ember-metal.computed-deep-each' }
   );
   args.push(property);
 }
開發者ID:chundabear,項目名稱:ember.js,代碼行數:10,代碼來源:computed.ts

示例3: register

  register(name: string, version: string, isCoreLibrary?: boolean): void {
    let index = this._registry.length;

    if (!this._getLibraryByName(name)) {
      if (isCoreLibrary) {
        index = this._coreLibIndex++;
      }
      this._registry.splice(index, 0, { name, version });
    } else {
      warn(`Library "${name}" is already registered with Ember.`, false, {
        id: 'ember-metal.libraries-register',
      });
    }
  }
開發者ID:cibernox,項目名稱:ember.js,代碼行數:14,代碼來源:libraries.ts

示例4: runInDebug

          runInDebug(function() {
            const message = `The server returned an empty string for ${
              requestData.type
            } ${
              requestData.url
            }, which cannot be parsed into a valid JSON. Return either null or {}.`;
            const validJSONString = !(
              textStatus === 'parsererror' && jqXHR.responseText === ''
            );

            warn(message, validJSONString, {
              id: 'ds.adapter.returned-empty-string-as-JSON'
            });
          });
開發者ID:knownasilya,項目名稱:ember-ajax,代碼行數:14,代碼來源:ajax-request.ts

示例5: async

const datasetUrnToId = async (urn: string): Promise<number> => {
  let datasetId = 0;

  try {
    // The headers object is a Header
    const headers = await getHeaders({ url: datasetIdTranslationUrlByUrn(urn) });
    const stringId = headers.get('datasetid');

    // If stringId is not falsey, parse as int and return, otherwise use default
    if (stringId) {
      datasetId = parseInt(stringId, 10);
    }
  } catch (e) {
    warn(`Exception occurred translating datasetUrn: ${e.message}`);
  }

  return datasetId;
};
開發者ID:linwenxue,項目名稱:WhereHows,代碼行數:18,代碼來源:dataset.ts

示例6: updateLink

  updateLink(link: string | null) {
    warn(
      `You pushed a record of type '${this.recordData.modelName}' with a relationship '${
        this.key
      }' configured as 'async: false'. You've included a link but no primary data, this may be an error in your payload. EmberData will treat this relationship as known-to-be-empty.`,
      this.isAsync || this.hasAnyRelationshipData,
      {
        id: 'ds.store.push-link-for-sync-relationship',
      }
    );
    assert(
      `You have pushed a record of type '${this.recordData.modelName}' with '${
        this.key
      }' as a link, but the value of that link is not a string.`,
      typeof link === 'string' || link === null
    );

    this.link = link;
  }
開發者ID:emberjs,項目名稱:data,代碼行數:19,代碼來源:relationship.ts

示例7: warn

    }

    if (get(this, 'bubbles') === false) {
      event.stopPropagation();
    }

    if (this._isDisabled) {
      return false;
    }

    if (get(this, 'loading')) {
      // tslint:disable-next-line:max-line-length
      warn(
        'This link-to is in an inactive loading state because at least one of its parameters presently has a null/undefined value, or the provided route name is invalid.',
        false,
        {
          id: 'ember-glimmer.link-to.inactive-loading-state',
        }
      );
      return false;
    }

    if (targetAttribute && targetAttribute !== '_self') {
      return false;
    }

    let qualifiedRouteName = get(this, 'qualifiedRouteName');
    let models = get(this, 'models');
    let queryParams = get(this, 'queryParams.values');
    let shouldReplace = get(this, 'replace');
開發者ID:habdelra,項目名稱:ember.js,代碼行數:30,代碼來源:link-to.ts

示例8: runInDebug

import { runInDebug, warn, debug, assert, registerWarnHandler, registerDeprecationHandler } from "@ember/debug";

/**
 * @ember/debug tests
 */
runInDebug(); // $ExpectError
runInDebug(() => console.log('Should not show up in prod')); // $ExpectType void

// Log a warning if we have more than 3 tomsters
const tomsterCount = 2;
warn('Too many tomsters!'); // $ExpectType void
warn('Too many tomsters!', tomsterCount <= 3); // $ExpectType void
warn('Too many tomsters!', tomsterCount <= 3, { // $ExpectType void
    id: 'ember-debug.too-many-tomsters'
});

debug(); // $ExpectError
debug('Too many tomsters!'); // $ExpectType void
debug('Too many tomsters!', 'foo'); // $ExpectError

// Test for truthiness
const str = 'hello';
assert('Must pass a string', typeof str === 'string'); // $ExpectType void

// Fail unconditionally
assert('This code path should never be run'); // $ExpectType void

// next is not called, so no warnings get the default behavior
registerWarnHandler(); // $ExpectError
registerWarnHandler(() => {}); // $ExpectType void
registerWarnHandler((message, { id }, next) => { // $ExpectType void
開發者ID:AlexGalays,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:ember__debug-tests.ts

示例9: _setupRelationships

  _setupRelationships(data) {
    let relationships = this.storeWrapper.relationshipsDefinitionFor(this.modelName);
    let keys = Object.keys(relationships);
    for (let i = 0; i < keys.length; i++) {
      let relationshipName = keys[i];

      if (!data.relationships[relationshipName]) {
        continue;
      }

      // in debug, assert payload validity eagerly
      let relationshipData = data.relationships[relationshipName];

      if (DEBUG) {
        let store = this.store;
        let recordData = this;
        let relationshipMeta = relationships[relationshipName];
        if (!relationshipData || !relationshipMeta) {
          continue;
        }

        if (relationshipData.links) {
          let isAsync = relationshipMeta.options && relationshipMeta.options.async !== false;
          let relationship = this._relationships.get(relationshipName);
          warn(
            `You pushed a record of type '${
              this.modelName
            }' with a relationship '${relationshipName}' configured as 'async: false'. You've included a link but no primary data, this may be an error in your payload. EmberData will treat this relationship as known-to-be-empty.`,
            isAsync || relationshipData.data || relationship.hasAnyRelationshipData,
            {
              id: 'ds.store.push-link-for-sync-relationship',
            }
          );
        } else if (relationshipData.data) {
          if (relationshipMeta.kind === 'belongsTo') {
            assert(
              `A ${
                this.modelName
              } record was pushed into the store with the value of ${relationshipName} being ${inspect(
                relationshipData.data
              )}, but ${relationshipName} is a belongsTo relationship so the value must not be an array. You should probably check your data payload or serializer.`,
              !Array.isArray(relationshipData.data)
            );
            assertRelationshipData(store, recordData, relationshipData.data, relationshipMeta);
          } else if (relationshipMeta.kind === 'hasMany') {
            assert(
              `A ${
                this.modelName
              } record was pushed into the store with the value of ${relationshipName} being '${inspect(
                relationshipData.data
              )}', but ${relationshipName} is a hasMany relationship so the value must be an array. You should probably check your data payload or serializer.`,
              Array.isArray(relationshipData.data)
            );
            if (Array.isArray(relationshipData.data)) {
              for (let i = 0; i < relationshipData.data.length; i++) {
                assertRelationshipData(
                  store,
                  recordData,
                  relationshipData.data[i],
                  relationshipMeta
                );
              }
            }
          }
        }
      }

      let relationship = this._relationships.get(relationshipName);

      relationship.push(relationshipData);
    }
  }
開發者ID:code0100fun,項目名稱:data,代碼行數:72,代碼來源:record-data.ts

示例10: create

  create(
    element: Simple.Element,
    _state: Opaque,
    args: Arguments,
    _dynamicScope: DynamicScope,
    dom: any
  ) {
    let { named, positional, tag } = args.capture();
    let implicitTarget: any;
    let actionName;
    let actionNameRef: any;
    if (positional.length > 1) {
      implicitTarget = positional.at(0);
      actionNameRef = positional.at(1);

      if (actionNameRef[INVOKE]) {
        actionName = actionNameRef;
      } else {
        let actionLabel = actionNameRef._propertyKey;
        actionName = actionNameRef.value();

        assert(
          'You specified a quoteless path, `' +
            actionLabel +
            '`, to the ' +
            '{{action}} modifier which did not resolve to an action name (a ' +
            'string). Perhaps you meant to use a quoted actionName? (e.g. ' +
            '{{action "' +
            actionLabel +
            '"}}).',
          typeof actionName === 'string' || typeof actionName === 'function'
        );

        if (DEBUG && EMBER_NATIVE_DECORATOR_SUPPORT) {
          let implicitTargetValue = implicitTarget.value();

          warn(
            `You passed a method, ${actionLabel}, to the {{action}} modifier which was not decorated with the '@action' decorator. All actions should be decorated with the '@action' decorator.`,
            typeof actionName !== 'function' ||
              !implicitTargetValue ||
              implicitTargetValue[actionLabel] !== actionName ||
              actionName[ACTION_METHOD] === true,
            {
              id: 'action-without-decorator',
            }
          );
        }
      }
    }

    let actionArgs: any[] = [];
    // The first two arguments are (1) `this` and (2) the action name.
    // Everything else is a param.
    for (let i = 2; i < positional.length; i++) {
      actionArgs.push(positional.at(i));
    }

    let actionId = uuid();
    return new ActionState(
      element,
      actionId,
      actionName,
      actionArgs,
      named,
      positional,
      implicitTarget,
      dom,
      tag
    );
  }
開發者ID:habdelra,項目名稱:ember.js,代碼行數:70,代碼來源:action.ts


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