Skip to content
This repository was archived by the owner on Feb 9, 2020. It is now read-only.

Commit a2b6e48

Browse files
gary-bSomeKittens
authored andcommitted
fix(inspectedApp): read posted data structure correctly
inspectedApp processes message objects posted from ngHint. It was looking for properties on the root of the object that exist in a nested object. This caused the Batarang scope tree to appear blank.
1 parent 02e96cf commit a2b6e48

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

panel/components/inspected-app/inspected-app.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,21 @@ function inspectedAppService($rootScope, $q) {
8888
});
8989
} else if (hint.event === 'scope:new') {
9090
addNewScope(hint);
91-
} else if (hint.id && scopes[hint.id]) {
92-
var scope = scopes[hint.id];
91+
} else if (hint.data.id && scopes[hint.data.id]) {
92+
var scope = scopes[hint.data.id];
9393
if (hint.event === 'scope:destroy') {
9494
if (scope.parent) {
9595
scope.parent.children.splice(scope.parent.children.indexOf(child), 1);
9696
}
97-
delete scopes[hint.id];
97+
delete scopes[hint.data.id];
9898
} else if (hint.event === 'model:change') {
99-
scope.models[hint.path] = (typeof hint.value === 'undefined') ?
100-
undefined : JSON.parse(hint.value);
99+
scope.models[hint.data.path] = (typeof hint.data.value === 'undefined') ?
100+
undefined : JSON.parse(hint.data.value);
101101
} else if (hint.event === 'scope:link') {
102-
scope.descriptor = hint.descriptor;
102+
scope.descriptor = hint.data.descriptor;
103103
}
104104
}
105-
$rootScope.$broadcast(hint.event, hint);
105+
$rootScope.$broadcast(hint.event, hint.data);
106106
}
107107
}
108108

@@ -112,13 +112,13 @@ function inspectedAppService($rootScope, $q) {
112112
}
113113

114114
function addNewScope (hint) {
115-
scopes[hint.child] = {
116-
parent: hint.parent,
115+
scopes[hint.data.child] = {
116+
parent: hint.data.parent,
117117
children: [],
118118
models: {}
119119
};
120-
if (scopes[hint.parent]) {
121-
scopes[hint.parent].children.push(hint.child);
120+
if (scopes[hint.data.parent]) {
121+
scopes[hint.data.parent].children.push(hint.data.child);
122122
}
123123
}
124124

panel/components/inspected-app/inspected-app.spec.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
'use strict';
22

33
describe('inspectedApp', function() {
4-
var inspectedApp, port;
4+
var inspectedApp, rootScope, port;
55

66
beforeEach(function() {
77
module('batarang.inspected-app')
88
window.chrome = createMockChrome();
9-
inject(function(_inspectedApp_) {
9+
inject(function(_inspectedApp_, _$rootScope_) {
1010
inspectedApp = _inspectedApp_;
11+
rootScope = _$rootScope_;
12+
spyOn(rootScope, '$broadcast');
1113
});
1214
});
1315

@@ -26,20 +28,27 @@ describe('inspectedApp', function() {
2628
}));
2729

2830
it('should track new scopes', inject(function ($browser) {
29-
port.onMessage.trigger(JSON.stringify({ event: 'scope:new', child: 1 }));
31+
port.onMessage.trigger(JSON.stringify({ event: 'scope:new', data: { child: 1 } }));
3032
$browser.defer.flush();
3133

3234
expect(inspectedApp.scopes).toEqual({ 1: { parent: undefined, children: [], models: {} } });
3335
}));
3436

3537
it('should track updates to scope descriptors', inject(function ($browser) {
36-
port.onMessage.trigger(JSON.stringify({ event: 'scope:new', child: 1 }));
37-
port.onMessage.trigger(JSON.stringify({ event: 'scope:link', id: 1, descriptor: 'pasta' }));
38+
port.onMessage.trigger(JSON.stringify({ event: 'scope:new', data: { child: 1 } }));
39+
port.onMessage.trigger(JSON.stringify({ event: 'scope:link', data: { id: 1, descriptor: 'pasta' } }));
3840
$browser.defer.flush();
3941

4042
expect(inspectedApp.scopes[1].descriptor).toBe('pasta');
4143
}));
42-
})
44+
it('should broadcast message from $rootScope', inject(function ($browser) {
45+
var message = { event: 'scope:new', data: { child: 1 } };
46+
port.onMessage.trigger(JSON.stringify(message));
47+
$browser.defer.flush();
48+
49+
expect(rootScope.$broadcast).toHaveBeenCalledWith(message.event, message.data);
50+
}));
51+
});
4352

4453
describe('watch', function () {
4554
it('should call chrome devtools APIs', function() {

0 commit comments

Comments
 (0)