UNPKG

1.6 kBTypeScriptView Raw
1declare module '@ember/utils/lib/is-equal' {
2 /**
3 @module @ember/utils
4 */
5 /**
6 Compares two objects, returning true if they are equal.
7
8 ```javascript
9 import { isEqual } from '@ember/utils';
10
11 isEqual('hello', 'hello'); // true
12 isEqual(1, 2); // false
13 ```
14
15 `isEqual` is a more specific comparison than a triple equal comparison.
16 It will call the `isEqual` instance method on the objects being
17 compared, allowing finer control over when objects should be considered
18 equal to each other.
19
20 ```javascript
21 import { isEqual } from '@ember/utils';
22 import EmberObject from '@ember/object';
23
24 let Person = EmberObject.extend({
25 isEqual(other) { return this.ssn == other.ssn; }
26 });
27
28 let personA = Person.create({name: 'Muhammad Ali', ssn: '123-45-6789'});
29 let personB = Person.create({name: 'Cassius Clay', ssn: '123-45-6789'});
30
31 isEqual(personA, personB); // true
32 ```
33
34 Due to the expense of array comparisons, collections will never be equal to
35 each other even if each of their items are equal to each other.
36
37 ```javascript
38 import { isEqual } from '@ember/utils';
39
40 isEqual([4, 2], [4, 2]); // false
41 ```
42
43 @method isEqual
44 @for @ember/utils
45 @static
46 @param {Object} a first object to compare
47 @param {Object} b second object to compare
48 @return {Boolean}
49 @public
50 */
51 export default function isEqual(a: unknown, b: unknown): boolean;
52}