Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Commit 0f51832

Browse files
gary-bSomeKittens
authored andcommitted
fix(scopes) maintain id data type
Batarang had an issue were the jsonTree would not update when model:change events were received. This was caused by the fact angular 1.3+ uses int ids while batarang was storing them as keys in objects. It would pass hint the id as a string, hint would find the scope and emit an event, but would also echo back the id as a string. Problem is the jsonTree maintains a type correct version of the Id, and strict comparisons then failed, hence no UI update occurred. Updating so hint always returns the id in the type dictated by the current angular version, regardless of the type of the id passed to it.
1 parent ab57cc4 commit 0f51832

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/modules/scopes.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function decorateRootScope($delegate, $parse) {
4040
value: value
4141
};
4242
hint.emit('model:change', {
43-
id: scopeId,
43+
id: convertIdToOriginalType(scopeId),
4444
path: partialPath,
4545
value: value
4646
});
@@ -247,7 +247,7 @@ function decorateRootScope($delegate, $parse) {
247247
var value = summarize(model.get());
248248
if (value !== model.value) {
249249
hint.emit('model:change', {
250-
id: (angular.version.minor < 3) ? scopeId : parseInt(scopeId),
250+
id: convertIdToOriginalType(scopeId),
251251
path: path,
252252
oldValue: model.value,
253253
value: value
@@ -337,3 +337,7 @@ function isOneTimeBindExp(exp) {
337337
// for a one time bind expression
338338
return exp.charAt(0) === ':' && exp.charAt(1) === ':';
339339
}
340+
341+
function convertIdToOriginalType(scopeId) {
342+
return (angular.version.minor < 3) ? scopeId : parseInt(scopeId, 10);
343+
}

test/scopes.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,15 @@ describe('ngHintScopes', function() {
363363
});
364364
});
365365

366+
it('should accept an id as a string and return the id in the data type the current angular version uses', function() {
367+
hint.watch('' + scope.$id, '');
368+
369+
expect(hint.emit).toHaveBeenCalled();
370+
371+
var args = getArgsOfNthCall(0);
372+
expect(args[0]).toBe('model:change');
373+
expect(args[1].id).toBe(scope.$id);
374+
});
366375
});
367376

368377

0 commit comments

Comments
 (0)