Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
framerjs pubsub
exports.pubsub = (->
listeners = {}
subscribe: (name, callback) ->
listeners[name] = [] unless listeners[name]
listeners[name].push callback
publish: (name) ->
args = Array::slice.call(arguments, 1)
if listeners[name]
i = 0
while i < listeners[name].length
listeners[name][i].apply null, args
i++
)()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.