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

Function AutoBind

src/tailwind/Components/FlyingPosters/FlyingPosters.jsx:98–125  ·  view source on GitHub ↗
(self, { include, exclude } = {})

Source from the content-addressed store, hash-verified

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