Last active
August 29, 2015 14:18
-
-
Save psychobunny/e35a5eb82aa11e37974d to your computer and use it in GitHub Desktop.
FlightJS inspired components system for NodeBB
This file contains 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
define('notifications', ['events', 'components'], function(events, components) { | |
var notifications = {}; | |
notifications.init = function() { | |
events.initialize('notifications', function() { | |
this.register('icon.unread', markUnread); | |
this.register('icon.read', markRead); | |
}); | |
}; | |
notifications.update = function(count) { | |
if (count > 0) { | |
events.fire('notifications:icon.unread'); | |
} else { | |
events.fire('notifications:icon.read'); | |
} | |
} | |
// DOM manipulation should only happen here and nowhere else to "decouple" DOM from logic | |
function markUnread() { | |
components.get('notifIcon') | |
.removeClass('fa-bell-o').addClass('fa-bell'); | |
} | |
function markRead() { | |
components.get('notifIcon') | |
.removeClass('fa-bell').addClass('fa-bell-o'); | |
} | |
return notifications; | |
}); |
This file contains 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
define('my/plugin/or/theme', ['events', 'components'], function(events, components) { | |
var plugin = {}; | |
plugin.init = function() { | |
events.extend('notifications', function() { | |
this.after('icon.read', afterMarkRead); | |
this.before('icon.read', beforeMarkRead); | |
this.override('icon.unread', myBetterVersion); | |
}); | |
}; | |
function afterMarkRead() { | |
alert('notif was marked read!'); | |
} | |
function beforeMarkRead() { | |
alert('notif is about to be marked read!'); | |
} | |
function myBetterVersion() { | |
components.get('notifIcon') | |
.removeClass('fa-custom-font').addClass('fa-custom-font'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment