Last active
August 29, 2015 14:05
-
-
Save itzaks/b5b3a422751ace1a95d3 to your computer and use it in GitHub Desktop.
Add mediator style pub/sub to space-pen views using flesch/psst.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| psst = require 'psst' | |
| module.exports = require 'space-pen' | |
| module.exports.EventView = | |
| class EventView extends module.exports.View | |
| subscriptions: null | |
| initialize: -> | |
| return unless @subscriptions | |
| for subscription, method of @subscriptions | |
| method = @[method] if typeof method is 'string' | |
| psst.on subscription, method | |
| @beforeRemove = -> @unsubscribe() | |
| emit: -> | |
| psst.emit arguments... | |
| unsubscribe: -> | |
| for subscripition, method of subscriptions | |
| psst.off subscription |
Author
Author
remember to call super on initialize and beforeRemove if used.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use: