From 467f320d98fd9279d234b9aea1b8fbf19f710900 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Thu, 7 Feb 2013 00:21:02 +0100 Subject: moved from cakefile to grunt --- coffee/lib/services/publisher.coffee | 54 ++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 coffee/lib/services/publisher.coffee (limited to 'coffee/lib/services/publisher.coffee') 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 +# +# 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 -- cgit v1.2.3