Skip to content

Commit

Permalink
Propagate "updateOneTimeBindings" to if.
Browse files Browse the repository at this point in the history
  • Loading branch information
rluba committed Jul 13, 2018
1 parent 28ceddc commit 7309923
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
8 changes: 8 additions & 0 deletions src/if-core.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { updateBindings } from './repeat-utilities';

/**
* For internal use only. May change without warning.
*/
Expand All @@ -20,6 +22,12 @@ export class IfCore {
this.overrideContext = overrideContext;
}

updateOneTimeBindings() {
if (this.view && this.view.isBound) {
updateBindings(this.view);
}
}

unbind() {
if (this.view === null) {
return;
Expand Down
22 changes: 22 additions & 0 deletions src/repeat-utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,28 @@ export function isOneTime(expression) {
return false;
}

/**
* Forces all one-time bindings in that view to reevaluate.
*/
export function updateBindings(view) {
let j = view.bindings.length;
while (j--) {
updateOneTimeBinding(view.bindings[j]);
}
j = view.controllers.length;
while (j--) {
let k = view.controllers[j].boundProperties.length;
while (k--) {
if (view.controllers[j].viewModel && view.controllers[j].viewModel.updateOneTimeBindings) {
view.controllers[j].viewModel.updateOneTimeBindings();
}
let binding = view.controllers[j].boundProperties[k].binding;
updateOneTimeBinding(binding);
}
}
}


/**
* Forces a binding instance to reevaluate.
*/
Expand Down
15 changes: 2 additions & 13 deletions src/repeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
getItemsSourceExpression,
unwrapExpression,
isOneTime,
updateOneTimeBinding
updateBindings
} from './repeat-utilities';
import {viewsRequireLifecycle} from './analyze-view-factory';
import {AbstractRepeater} from './abstract-repeater';
Expand Down Expand Up @@ -270,17 +270,6 @@ export class Repeat extends AbstractRepeater {
}

updateBindings(view: View) {
let j = view.bindings.length;
while (j--) {
updateOneTimeBinding(view.bindings[j]);
}
j = view.controllers.length;
while (j--) {
let k = view.controllers[j].boundProperties.length;
while (k--) {
let binding = view.controllers[j].boundProperties[k].binding;
updateOneTimeBinding(binding);
}
}
updateBindings(view);
}
}

0 comments on commit 7309923

Please sign in to comment.