Skip to content
This repository was archived by the owner on Mar 13, 2018. It is now read-only.

Commit 35f5c69

Browse files
committed
getInstanceModel -> prepareInstanceModel
R=arv BUG= Review URL: https://codereview.appspot.com/13577043
1 parent ad64879 commit 35f5c69

2 files changed

Lines changed: 30 additions & 19 deletions

File tree

src/TemplateBinding.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,11 +1012,13 @@
10121012
return;
10131013
}
10141014

1015-
var delegate = template.bindingDelegate;
1016-
var delegateInstanceModelFn =
1017-
delegate && typeof delegate.getInstanceModel === 'function' ?
1018-
delegate.getInstanceModel : undefined;
1019-
1015+
if (this.instanceModelFn_ === undefined) {
1016+
var delegate = template.bindingDelegate;
1017+
if (delegate && typeof delegate.prepareInstanceModel === 'function')
1018+
this.instanceModelFn_ = delegate.prepareInstanceModel(template);
1019+
if (typeof this.instanceModelFn_ !== 'function')
1020+
this.instanceModelFn_ = false;
1021+
}
10201022

10211023
var instanceCache = new Map;
10221024
var removeDelta = 0;
@@ -1042,8 +1044,8 @@
10421044
bound = instanceNodes.bound;
10431045
} else {
10441046
bound = [];
1045-
if (delegateInstanceModelFn)
1046-
model = delegateInstanceModelFn(template, model);
1047+
if (this.instanceModelFn_)
1048+
model = this.instanceModelFn_(model);
10471049

10481050
if (model !== undefined) {
10491051
fragment = this.templateElement_.createInstance(model,

tests/tests.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,28 +1918,31 @@ suite('Binding Delegate API', function() {
19181918
var testData = [
19191919
{
19201920
template: template,
1921+
},
1922+
{
19211923
model: model[0],
19221924
altModel: { foo: 'a' }
19231925
},
19241926
{
1925-
template: template,
19261927
model: model[1],
19271928
altModel: { foo: 'b' }
19281929
},
19291930
{
1930-
template: template,
19311931
model: model[2],
19321932
altModel: { foo: 'c' }
19331933
}
19341934
];
19351935

19361936
var delegate = {
1937-
getInstanceModel: function(template, model) {
1937+
prepareInstanceModel: function(template) {
19381938
var data = testData.shift();
1939-
19401939
assert.strictEqual(data.template, template);
1941-
assert.strictEqual(data.model, model);
1942-
return data.altModel;
1940+
1941+
return function(model) {
1942+
data = testData.shift();
1943+
assert.strictEqual(data.model, model);
1944+
return data.altModel;
1945+
}
19431946
}
19441947
};
19451948

@@ -1961,22 +1964,28 @@ suite('Binding Delegate API', function() {
19611964
'<template repeat>' +
19621965
'{{}}</template>');
19631966
var template = div.firstChild;
1964-
var count = 0;
1967+
var prepareCount = 0;
1968+
var callCount = 0;
19651969

19661970
var delegate = {
1967-
getInstanceModel: function(template, model) {
1968-
count++;
1969-
return model;
1971+
prepareInstanceModel: function(template) {
1972+
prepareCount++;
1973+
return function(model) {
1974+
callCount++;
1975+
return model;
1976+
};
19701977
}
19711978
};
19721979

19731980
recursivelySetTemplateModel(div, model, delegate);
19741981
Platform.performMicrotaskCheckpoint();
1975-
assert.strictEqual(3, count);
1982+
assert.strictEqual(1, prepareCount);
1983+
assert.strictEqual(3, callCount);
19761984

19771985
model.reverse();
19781986
Platform.performMicrotaskCheckpoint();
1979-
assert.strictEqual(3, count);
1987+
assert.strictEqual(1, prepareCount);
1988+
assert.strictEqual(3, callCount);
19801989
});
19811990

19821991
test('Basic', function() {

0 commit comments

Comments
 (0)