diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-02-07 00:21:02 +0100 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-02-07 00:21:02 +0100 |
commit | 467f320d98fd9279d234b9aea1b8fbf19f710900 (patch) | |
tree | 347b6edf614236e3a239b9382f89720b3215eced /coffee/lib/services/publisher.coffee | |
parent | 8c1ee2f48b040b8d679c2fc1d38e8b9582b6b691 (diff) |
moved from cakefile to grunt
Diffstat (limited to 'coffee/lib/services/publisher.coffee')
-rw-r--r-- | coffee/lib/services/publisher.coffee | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/coffee/lib/services/publisher.coffee b/coffee/lib/services/publisher.coffee new file mode 100644 index 000000000..4d8788726 --- /dev/null +++ b/coffee/lib/services/publisher.coffee @@ -0,0 +1,54 @@ +### +# ownCloud +# +# @author Bernhard Posselt +# Copyright (c) 2012 - Bernhard Posselt <nukeawhale@gmail.com> +# +# This file is licensed under the Affero General Public License version 3 or later. +# See the COPYING-README file +# +### + +### +# Used for properly distributing received model data from the server +### +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 |