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


TypeScript polyfills.assign函數代碼示例

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


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

示例1: assign

(() => { /* assign */
    assign({}, { a: 'b'});
    assign({}, { a: 'b'}).a; // $ExpectType string
    assign({ a: 6 }, { a: 'b'}).a; // $ExpectType string
    assign({ a: 6 }, {}).a; // $ExpectType number
    assign({ b: 6 }, {}).a; // $ExpectError
    assign({}, { b: 6 }, {}).b; // $ExpectType number
    assign({ a: 'hello' }, { b: 6 }, {}).a; // $ExpectType string
    assign({ a: 'hello' }, { b: 6 }, { a: true }).a; // $ExpectType boolean
    assign({ a: 'hello' }, '', { a: true }).a; // $ExpectError
    assign({ d: ['gobias industries'] }, { a: 'hello' }, { b: 6 }, { a: true }).d; // $ExpectType string[]
})();
開發者ID:AlexGalays,項目名稱:DefinitelyTyped,代碼行數:12,代碼來源:ember__polyfills-tests.ts

示例2: state

  /*
    Ember Data has 3 buckets for storing the value of an attribute on an internalModel.

    `_data` holds all of the attributes that have been acknowledged by
    a backend via the adapter. When rollbackAttributes is called on a model all
    attributes will revert to the record's state in `_data`.

    `_attributes` holds any change the user has made to an attribute
    that has not been acknowledged by the adapter. Any values in
    `_attributes` are have priority over values in `_data`.

    `_inFlightAttributes`. When a record is being synced with the
    backend the values in `_attributes` are copied to
    `_inFlightAttributes`. This way if the backend acknowledges the
    save but does not return the new state Ember Data can copy the
    values from `_inFlightAttributes` to `_data`. Without having to
    worry about changes made to `_attributes` while the save was
    happenign.


    Changed keys builds a list of all of the values that may have been
    changed by the backend after a successful save.

    It does this by iterating over each key, value pair in the payload
    returned from the server after a save. If the `key` is found in
    `_attributes` then the user has a local changed to the attribute
    that has not been synced with the server and the key is not
    included in the list of changed keys.



    If the value, for a key differs from the value in what Ember Data
    believes to be the truth about the backend state (A merger of the
    `_data` and `_inFlightAttributes` objects where
    `_inFlightAttributes` has priority) then that means the backend
    has updated the value and the key is added to the list of changed
    keys.

    @method _changedKeys
    @private
  */
  /*
      TODO IGOR DAVID
      There seems to be a potential bug here, where we will return keys that are not
      in the schema
  */
  _changedKeys(updates) {
    let changedKeys: string[] = [];

    if (updates) {
      let original, i, value, key;
      let keys = Object.keys(updates);
      let length = keys.length;
      let hasAttrs = this.hasChangedAttributes();
      let attrs;
      if (hasAttrs) {
        attrs = this._attributes;
      }

      original = assign(Object.create(null), this._data, this.__inFlightAttributes);

      for (i = 0; i < length; i++) {
        key = keys[i];
        value = updates[key];

        // A value in _attributes means the user has a local change to
        // this attributes. We never override this value when merging
        // updates from the backend so we should not sent a change
        // notification if the server value differs from the original.
        if (hasAttrs === true && attrs[key] !== undefined) {
          continue;
        }

        if (!isEqual(original[key], value)) {
          changedKeys.push(key);
        }
      }
    }

    return changedKeys;
  }
開發者ID:code0100fun,項目名稱:data,代碼行數:81,代碼來源:record-data.ts

示例3: create

 static create(options: any) {
   if (options) {
     return super.create(assign({}, injections, options));
   } else {
     return super.create(injections);
   }
 }
開發者ID:GreatWizard,項目名稱:ember.js,代碼行數:7,代碼來源:outlet.ts

示例4: buildMouseEvent

// eslint-disable-next-line require-jsdoc
function buildMouseEvent(type: MouseEventType, options: any = {}) {
  let event;
  let eventOpts: any = assign({ view: window }, DEFAULT_EVENT_OPTIONS, options);
  if (MOUSE_EVENT_CONSTRUCTOR) {
    event = new MouseEvent(type, eventOpts);
  } else {
    try {
      event = document.createEvent('MouseEvents');
      event.initMouseEvent(
        type,
        eventOpts.bubbles,
        eventOpts.cancelable,
        window,
        eventOpts.detail,
        eventOpts.screenX,
        eventOpts.screenY,
        eventOpts.clientX,
        eventOpts.clientY,
        eventOpts.ctrlKey,
        eventOpts.altKey,
        eventOpts.shiftKey,
        eventOpts.metaKey,
        eventOpts.button,
        eventOpts.relatedTarget
      );
    } catch (e) {
      event = buildBasicEvent(type, options);
    }
  }

  return event;
}
開發者ID:switchfly,項目名稱:ember-test-helpers,代碼行數:33,代碼來源:fire-event.ts

示例5: compileOptions

export default function compileOptions(_options: Partial<CompileOptions>): PrecompileOptions {
  let options = assign({ meta: {} }, _options, {
    customizeComponentName(tagname: string): string {
      return COMPONENT_NAME_SIMPLE_DASHERIZE_CACHE.get(tagname);
    },
  });

  // move `moduleName` into `meta` property
  if (options.moduleName) {
    let meta = options.meta;
    meta.moduleName = options.moduleName;
  }

  if (!options.plugins) {
    options.plugins = { ast: [...USER_PLUGINS, ...PLUGINS] };
  } else {
    let potententialPugins = [...USER_PLUGINS, ...PLUGINS];
    let providedPlugins = options.plugins.ast.map(plugin => wrapLegacyPluginIfNeeded(plugin));
    let pluginsToAdd = potententialPugins.filter(plugin => {
      return options.plugins!.ast.indexOf(plugin) === -1;
    });
    options.plugins.ast = providedPlugins.concat(pluginsToAdd);
  }

  return options;
}
開發者ID:GreatWizard,項目名稱:ember.js,代碼行數:26,代碼來源:compile-options.ts

示例6: accumulateQueryParamDescriptors

function accumulateQueryParamDescriptors(_desc: QueryParam, accum: {}) {
  let desc: {} = _desc;
  let tmp: {};
  if (typeof desc === 'string') {
    tmp = {};
    tmp[desc] = { as: null };
    desc = tmp;
  }

  for (let key in desc) {
    if (!desc.hasOwnProperty(key)) {
      return;
    }

    let singleDesc = desc[key];
    if (typeof singleDesc === 'string') {
      singleDesc = { as: singleDesc };
    }

    tmp = accum[key] || { as: null, scope: 'model' };
    assign(tmp, singleDesc);

    accum[key] = tmp;
  }
}
開發者ID:Turbo87,項目名稱:ember.js,代碼行數:25,代碼來源:utils.ts

示例7: queryParams

/**
  This is a helper to be used in conjunction with the link-to helper.
  It will supply url query parameters to the target route.

  Example

  ```handlebars
  {{#link-to 'posts' (query-params direction="asc")}}Sort{{/link-to}}
  ```

  @method query-params
  @for Ember.Templates.helpers
  @param {Object} hash takes a hash of query parameters
  @return {Object} A `QueryParams` object for `{{link-to}}`
  @public
*/
function queryParams({ positional, named }: CapturedArguments) {
  // tslint:disable-next-line:max-line-length
  assert(
    "The `query-params` helper only accepts hash parameters, e.g. (query-params queryParamPropertyName='foo') as opposed to just (query-params 'foo')",
    positional.value().length === 0
  );

  return new QueryParams(assign({}, named.value() as any));
}
開發者ID:GreatWizard,項目名稱:ember.js,代碼行數:25,代碼來源:query-param.ts

示例8: assign

 return payload.errors.map(function(error) {
   if (isObject(error)) {
     const ret = assign({}, error);
     ret.status = `${error.status}`;
     return ret;
   } else {
     return {
       status: `${status}`,
       title: error
     };
   }
 });
開發者ID:knownasilya,項目名稱:ember-ajax,代碼行數:12,代碼來源:normalize-error-response.ts

示例9: computed

  resolvedQueryParams: computed('queryParams', function computeLinkToComponentResolvedQueryParams(
    this: any
  ) {
    let resolvedQueryParams = {};
    let queryParams = get(this, 'queryParams');

    if (queryParams !== EMPTY_QUERY_PARAMS) {
      let { values } = queryParams;
      assign(resolvedQueryParams, values);
    }

    return resolvedQueryParams;
  }),
開發者ID:habdelra,項目名稱:ember.js,代碼行數:13,代碼來源:link-to.ts

示例10: nextTickPromise

  return nextTickPromise().then(() => {
    if (!target) {
      throw new Error('Must pass an element or selector to `triggerKeyEvent`.');
    }

    let element = getElement(target);
    if (!element) {
      throw new Error(`Element not found when calling \`triggerKeyEvent('${target}', ...)\`.`);
    }

    if (!eventType) {
      throw new Error(`Must provide an \`eventType\` to \`triggerKeyEvent\``);
    }

    if (!isKeyboardEventType(eventType)) {
      let validEventTypes = KEYBOARD_EVENT_TYPES.join(', ');
      throw new Error(
        `Must provide an \`eventType\` of ${validEventTypes} to \`triggerKeyEvent\` but you passed \`${eventType}\`.`
      );
    }

    let props;
    if (typeof key === 'number') {
      props = { keyCode: key, which: key, key: keyFromKeyCodeAndModifiers(key, modifiers) };
    } else if (typeof key === 'string' && key.length !== 0) {
      let firstCharacter = key[0];
      if (firstCharacter !== firstCharacter.toUpperCase()) {
        throw new Error(
          `Must provide a \`key\` to \`triggerKeyEvent\` that starts with an uppercase character but you passed \`${key}\`.`
        );
      }

      if (isNumeric(key) && key.length > 1) {
        throw new Error(
          `Must provide a numeric \`keyCode\` to \`triggerKeyEvent\` but you passed \`${key}\` as a string.`
        );
      }

      let keyCode = keyCodeFromKey(key);
      props = { keyCode, which: keyCode, key };
    } else {
      throw new Error(`Must provide a \`key\` or \`keyCode\` to \`triggerKeyEvent\``);
    }

    let options = assign(props, modifiers);

    fireEvent(element, eventType, options);

    return settled();
  });
開發者ID:switchfly,項目名稱:ember-test-helpers,代碼行數:50,代碼來源:trigger-key-event.ts


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