diff options
| author | Misko Hevery | 2010-01-24 17:10:58 -0800 |
|---|---|---|
| committer | Misko Hevery | 2010-01-24 17:10:58 -0800 |
| commit | efad9ec5be8da442af5fb3dffc08510f7a71e10f (patch) | |
| tree | b6ffdda829b47b9058f0b2ccbd6ef3465ccfe0bc /src | |
| parent | c7719c24121b500f0bc2ac7c652d8ec0de418a37 (diff) | |
| download | angular.js-efad9ec5be8da442af5fb3dffc08510f7a71e10f.tar.bz2 | |
changes to make it closure compiler compatible
Diffstat (limited to 'src')
| -rw-r--r-- | src/Angular.js | 20 | ||||
| -rw-r--r-- | src/Binder.js | 15 | ||||
| -rw-r--r-- | src/ControlBar.js | 2 | ||||
| -rw-r--r-- | src/DataStore.js | 104 | ||||
| -rw-r--r-- | src/Model.js | 12 | ||||
| -rw-r--r-- | src/Parser.js | 3 | ||||
| -rw-r--r-- | src/Scope.js | 12 | ||||
| -rw-r--r-- | src/Server.js | 4 |
8 files changed, 87 insertions, 85 deletions
diff --git a/src/Angular.js b/src/Angular.js index d3eef9d9..cadef4d0 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -20,11 +20,9 @@ if (typeof Node == 'undefined') { function noop() {} if (!window['console']) window['console']={'log':noop, 'error':noop}; -var consoleNode, +var consoleNode, jQuery, msie, foreach = _.each, extend = _.extend, - jQuery = window['jQuery'], - msie = jQuery['browser']['msie'], angular = window['angular'] || (window['angular'] = {}), angularValidator = angular['validator'] || (angular['validator'] = {}), angularFilter = angular['filter'] || (angular['filter'] = {}), @@ -212,7 +210,6 @@ UrlWatcher.prototype = { self.setTimeout(pull, self.delay); }; pull(); - return this; }, set: function(url) { @@ -271,19 +268,20 @@ function exposeMethods(obj, methods){ function wireAngular(element, config) { var widgetFactory = new WidgetFactory(config['server'], config['database']); - var binder = new Binder(element[0], widgetFactory, config['location'], config); + var binder = new Binder(element[0], widgetFactory, datastore, config['location'], config); var controlBar = new ControlBar(element.find('body'), config.server); var onUpdate = function(){binder.updateView();}; - var server = config.database=="$MEMORY" ? + var server = config['database'] =="$MEMORY" ? new FrameServer(this.window) : - new Server(config.server, jQuery.getScript); + new Server(config['server'], jQuery['getScript']); server = new VisualServer(server, new Status(jQuery(element.body)), onUpdate); var users = new Users(server, controlBar); - var databasePath = '/data/' + config.database; + var databasePath = '/data/' + config['database']; var post = function(request, callback){ server.request("POST", databasePath, request, callback); }; var datastore = new DataStore(post, users, binder.anchor); + binder.datastore = datastore; binder.updateListeners.push(function(){datastore.flush();}); var scope = new Scope({ '$anchor' : binder.anchor, @@ -343,10 +341,14 @@ function wireAngular(element, config) { } angular['startUrlWatcher'] = function(){ - return new UrlWatcher(window['location']).watch(); + var watcher = new UrlWatcher(window['location']); + watcher.watch(); + return exposeMethods(watcher, {'listen':watcher.listen, 'set':watcher.set, 'get':watcher.get}); }; angular['compile'] = function(element, config) { + jQuery = window['jQuery']; + msie = jQuery['browser']['msie']; config = _({ 'server': "", 'location': {'get':noop, 'set':noop, 'listen':noop} diff --git a/src/Binder.js b/src/Binder.js index 48a4f611..e516ec32 100644 --- a/src/Binder.js +++ b/src/Binder.js @@ -1,6 +1,7 @@ -function Binder(doc, widgetFactory, location, config) { +function Binder(doc, widgetFactory, datastore, location, config) { this.doc = doc; this.location = location; + this.datastore = datastore; this.anchor = {}; this.widgetFactory = widgetFactory; this.config = config || {}; @@ -49,7 +50,7 @@ Binder.prototype = { }, parseAnchor: function() { - var self = this, url = this.location.get() || ""; + var self = this, url = this.location['get']() || ""; var anchorIndex = url.indexOf('#'); if (anchorIndex < 0) return; @@ -70,7 +71,7 @@ Binder.prototype = { }, updateAnchor: function() { - var url = this.location.get() || ""; + var url = this.location['get']() || ""; var anchorIndex = url.indexOf('#'); if (anchorIndex > -1) url = url.substring(0, anchorIndex); @@ -87,7 +88,7 @@ Binder.prototype = { sep = '&'; } } - this.location.set(url); + this.location['set'](url); return url; }, @@ -123,12 +124,14 @@ Binder.prototype = { }, entity: function (scope) { + var self = this; this.docFindWithSelf("[ng-entity]").attr("ng-watch", function() { try { var jNode = jQuery(this); - var decl = scope.entity(jNode.attr("ng-entity")); + var decl = scope.entity(jNode.attr("ng-entity"), self.datastore); return decl + (jNode.attr('ng-watch') || ""); } catch (e) { + log(e); alert(e); } }); @@ -136,7 +139,7 @@ Binder.prototype = { compile: function() { var jNode = jQuery(this.doc); - if (this.config.autoSubmit) { + if (this.config['autoSubmit']) { var submits = this.docFindWithSelf(":submit").not("[ng-action]"); submits.attr("ng-action", "$save()"); submits.not(":disabled").not("ng-bind-attr").attr("ng-bind-attr", '{disabled:"{{$invalidWidgets}}"}'); diff --git a/src/ControlBar.js b/src/ControlBar.js index 53c87199..a50b8854 100644 --- a/src/ControlBar.js +++ b/src/ControlBar.js @@ -55,7 +55,7 @@ ControlBar.prototype = { resizable: false, modal:true, title: 'Authentication: <a href="http://www.getangular.com"><tt><angular/></tt></a>' }); - callbacks["_iframe_notify_" + id] = function() { + angularCallbacks["_iframe_notify_" + id] = function() { loginView.dialog("destroy"); loginView.remove(); foreach(self.callbacks, function(callback){ diff --git a/src/DataStore.js b/src/DataStore.js index 7952096f..789b8f71 100644 --- a/src/DataStore.js +++ b/src/DataStore.js @@ -1,7 +1,8 @@ function DataStore(post, users, anchor) { this.post = post; this.users = users; - this._cache = {$collections:[]}; + this._cache_collections = []; + this._cache = {'$collections':this._cache_collections}; this.anchor = anchor; this.bulkRequest = []; }; @@ -15,10 +16,10 @@ DataStore.NullEntity = extend(function(){}, { DataStore.prototype = { cache: function(document) { - if (! document instanceof Model) { + if (! document.datastore === this) { throw "Parameter must be an instance of Entity! " + toJson(document); } - var key = document.$entity + '/' + document.$id; + var key = document['$entity'] + '/' + document['$id']; var cachedDocument = this._cache[key]; if (cachedDocument) { Model.copyDirectFields(document, cachedDocument); @@ -32,10 +33,10 @@ DataStore.prototype = { load: function(instance, id, callback, failure) { if (id && id !== '*') { var self = this; - this._jsonRequest(["GET", instance.$entity + "/" + id], function(response) { - instance.$loadFrom(response); - instance.$migrate(); - var clone = instance.$$entity(instance); + this._jsonRequest(["GET", instance['$entity'] + "/" + id], function(response) { + instance['$loadFrom'](response); + instance['$migrate'](); + var clone = instance['$$entity'](instance); self.cache(clone); (callback||noop)(instance); }, failure); @@ -61,8 +62,8 @@ DataStore.prototype = { loadOrCreate: function(instance, id, callback) { var self=this; return this.load(instance, id, callback, function(response){ - if (response.$status_code == 404) { - instance.$id = id; + if (response['$status_code'] == 404) { + instance['$id'] = id; (callback||noop)(instance); } else { throw response; @@ -73,15 +74,15 @@ DataStore.prototype = { loadAll: function(entity, callback) { var self = this; var list = []; - list.$$accept = function(doc){ - return doc.$entity == entity.title; + list['$$accept'] = function(doc){ + return doc['$entity'] == entity['title']; }; - this._cache.$collections.push(list); - this._jsonRequest(["GET", entity.title], function(response) { + this._cache_collections.push(list); + this._jsonRequest(["GET", entity['title']], function(response) { var rows = response; for ( var i = 0; i < rows.length; i++) { var document = entity(); - document.$loadFrom(rows[i]); + document['$loadFrom'](rows[i]); list.push(self.cache(document)); } (callback||noop)(list); @@ -92,17 +93,17 @@ DataStore.prototype = { save: function(document, callback) { var self = this; var data = {}; - document.$saveTo(data); + document['$saveTo'](data); this._jsonRequest(["POST", "", data], function(response) { - document.$loadFrom(response); + document['$loadFrom'](response); var cachedDoc = self.cache(document); - _.each(self._cache.$collections, function(collection){ - if (collection.$$accept(document)) { - angular['Array']['includeIf'](collection, cachedDoc, true); + _.each(self._cache_collections, function(collection){ + if (collection['$$accept'](document)) { + angularArray['includeIf'](collection, cachedDoc, true); } }); - if (document.$$anchor) { - self.anchor[document.$$anchor] = document.$id; + if (document['$$anchor']) { + self.anchor[document['$$anchor']] = document['$id']; } if (callback) callback(document); @@ -112,13 +113,13 @@ DataStore.prototype = { remove: function(document, callback) { var self = this; var data = {}; - document.$saveTo(data); + document['$saveTo'](data); this._jsonRequest(["DELETE", "", data], function(response) { - delete self._cache[document.$entity + '/' + document.$id]; - _.each(self._cache.$collections, function(collection){ + delete self._cache[document['$entity'] + '/' + document['$id']]; + _.each(self._cache_collections, function(collection){ for ( var i = 0; i < collection.length; i++) { var item = collection[i]; - if (item.$id == document.$id) { + if (item['$id'] == document['$id']) { collection.splice(i, 1); } } @@ -128,8 +129,8 @@ DataStore.prototype = { }, _jsonRequest: function(request, callback, failure) { - request.$$callback = callback; - request.$$failure = failure||function(response){ + request['$$callback'] = callback; + request['$$failure'] = failure||function(response){ throw response; }; this.bulkRequest.push(request); @@ -143,25 +144,25 @@ DataStore.prototype = { log('REQUEST:', bulkRequest); function callback(code, bulkResponse){ log('RESPONSE[' + code + ']: ', bulkResponse); - if(bulkResponse.$status_code == 401) { - self.users.login(function(){ + if(bulkResponse['$status_code'] == 401) { + self.users['login'](function(){ self.post(bulkRequest, callback); }); - } else if(bulkResponse.$status_code) { + } else if(bulkResponse['$status_code']) { alert(toJson(bulkResponse)); } else { for ( var i = 0; i < bulkResponse.length; i++) { var response = bulkResponse[i]; var request = bulkRequest[i]; - var responseCode = response.$status_code; + var responseCode = response['$status_code']; if(responseCode) { if(responseCode == 403) { - self.users.notAuthorized(); + self.users['notAuthorized'](); } else { - request.$$failure(response); + request['$$failure'](response); } } else { - request.$$callback(response); + request['$$callback'](response); } } } @@ -178,9 +179,9 @@ DataStore.prototype = { } for(var key in scope) { var item = scope[key]; - if (item && item.$save == Model.prototype.$save) { + if (item && item['$save'] == Model.prototype['$save']) { saveCounter++; - item.$save(onSaveDone); + item['$save'](onSaveDone); } } onSaveDone(); @@ -189,19 +190,18 @@ DataStore.prototype = { query: function(type, query, arg, callback){ var self = this; var queryList = []; - queryList.$$accept = function(doc){ + queryList['$$accept'] = function(doc){ return false; }; - this._cache.$collections.push(queryList); - var request = type.title + '/' + query + '=' + arg; + this._cache_collections.push(queryList); + var request = type['title'] + '/' + query + '=' + arg; this._jsonRequest(["GET", request], function(response){ var list = response; - for(var i = 0; i < list.length; i++) { - var document = new type().$loadFrom(list[i]); + foreach(list, function(item){ + var document = type()['$loadFrom'](item); queryList.push(self.cache(document)); - } - if (callback) - callback(queryList); + }); + (callback||noop)(queryList); }); return queryList; }, @@ -210,11 +210,11 @@ DataStore.prototype = { var entities = []; var self = this; this._jsonRequest(["GET", "$entities"], function(response) { - for (var entityName in response) { + foreach(response, function(value, entityName){ entities.push(self.entity(entityName)); - } + }); entities.sort(function(a,b){return a.title > b.title ? 1 : -1;}); - if (callback) callback(entities); + (callback||noop)(entities); }); return entities; }, @@ -223,9 +223,7 @@ DataStore.prototype = { var counts = {}; var self = this; self.post([["GET", "$users"]], function(code, response){ - foreach(response[0], function(value, key){ - counts[key] = value; - }); + extend(counts, response[0]); }); return counts; }, @@ -234,9 +232,7 @@ DataStore.prototype = { var ids = {}; var self = this; self.post([["GET", "$users/" + user]], function(code, response){ - foreach(response[0], function(value, key){ - ids[key] = value; - }); + extend(ids, response[0]); }); return ids; }, @@ -252,7 +248,7 @@ DataStore.prototype = { // entity.name does not work as name seems to be reserved for functions 'title': name, '$$factory': true, - 'datastore': this, + datastore: this, //private, obfuscate 'defaults': defaults || {}, 'load': function(id, callback){ return self.load(entity(), id, callback); diff --git a/src/Model.js b/src/Model.js index 4a3a1806..b09efd0e 100644 --- a/src/Model.js +++ b/src/Model.js @@ -3,9 +3,9 @@ function Model(entity, initial) { this['$$entity'] = entity; - this.$loadFrom(initial||{}); - this.$entity = entity['title']; - this.$migrate(); + this['$loadFrom'](initial||{}); + this['$entity'] = entity['title']; + this['$migrate'](); }; Model.copyDirectFields = function(src, dst) { @@ -25,9 +25,9 @@ Model.copyDirectFields = function(src, dst) { } }; -Model.prototype = { +extend(Model.prototype, { '$migrate': function() { - merge(this['$$entity'].defaults, this); + merge(this['$$entity']['defaults'], this); return this; }, @@ -62,4 +62,4 @@ Model.prototype = { Model.copyDirectFields(this, other); return this; } -};
\ No newline at end of file +});
\ No newline at end of file diff --git a/src/Parser.js b/src/Parser.js index 840f5541..d33ae3db 100644 --- a/src/Parser.js +++ b/src/Parser.js @@ -691,8 +691,7 @@ Parser.prototype = { defaults = this.primary()(null); } return function(self) { - var datastore = self.scope.get('$datastore'); - var Entity = datastore.entity(entity, defaults); + var Entity = self.datastore.entity(entity, defaults); self.scope.set(entity, Entity); if (instance) { var document = Entity(); diff --git a/src/Scope.js b/src/Scope.js index dcc50007..3b1f3930 100644 --- a/src/Scope.js +++ b/src/Scope.js @@ -6,9 +6,9 @@ function Scope(initialState, name) { var State = function(){}; State.prototype = initialState; this.state = new State(); - this.state.$parent = initialState; + this.state['$parent'] = initialState; if (name == "ROOT") { - this.state.$root = this.state; + this.state['$root'] = this.state; } }; @@ -37,7 +37,7 @@ Scope.getter = function(instance, path) { } } } - if (typeof instance === 'function' && !instance.$$factory) { + if (typeof instance === 'function' && !instance['$$factory']) { return bind(lastInstance, instance); } return instance; @@ -69,10 +69,12 @@ Scope.prototype = { }, get: function(path) { +// log('SCOPE.get', path, Scope.getter(this.state, path)); return Scope.getter(this.state, path); }, set: function(path, value) { +// log('SCOPE.set', path, value); var element = path.split('.'); var instance = this.state; for ( var i = 0; element.length > 1; i++) { @@ -145,9 +147,9 @@ Scope.prototype = { return expression(self)(self, value); }, - entity: function(entityDeclaration) { + entity: function(entityDeclaration, datastore) { var expression = new Parser(entityDeclaration).entityDeclaration(); - return expression({scope:this}); + return expression({scope:this, datastore:datastore}); }, markInvalid: function(widget) { diff --git a/src/Server.js b/src/Server.js index f351e84c..2932c09b 100644 --- a/src/Server.js +++ b/src/Server.js @@ -14,10 +14,10 @@ Server.prototype = { request: function(method, url, request, callback) { var requestId = this.uuid + (this.nextId++); angularCallbacks[requestId] = function(response) { - delete angular[requestId]; + delete angularCallbacks[requestId]; callback(200, response); }; - var payload = {u:url, m:method, p:request}; + var payload = {'u':url, 'm':method, 'p':request}; payload = this.base64url(toJson(payload)); var totalPockets = Math.ceil(payload.length / this.maxSize); var baseUrl = this.url + "/$/" + requestId + "/" + totalPockets + "/"; |
