landers.angular
Version:
landers.angular
49 lines (48 loc) • 1.83 kB
JavaScript
;angular.module('Landers.angular')
.factory('Runtime', ['Flat', function (Flat) {
var cache = {};
function runtime (scope, inhert){
var prekey = '$runtime';
var watchers = {};
if ( !cache[scope.$id] ) {
if (inhert) {
scope.$runtime = scope.$runtime || {};
} else {
scope.$runtime = {};
}
cache[scope.$id] = true;
}
this.__proto__ = Flat.make(scope[prekey], scope);
this.watch = function(keys, callback, is_object){
if (angular.isArray(keys)) {
var _watchers = [];
keys.map(function(key){
key = prekey + '.' + key;
watchers[key] = scope.$watch(key, callback, is_object);
_watchers[key] = watchers[key];
});
return _watchers;
} else {
key = prekey + '.' + keys;
watchers[key] = scope.$watch(key, callback, is_object);
return watchers[key];
}
};
this.destroyWatchers = function(keys){
var that = this;
if (!angular.isArray(keys)) keys = [keys];
keys.map(function(key){
key = prekey + '.' + key;
console.log(key, typeof watchers[key], watchers[key]);
if (angular.isFunction(watchers[key])) {
watchers[key]();
}
});
}
}
return {
make:function(scope, inhert){
return new runtime(scope, inhert);
}
};
}]);