MCPcopy
hub / github.com/preactjs/preact / logCall

Function logCall

test/_util/logCall.js:23–57  ·  view source on GitHub ↗
(obj, method)

Source from the content-addressed store, hash-verified

21 * @param {keyof T} method
22 */
23export function logCall(obj, method) {
24 let old = obj[method];
25 obj[method] = function (...args) {
26 let c = '';
27 for (let i = 0; i < args.length; i++) {
28 if (c) c += ', ';
29 c += serialize(args[i]);
30 }
31
32 let operation;
33 switch (method) {
34 case 'removeChild': {
35 operation = `${serialize(c)}.remove()`;
36 break;
37 }
38 case 'insertBefore': {
39 if (args[1] === null && args.length === 2) {
40 operation = `${serialize(this)}.appendChild(${serialize(args[0])})`;
41 } else {
42 operation = `${serialize(this)}.${String(method)}(${c})`;
43 }
44 break;
45 }
46 default: {
47 operation = `${serialize(this)}.${String(method)}(${c})`;
48 break;
49 }
50 }
51
52 log.push(operation);
53 return old.apply(this, args);
54 };
55
56 return () => (obj[method] = old);
57}
58
59/**
60 * Return log object

Calls 1

serializeFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…