當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。