MCPcopy Create free account
hub / github.com/DavidHDev/react-bits / AutoBind

Function AutoBind

src/content/Components/FlyingPosters/FlyingPosters.jsx:100–127  ·  view source on GitHub ↗
(self, { include, exclude } = {})

Source from the content-addressed store, hash-verified

98`;
99
100function AutoBind(self, { include, exclude } = {}) {
101 const getAllProperties = object => {
102 const properties = new Set();
103 do {
104 for (const key of Reflect.ownKeys(object)) {
105 properties.add([object, key]);
106 }
107 } while ((object = Reflect.getPrototypeOf(object)) && object !== Object.prototype);
108 return properties;
109 };
110
111 const filter = key => {
112 const match = pattern => (typeof pattern === 'string' ? key === pattern : pattern.test(key));
113
114 if (include) return include.some(match);
115 if (exclude) return !exclude.some(match);
116 return true;
117 };
118
119 for (const [object, key] of getAllProperties(self.constructor.prototype)) {
120 if (key === 'constructor' || !filter(key)) continue;
121 const descriptor = Reflect.getOwnPropertyDescriptor(object, key);
122 if (descriptor && typeof descriptor.value === 'function') {
123 self[key] = self[key].bind(self);
124 }
125 }
126 return self;
127}
128
129function lerp(p1, p2, t) {
130 return p1 + (p2 - p1) * t;

Callers 1

constructorMethod · 0.70

Calls 3

getAllPropertiesFunction · 0.70
filterFunction · 0.70
bindMethod · 0.45

Tested by

no test coverage detected