summaryrefslogtreecommitdiffstats
path: root/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/inferno/src/share.js
blob: 9e7d962b8f1774702d76546ca109ad979244a3e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
 * Shared funcs/values
 */

export const ENTER = 13;
export const ESCAPE = 27;

export const filters = {
    all: t => true,
    active: t => !t.completed,
    completed: t => t.completed
}

/**
 * Read the `location.hash` value
 * @return {String}
 */
export function read() {
    return location.hash.replace('#/', '') || 'all';
}

/**
 * Modified `Object.assign` shim
 * - always writes to new object
 * @return {Object}
 */
export function assign() {
    let src;
    let tar = {};
    for (let s = 0; s < arguments.length; s++) {
        src = Object(arguments[s]);
        for (const k in src) {
            tar[k] = src[k];
        }
    }
    return tar;
}

/**
 * Are two Objects equal values?
 * @param  {Object} a
 * @param  {Object} b
 * @return {Boolean}
 */
export function isEqual(a, b) {
    // Create arrays of property names
    const aProps = Object.getOwnPropertyNames(a);
    const bProps = Object.getOwnPropertyNames(b);

    if (aProps.length !== bProps.length) return false;

    for (let i = 0; i < aProps.length; i++) {
        const k = aProps[i];
        if (a[k] !== b[k]) return false;
    }

    return true;
}