Skip to content

Commit

Permalink
Props Iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
brainkim committed Oct 12, 2020
1 parent 274b914 commit 79e1298
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions crank.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,24 @@ class Context {

// flags
this._isUpdating = false;
this._isIterating = false;
this._isDone = false;
}

refresh() {
return stepCtx(this);
}

*[Symbol.iterator]() {
while (!this._isDone) {
if (this._isIterating) {
throw new Error("Context iterated twice without a yield");
}

this._isIterating = true;
yield this._el.props;
}
}
}

function stepCtx(ctx) {
Expand All @@ -313,6 +325,7 @@ function stepCtx(ctx) {
}

const iteration = ctx._iter.next();
ctx._isIterating = false;
if (iteration.done) {
ctx._isDone = true;
}
Expand Down

0 comments on commit 79e1298

Please sign in to comment.