diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-02-07 00:39:13 +0100 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-02-07 00:39:13 +0100 |
commit | 9325aafb84476c779b96eb9260c69a0144e55bc8 (patch) | |
tree | 01a822aa6afd4dc78b8e04dd6d514836bc6367d3 /coffee/lib/services | |
parent | 2c7f779af5d902d1e323c0cec8e35a184e519de0 (diff) |
spaces to tabs
Diffstat (limited to 'coffee/lib/services')
-rw-r--r-- | coffee/lib/services/publisher.coffee | 74 | ||||
-rw-r--r-- | coffee/lib/services/request.coffee | 86 | ||||
-rw-r--r-- | coffee/lib/services/router.coffee | 2 |
3 files changed, 81 insertions, 81 deletions
diff --git a/coffee/lib/services/publisher.coffee b/coffee/lib/services/publisher.coffee index 39d4ddd43..4d8788726 100644 --- a/coffee/lib/services/publisher.coffee +++ b/coffee/lib/services/publisher.coffee @@ -15,40 +15,40 @@ angular.module('OC').factory '_Publisher', -> - class Publisher - - constructor: -> - @subscriptions = {} - - - # Use this to subscribe to a certain hashkey in the returned json data - # dictionary. - # If you send JSON from the server, you'll receive something like this - # - # { - # data: { - # modelName: { - # create: [{id: 1, name: 'john'}, {id: 2, name: 'ron'}], - # update: [], - # delete: [] - # } - # } - # } - # - # To get the array ['one', 'two'] passed to your model, just subscribe - # to the key: - # Publisher.subscribeModelTo('modelName', myModelInstance) - # - subscribeModelTo: (model, name) -> - @subscriptions[name] or= [] - @subscriptions[name].push(model) - - - # This will publish data from the server to all registered subscribers - # The parameter 'name' is the name under which subscribers have registered - publishDataTo: (data, name) -> - for subscriber in @subscriptions[name] || [] - subscriber.handle(data) - - - return Publisher
\ No newline at end of file + class Publisher + + constructor: -> + @subscriptions = {} + + + # Use this to subscribe to a certain hashkey in the returned json data + # dictionary. + # If you send JSON from the server, you'll receive something like this + # + # { + # data: { + # modelName: { + # create: [{id: 1, name: 'john'}, {id: 2, name: 'ron'}], + # update: [], + # delete: [] + # } + # } + # } + # + # To get the array ['one', 'two'] passed to your model, just subscribe + # to the key: + # Publisher.subscribeModelTo('modelName', myModelInstance) + # + subscribeModelTo: (model, name) -> + @subscriptions[name] or= [] + @subscriptions[name].push(model) + + + # This will publish data from the server to all registered subscribers + # The parameter 'name' is the name under which subscribers have registered + publishDataTo: (data, name) -> + for subscriber in @subscriptions[name] || [] + subscriber.handle(data) + + + return Publisher
\ No newline at end of file diff --git a/coffee/lib/services/request.coffee b/coffee/lib/services/request.coffee index 16f6db5cc..15b4b9013 100644 --- a/coffee/lib/services/request.coffee +++ b/coffee/lib/services/request.coffee @@ -11,64 +11,64 @@ angular.module('OC').factory '_Request', -> - class Request + class Request - constructor: (@_$http, @_$rootScope, @_publisher, @_token, @_router) -> - @_initialized = false - @_shelvedRequests = [] + constructor: (@_$http, @_$rootScope, @_publisher, @_token, @_router) -> + @_initialized = false + @_shelvedRequests = [] - @_$rootScope.$on 'routesLoaded', => - @_executeShelvedRequests() - @_initialized = true - @_shelvedRequests = [] + @_$rootScope.$on 'routesLoaded', => + @_executeShelvedRequests() + @_initialized = true + @_shelvedRequests = [] - request: (route, routeParams={}, data={}, onSuccess=null, onFailure=null, config={}) -> - # if routes are not ready yet, save the request - if not @_initialized - @_shelveRequest(route, routeParams, data, method, config) - return + request: (route, routeParams={}, data={}, onSuccess=null, onFailure=null, config={}) -> + # if routes are not ready yet, save the request + if not @_initialized + @_shelveRequest(route, routeParams, data, method, config) + return - url = @_router.generate(route, routeParams) + url = @_router.generate(route, routeParams) - defaultConfig = - method: 'GET' - url: url - data: data + defaultConfig = + method: 'GET' + url: url + data: data - # overwrite default values from passed in config - for key, value of config - defaultConfig[key] = value + # overwrite default values from passed in config + for key, value of config + defaultConfig[key] = value - @_$http(config) - .success (data, status, headers, config) => - if onSuccess - onSuccess(data, status, headers, config) + @_$http(config) + .success (data, status, headers, config) => + if onSuccess + onSuccess(data, status, headers, config) - # publish data to models - for name, value of data.data - @publisher.publishDataTo(name, value) + # publish data to models + for name, value of data.data + @publisher.publishDataTo(name, value) - .error (data, status, headers, config) -> - if onFailure - onFailure(data, status, headers, config) + .error (data, status, headers, config) -> + if onFailure + onFailure(data, status, headers, config) - _shelveRequest: (route, routeParams, data, method, config) -> - request = - route: route - routeParams: routeParams - data: data - config: config - method: method + _shelveRequest: (route, routeParams, data, method, config) -> + request = + route: route + routeParams: routeParams + data: data + config: config + method: method - @_shelvedRequests.push(request) + @_shelvedRequests.push(request) - _executeShelvedRequests: -> - for req in @_shelvedRequests - @post(req.route, req.routeParams, req.data, req.method, req.config) + _executeShelvedRequests: -> + for req in @_shelvedRequests + @post(req.route, req.routeParams, req.data, req.method, req.config) - return Request + return Request diff --git a/coffee/lib/services/router.coffee b/coffee/lib/services/router.coffee index ace9596cf..71ed24332 100644 --- a/coffee/lib/services/router.coffee +++ b/coffee/lib/services/router.coffee @@ -13,4 +13,4 @@ # Inject router into angular to make testing easier ### angular.module('OC').factory 'Router', -> - return OC.Router
\ No newline at end of file + return OC.Router
\ No newline at end of file |