Skip to content

Commit

Permalink
Better handling of placeholders in component function
Browse files Browse the repository at this point in the history
  • Loading branch information
paldepind committed Aug 21, 2019
1 parent 9616676 commit 91c07a7
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,20 +270,22 @@ class LoopComponent<L, O> extends Component<O, {}> {
private f: (
o: L
) => Child<L> | Now<Child<L>> | Result<O, L> | Now<Result<O, L>>,
private placeholderNames?: string[]
private placeholderNames?: (keyof L)[]
) {
super();
}
run(parent: DomApi, destroyed: Future<boolean>): Out<O, {}> {
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<Child<L> | Result<O, L>>(res) : res;
Expand All @@ -307,15 +309,15 @@ class LoopComponent<L, O> extends Component<O, {}> {

export function component<L extends ReactivesObject>(
f: (l: L) => Child<L> | Now<Child<L>>,
placeholderNames?: string[]
placeholderNames?: (keyof L)[]
): Component<{}, {}>;
export function component<L extends ReactivesObject, O>(
f: (l: L) => Result<O, L> | Now<Result<O, L>>,
placeholderNames?: string[]
placeholderNames?: (keyof L)[]
): Component<O, {}>;
export function component<L, O extends ReactivesObject>(
f: (l: L) => Child<L> | Now<Child<L>> | Result<O, L> | Now<Result<O, L>>,
placeholderNames?: string[]
placeholderNames?: (keyof L)[]
): Component<O, {}> {
const f2 = isGeneratorFunction(f) ? fgo<L>(f) : f;
return new LoopComponent<L, O>(f2, placeholderNames);
Expand Down

0 comments on commit 91c07a7

Please sign in to comment.