Skip to content

Commit 784dd4e

Browse files
committed
WIP: Igor's code review changes
1 parent 547191a commit 784dd4e

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

src/ng/interpolate.js

+15-12
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ function $InterpolateProvider() {
169169
if (!mustHaveExpression || hasInterpolation) {
170170
var concat = new Array(parts.length),
171171
expressions = {};
172+
172173
forEach(parts, function (value, index) {
173174
if (isFunction(value)) {
174175
expressions[index] = value;
@@ -177,49 +178,51 @@ function $InterpolateProvider() {
177178
concat[index] = value;
178179
}
179180
});
181+
180182
// computes all the interpolations and returns the resulting string
181-
// a specific index might already be computed (cz of the scope's dirty-checking),
183+
// a specific index might already be computed (thanks to the scope's dirty-checking),
182184
// and so its expression shouldn't be executed a 2nd time
183185
// also populates the lastValues of custom watchers for internal dirty-checking
184-
var getTextValue = function (scope, computedIndex, computedValue, lastValues) {
186+
//TODO(i): rename to getConcatValue
187+
var getTextValue = function(scope, computedIndex, computedValue, lastValues) {
185188
try {
189+
186190
forEach(expressions, function (expression, index) {
187-
concat[index] = index == computedIndex
191+
concat[index] = (index === computedIndex)
188192
? computedValue
189193
: getStringValue(expression(scope));
190194

191195
if (lastValues) lastValues[index] = concat[index];
192196
});
193197
return concat.join('');
194-
}
195-
catch(err) {
198+
199+
} catch(err) {
196200
var newErr = $interpolateMinErr('interr', "Can't interpolate: {0}\n{1}", text,
197201
err.toString());
198202
$exceptionHandler(newErr);
199203
}
200204
};
201-
var getStringValue = function (value) {
205+
206+
var getStringValue = function(value) {
202207
value = trustedContext
203208
? $sce.getTrusted(trustedContext, value)
204209
: $sce.valueOf(value);
205210

206-
if (value === null || isUndefined(value)) {
211+
if (value == null) {
207212
return '';
208213
}
209214
return isString(value) ? value : toJson(value);
210215
};
211216

212-
fn = function(scope) {
213-
return getTextValue(scope);
214-
};
217+
fn = getTextValue;
215218
fn.exp = text;
216219
fn.parts = parts;
217220

218221
// watches each interpolation separately for performance
219-
fn.$$beWatched = function (scope, origListener, objectEquality) {
222+
fn.$$beWatched = function(scope, origListener, objectEquality) {
220223
var lastTextValue, lastValues = {}, watchersRm = [];
221224

222-
forEach(expressions, function (expression, index) {
225+
forEach(expressions, function(expression, index) {
223226
watchersRm.push(scope.$watch(function watchInterpolatedExpr(scope) {
224227
try {
225228
return getStringValue(expression(scope));

src/ng/rootScope.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ function $RootScopeProvider(){
315315
* @returns {function()} Returns a deregistration function for this listener.
316316
*/
317317
$watch: function(watchExp, listener, objectEquality) {
318-
if (isFunction(watchExp.$$beWatched)) {
318+
if (watchExp.$$beWatched) {
319319
return watchExp.$$beWatched(this, listener, objectEquality, watchExp);
320320
}
321321
var scope = this,

test/ng/interpolateSpec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ describe('$interpolate', function() {
1010

1111
it('should return undefined when there are no bindings and textOnly is set to true',
1212
inject(function($interpolate) {
13+
//TODO(i): this is weird
1314
expect($interpolate('some text', true)).toBeNull();
1415
}));
1516

@@ -319,5 +320,4 @@ describe('$interpolate', function() {
319320
expect(nbCalls).toBe(4);
320321
}));
321322
})
322-
323323
});

0 commit comments

Comments
 (0)