本文整理汇总了TypeScript中@ember/utils.isEqual函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isEqual函数的具体用法?TypeScript isEqual怎么用?TypeScript isEqual使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isEqual函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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;
}
示例2: isEqual
(function() {
/** isEqual */
isEqual('foo', 'bar'); // $ExpectType boolean
isEqual(14, 37); // $ExpectType boolean
isEqual(14, '1'); // $ExpectType boolean
isEqual(() => 4, () => 37); // $ExpectType boolean
isEqual(14); // $ExpectError
isEqual(); // $ExpectError
})();