diff --git a/src/component.ts b/src/component.ts index 69b98f6..9f4db12 100644 --- a/src/component.ts +++ b/src/component.ts @@ -270,20 +270,22 @@ class LoopComponent extends Component { private f: ( o: L ) => Child | Now> | Result | Now>, - private placeholderNames?: string[] + private placeholderNames?: (keyof L)[] ) { super(); } run(parent: DomApi, destroyed: Future): Out { let placeholderObject: any = { destroyed }; - if (supportsProxy) { + if (this.placeholderNames !== undefined) { + for (const name of this.placeholderNames) { + placeholderObject[name] = placeholder(); + } + } else if (supportsProxy) { placeholderObject = new Proxy(placeholderObject, placeholderProxyHandler); } else { - if (this.placeholderNames !== undefined) { - for (const name of this.placeholderNames) { - placeholderObject[name] = placeholder(); - } - } + throw new Error( + "component called with no list of names and proxies are not supported." + ); } const res = this.f(placeholderObject); const result = Now.is(res) ? runNow | Result>(res) : res; @@ -307,15 +309,15 @@ class LoopComponent extends Component { export function component( f: (l: L) => Child | Now>, - placeholderNames?: string[] + placeholderNames?: (keyof L)[] ): Component<{}, {}>; export function component( f: (l: L) => Result | Now>, - placeholderNames?: string[] + placeholderNames?: (keyof L)[] ): Component; export function component( f: (l: L) => Child | Now> | Result | Now>, - placeholderNames?: string[] + placeholderNames?: (keyof L)[] ): Component { const f2 = isGeneratorFunction(f) ? fgo(f) : f; return new LoopComponent(f2, placeholderNames);