You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
2.4 KiB
JavaScript
95 lines
2.4 KiB
JavaScript
12 years ago
|
// Service for running code in the context of the application being debugged
|
||
11 years ago
|
angular.module('panelApp').
|
||
|
|
||
|
factory('appModel', function ($rootScope, chromeExtension) {
|
||
12 years ago
|
|
||
11 years ago
|
var _scopeTreeCache = {},
|
||
|
_scopeCache = {},
|
||
11 years ago
|
_rootScopeIdCache = [];
|
||
12 years ago
|
|
||
11 years ago
|
$rootScope.$on('referesh', function clearCaches () {
|
||
|
emptyObject(_scopeCache);
|
||
|
emptyObject(_scopeTreeCache);
|
||
|
emptyArray(_rootScopeIdCache);
|
||
12 years ago
|
});
|
||
|
|
||
11 years ago
|
function emptyObject (obj) {
|
||
|
for (prop in obj) {
|
||
|
if (obj.hasOwnProperty(obj)) {
|
||
|
delete obj[prop];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function emptyArray (arr) {
|
||
|
arr.splice(0, arr.length);
|
||
|
}
|
||
|
|
||
|
$rootScope.$on('scopeChange', function (ev, data) {
|
||
|
if (_rootScopeIdCache.indexOf(data.id) === -1) {
|
||
|
_rootScopeIdCache.push(data.id);
|
||
|
$rootScope.$broadcast('rootScopeChange', _rootScopeIdCache);
|
||
11 years ago
|
}
|
||
|
_scopeTreeCache[data.id] = data.scope;
|
||
|
});
|
||
|
|
||
11 years ago
|
$rootScope.$on('scopeDeleted', function (ev, data) {
|
||
|
_rootScopeIdCache.splice(_rootScopeIdCache.indexOf(data.id), 1);
|
||
|
$rootScope.$broadcast('rootScopeChange', _rootScopeIdCache);
|
||
|
delete _scopeTreeCache[data.id];
|
||
|
});
|
||
|
|
||
12 years ago
|
return {
|
||
11 years ago
|
getRootScopeIds: function () {
|
||
|
return _rootScopeIdCache.slice();
|
||
12 years ago
|
},
|
||
|
|
||
11 years ago
|
getModel: function (id, path, callback) {
|
||
12 years ago
|
chromeExtension.eval(function (window, args) {
|
||
11 years ago
|
return window.__ngDebug.getSomeModel(args.id, args.path);
|
||
|
}, {
|
||
|
id: id,
|
||
|
path: path
|
||
|
}, callback);
|
||
|
},
|
||
|
|
||
|
setModel: function (id, path, value, callback) {
|
||
|
chromeExtension.eval(function (window, args) {
|
||
|
return window.__ngDebug.setSomeModel(args.id, args.path, args.value);
|
||
|
}, {
|
||
|
id: id,
|
||
|
path: path,
|
||
|
value: value
|
||
|
}, callback);
|
||
11 years ago
|
},
|
||
|
|
||
11 years ago
|
watchModel: function (id, path) {
|
||
|
chromeExtension.eval(function (window, args) {
|
||
|
return window.__ngDebug.watchModel(args.id, args.path);
|
||
|
}, {
|
||
|
id: id,
|
||
|
path: path
|
||
|
});
|
||
|
},
|
||
|
|
||
|
unwatchModel: function (id, path) {
|
||
11 years ago
|
chromeExtension.eval(function (window, args) {
|
||
11 years ago
|
return window.__ngDebug.unwatchModel(args.id, args.path);
|
||
|
}, {
|
||
|
id: id,
|
||
|
path: path
|
||
11 years ago
|
});
|
||
|
},
|
||
|
|
||
11 years ago
|
getScopeTree: function (id) {
|
||
|
return _scopeTreeCache[id];
|
||
|
},
|
||
|
|
||
11 years ago
|
enableInspector: function (argument) {
|
||
|
chromeExtension.eval(function (window, args) {
|
||
|
return window.__ngDebug.enable();
|
||
|
});
|
||
12 years ago
|
}
|
||
|
};
|
||
|
});
|