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


TypeScript debug.assert函数代码示例

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


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

示例1: _preloadRelationship

 _preloadRelationship(key, preloadValue) {
   let relationshipMeta = this.modelClass.metaForProperty(key);
   let modelClass = relationshipMeta.type;
   let data;
   if (relationshipMeta.kind === 'hasMany') {
     assert(
       'You need to pass in an array to set a hasMany property on a record',
       Array.isArray(preloadValue)
     );
     data = preloadValue.map(value => this._convertPreloadRelationshipToJSON(value, modelClass));
   } else {
     data = this._convertPreloadRelationshipToJSON(preloadValue, modelClass);
   }
   return { data };
 }
开发者ID:code0100fun,项目名称:data,代码行数:15,代码来源:internal-model.ts

示例2: setPath

function setPath(root: object, path: string, value: any, tolerant?: boolean): any {
  let parts = path.split('.');
  let keyName = parts.pop() as string;

  assert('Property set failed: You passed an empty path', keyName!.trim().length > 0);

  let newPath = parts.join('.');
  let newRoot = getPath(root, newPath);

  if (newRoot !== null && newRoot !== undefined) {
    return set(newRoot, keyName, value);
  } else if (!tolerant) {
    throw new EmberError(`Property set failed: object in path "${newPath}" could not be found.`);
  }
}
开发者ID:sbatson5,项目名称:ember.js,代码行数:15,代码来源:property_set.ts

示例3: writableChainWatchers

 writableChainWatchers(create: (source: object) => any) {
   assert(
     this.isMetaDestroyed()
       ? `Cannot create a new chain watcher for \`${toString(
           this.source
         )}\` after it has been destroyed.`
       : '',
     !this.isMetaDestroyed()
   );
   let ret = this._chainWatchers;
   if (ret === undefined) {
     ret = this._chainWatchers = create(this.source);
   }
   return ret;
 }
开发者ID:csantero,项目名称:ember.js,代码行数:15,代码来源:meta.ts

示例4: assertReservedNamedArguments

export default function assertReservedNamedArguments(env: ASTPluginEnvironment): ASTPlugin {
  let { moduleName } = env.meta;

  return {
    name: 'assert-reserved-named-arguments',

    visitor: {
      PathExpression({ original, loc }: AST.PathExpression) {
        if (isReserved(original)) {
          assert(`${assertMessage(original)} ${calculateLocationDisplay(moduleName, loc)}`);
        }
      },
    },
  };
}
开发者ID:jaswilli,项目名称:ember.js,代码行数:15,代码来源:assert-reserved-named-arguments.ts

示例5: assertRelationshipData

function assertRelationshipData(store, recordData, data, meta) {
  assert(
    `A ${recordData.modelName} record was pushed into the store with the value of ${
      meta.key
    } being '${JSON.stringify(data)}', but ${
      meta.key
    } is a belongsTo relationship so the value must not be an array. You should probably check your data payload or serializer.`,
    !Array.isArray(data)
  );
  assert(
    `Encountered a relationship identifier without a type for the ${meta.kind} relationship '${
      meta.key
    }' on ${recordData}, expected a json-api identifier with type '${
      meta.type
    }' but found '${JSON.stringify(
      data
    )}'. Please check your serializer and make sure it is serializing the relationship payload into a JSON API format.`,
    data === null || (typeof data.type === 'string' && data.type.length)
  );
  assert(
    `Encountered a relationship identifier without an id for the ${meta.kind} relationship '${
      meta.key
    }' on ${recordData}, expected a json-api identifier but found '${JSON.stringify(
      data
    )}'. Please check your serializer and make sure it is serializing the relationship payload into a JSON API format.`,
    data === null || !!coerceId(data.id)
  );
  assert(
    `Encountered a relationship identifier with type '${data.type}' for the ${
      meta.kind
    } relationship '${meta.key}' on ${recordData}, Expected a json-api identifier with type '${
      meta.type
    }'. No model was found for '${data.type}'.`,
    data === null || !data.type || store._hasModelFor(data.type)
  );
}
开发者ID:emberjs,项目名称:data,代码行数:36,代码来源:record-data.ts

示例6: assertSplattributeExpressions

export default function assertSplattributeExpressions(env: ASTPluginEnvironment): ASTPlugin {
  let { moduleName } = env.meta;

  return {
    name: 'assert-splattribute-expressions',

    visitor: {
      PathExpression({ original, loc }) {
        if (original === '...attributes') {
          assert(`${errorMessage()} ${calculateLocationDisplay(moduleName, loc)}`);
        }
      },
    },
  };
}
开发者ID:cibernox,项目名称:ember.js,代码行数:15,代码来源:assert-splattribute-expression.ts

示例7: function

  setupMandatorySetter = function(obj: object, keyName: string | symbol) {
    let desc = getPropertyDescriptor(obj, keyName) || {};

    if (desc.get || desc.set) {
      // if it has a getter or setter, we can't install the mandatory setter.
      // native setters are allowed, we have to assume that they will resolve
      // to tracked properties.
      return;
    }

    if (desc && (!desc.configurable || !desc.writable)) {
      // if it isn't writable anyways, so we shouldn't provide the setter.
      // if it isn't configurable, we can't overwrite it anyways.
      return;
    }

    let setters = MANDATORY_SETTERS.get(obj);

    if (setters === undefined) {
      setters = {};
      MANDATORY_SETTERS.set(obj, setters);
    }

    desc.hadOwnProperty = Object.hasOwnProperty.call(obj, keyName);

    setters[keyName] = desc;

    Object.defineProperty(obj, keyName, {
      configurable: true,
      enumerable: propertyIsEnumerable(obj, keyName),

      get() {
        if (desc.get) {
          return desc.get.call(this);
        } else {
          return desc.value;
        }
      },

      set(value: any) {
        assert(
          `You attempted to update ${this}.${String(keyName)} to "${String(
            value
          )}", but it is being tracked by a tracking context, such as a template, computed property, or observer. In order to make sure the context updates properly, you must invalidate the property when updating it. You can mark the property as \`@tracked\`, or use \`@ember/object#set\` to do this.`
        );
      },
    });
  };
开发者ID:emberjs,项目名称:ember.js,代码行数:48,代码来源:mandatory-setter.ts

示例8: addListener

export function addListener(
  obj: object,
  eventName: string,
  target: object | Function | null,
  method?: Function | string,
  once?: boolean
) {
  assert('You must pass at least an object and event name to addListener', !!obj && !!eventName);

  if (!method && 'function' === typeof target) {
    method = target;
    target = null;
  }

  metaFor(obj).addToListeners(eventName, target, method!, once === true);
}
开发者ID:GreatWizard,项目名称:ember.js,代码行数:16,代码来源:events.ts

示例9: extractRecordDataFromRecord

function extractRecordDataFromRecord(recordOrPromiseRecord) {
  if (!recordOrPromiseRecord) {
    return null;
  }

  if (recordOrPromiseRecord.then) {
    let content = recordOrPromiseRecord.get && recordOrPromiseRecord.get('content');
    assert(
      'You passed in a promise that did not originate from an EmberData relationship. You can only pass promises that come from a belongsTo or hasMany relationship to the get call.',
      content !== undefined
    );
    return content ? recordDataFor(content) : null;
  }

  return recordDataFor(recordOrPromiseRecord);
}
开发者ID:emberjs,项目名称:data,代码行数:16,代码来源:internal-model.ts

示例10: prepareArgs

  prepareArgs(_state: InternalDefinitionState, args: Arguments): PreparedArguments {
    assert(
      'The `<Input />` component does not take any positional arguments',
      args.positional.length === 0
    );

    let __ARGS__: Dict<VersionedPathReference> = args.named.capture().map;

    return {
      positional: EMPTY_POSITIONAL_ARGS,
      named: {
        __ARGS__: new RootReference(__ARGS__),
        type: args.named.get('type'),
      },
    };
  }
开发者ID:elwayman02,项目名称:ember.js,代码行数:16,代码来源:input.ts


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