Skip to content

Commit

Permalink
Make loop handle Component inside Now
Browse files Browse the repository at this point in the history
  • Loading branch information
paldepind committed Aug 19, 2019
1 parent 3c66646 commit cbdd99d
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ const placeholderProxyHandler = {

class LoopComponent<O> extends Component<O, {}> {
constructor(
private f: (o: O) => Child<O>,
private f: (o: O) => Child<O> | Now<Child<O>>,
private placeholderNames?: string[]
) {
super();
Expand All @@ -271,10 +271,9 @@ class LoopComponent<O> extends Component<O, {}> {
}
}
}
const { output } = toComponent(this.f(placeholderObject)).run(
parent,
destroyed
);
const res = this.f(placeholderObject);
const child = Now.is(res) ? runNow(res) : res;
const { output } = toComponent(child).run(parent, destroyed);
const needed = Object.keys(placeholderObject);
for (const name of needed) {
if (name === "destroyed") {
Expand All @@ -290,7 +289,7 @@ class LoopComponent<O> extends Component<O, {}> {
}

export function loop<O extends ReactivesObject>(
f: (o: O) => Component<any, O>,
f: (o: O) => Child<O> | Now<Child<O>>,
placeholderNames?: string[]
): Component<O, {}> {
const f2 = isGeneratorFunction(f) ? fgo<O>(f) : f;
Expand Down

0 comments on commit cbdd99d

Please sign in to comment.