First bit of real UI code landed

This commit is contained in:
Jake Archibald
2020-09-23 14:38:41 +01:00
parent 6573103755
commit 455c868e55
23 changed files with 839 additions and 141 deletions

View 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;
}