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 Mar 18, 2020
1 parent 5e3af9e commit 62a4707
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
7 changes: 7 additions & 0 deletions src/if-core.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ViewFactory, ViewSlot } from 'aurelia-templating';
import { updateBindings } from './repeat-utilities';

/**
* For internal use only. May change without warning.
Expand Down Expand Up @@ -52,6 +53,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
23 changes: 23 additions & 0 deletions src/repeat-utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,29 @@ export function isOneTime(expression) {
return false;
}

/**
* Forces all one-time bindings in that view to reevaluate.
*/
export function updateBindings(view) {
const $view = view as View & { bindings: any[]; controllers: any[] };
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
16 changes: 2 additions & 14 deletions src/repeat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,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 @@ -343,19 +343,7 @@ export class Repeat extends AbstractRepeater {
}

updateBindings(view: View) {
const $view = view as View & { bindings: any[]; controllers: any[] };
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);
}
}

Expand Down

0 comments on commit 62a4707

Please sign in to comment.