• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

excaliburjs / Excalibur / 11648280104

03 Nov 2024 03:55AM UTC coverage: 90.187% (-0.03%) from 90.219%
11648280104

push

github

web-flow
fix: [#3078] Pointer lastWorldPosition updates when the camera does (#3245)


Closes #3078

5863 of 7461 branches covered (78.58%)

15 of 17 new or added lines in 5 files covered. (88.24%)

13 existing lines in 2 files now uncovered.

12848 of 14246 relevant lines covered (90.19%)

25261.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

60.47
/src/engine/Util/Watch.ts
1
/**
2
 * Watch an object with a proxy, only fires if property value is different
3
 */
4
export function watch<T extends object>(type: T, change: (type: T) => any): T {
5
  if (!type) {
72,566!
6
    return type;
×
7
  }
8
  if ((type as any).__isProxy === undefined) {
72,566✔
9
    // expando hack to mark a proxy
10
    return new Proxy(type, {
72,562✔
11
      set: (obj, prop, value) => {
12
        // The default behavior to store the value
13
        if ((obj as any)[prop] !== value) {
2!
14
          (obj as any)[prop] = value;
2✔
15
          // Avoid watching private junk
16
          if (typeof prop === 'string') {
2!
17
            if (prop[0] !== '_') {
2!
18
              change(obj);
2✔
19
            }
20
          }
21
        }
22
        // Indicate success
23
        return true;
2✔
24
      },
25
      get: (obj, prop) => {
26
        if (prop !== '__isProxy') {
546,145✔
27
          return (obj as any)[prop];
546,141✔
28
        }
29
        return true;
4✔
30
      }
31
    });
32
  }
33
  return type;
4✔
34
}
35

36
const createHandler = <T>(path: string[] = [], change: (type: T) => any, typeType: T) => ({
14,822!
37
  get: (target: T, key: string): any => {
38
    if (key === '__isProxy') {
12,982!
39
      return true;
×
40
    }
41
    if (typeof (target as any)[key] === 'object' && (target as any)[key] != null) {
12,982✔
42
      return new Proxy((target as any)[key], createHandler<any>([...path, key as string], change, typeType));
4,118✔
43
    }
44
    return (target as any)[key];
8,864✔
45
  },
46
  set: (target: T, key: string, value: any) => {
47
    if (typeof key === 'string') {
1!
48
      if (key[0] !== '_') {
1!
49
        change(typeType);
1✔
50
      }
51
    }
52
    (target as any)[key] = value;
1✔
53
    return true;
1✔
54
  }
55
});
56

57
/**
58
 *
59
 */
60
export function watchDeep<T extends object>(type: T, change: (type: T) => any): T {
61
  if (!type) {
10,704!
62
    return type;
×
63
  }
64
  if ((type as any).__isProxy === undefined) {
10,704!
65
    // expando hack to mark a proxy
66
    return new Proxy(type, createHandler<T>([], change, type));
10,704✔
67
  }
68
  return type;
×
69
}
70

71
/**
72
 * Watch an object with a proxy, fires change on any property value change
73
 */
74
export function watchAny<T extends object>(type: T, change: (type: T) => any): T {
UNCOV
75
  if (!type) {
×
76
    return type;
×
77
  }
UNCOV
78
  if ((type as any).__isProxy === undefined) {
×
79
    // expando hack to mark a proxy
UNCOV
80
    return new Proxy(type, {
×
81
      set: (obj, prop, value) => {
82
        // The default behavior to store the value
UNCOV
83
        (obj as any)[prop] = value;
×
84
        // Avoid watching private junk
UNCOV
85
        if (typeof prop === 'string') {
×
UNCOV
86
          if (prop[0] !== '_') {
×
UNCOV
87
            change(obj);
×
88
          }
89
        }
90

91
        // Indicate success
UNCOV
92
        return true;
×
93
      },
94
      get: (obj, prop) => {
UNCOV
95
        if (prop !== '__isProxy') {
×
UNCOV
96
          return (obj as any)[prop];
×
97
        }
UNCOV
98
        return true;
×
99
      }
100
    });
101
  }
UNCOV
102
  return type;
×
103
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc