mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-15 01:59:57 +00:00
First bit of real UI code landed
This commit is contained in:
15
src/client/initial-app/util.ts
Normal file
15
src/client/initial-app/util.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/** Creates a function ref that assigns its value to a given property of an object.
|
||||
* @example
|
||||
* // element is stored as `this.foo` when rendered.
|
||||
* <div ref={linkRef(this, 'foo')} />
|
||||
*/
|
||||
export function linkRef<T>(obj: any, name: string) {
|
||||
const refName = `$$ref_${name}`;
|
||||
let ref = obj[refName];
|
||||
if (!ref) {
|
||||
ref = obj[refName] = (c: T) => {
|
||||
obj[name] = c;
|
||||
};
|
||||
}
|
||||
return ref;
|
||||
}
|
||||
Reference in New Issue
Block a user