Skip to content

Commit

Permalink
Refactors kandan.js; Turns the huge function into bits
Browse files Browse the repository at this point in the history
Signed-off-by: Akash Manohar J <akash@akash.im>
  • Loading branch information
HashNuke committed Mar 28, 2012
1 parent 19cd88b commit b8fd30e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
36 changes: 18 additions & 18 deletions app/assets/javascripts/backbone/kandan.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ window.Kandan =

# TODO this is a helper method to register plugins
# in the order required until we come up with plugin management
register_plugins: ->
registerPlugins: ->
plugins = [
"UserList"
,"YouTubeEmbed"
Expand All @@ -34,7 +34,7 @@ window.Kandan =

initBroadcasterAndSubscribe: ()->
window.broadcaster = new Kandan.Broadcasters.FayeBroadcaster()
window.broadcaster.subscribe "/channels/*" ##{channel.get('id')}
window.broadcaster.subscribe "/channels/*"


initChatbox: ()->
Expand Down Expand Up @@ -65,25 +65,25 @@ window.Kandan =
$(document).bind 'changeData', (element, name, value)->
Kandan.Data.ActiveUsers.runCallbacks('change') if name=="active_users"

onFetchActiveUsers: (channels)=>
return (activeUsers)=>
if not Kandan.Helpers.ActiveUsers.collectionHasCurrentUser(activeUsers)
activeUsers.add([Kandan.Helpers.Users.currentUser()])

Kandan.Helpers.ActiveUsers.setFromCollection(activeUsers)
Kandan.registerPlugins()
Kandan.Plugins.initAll()
Kandan.initChatArea(channels)
Kandan.initChatbox()
Kandan.initTabs()
Kandan.Widgets.initAll()


init: ->
channels = new Kandan.Collections.Channels()
channels.fetch({success: (channelsCollection)=>
@initBroadcasterAndSubscribe()
@bindEventCallbacks()

active_users = new Kandan.Collections.ActiveUsers()
active_users.fetch({
success: (activeUsersCollection)=>

if not Kandan.Helpers.ActiveUsers.collectionHasCurrentUser(activeUsersCollection)
activeUsersCollection.add([Kandan.Helpers.Users.currentUser()])

Kandan.Helpers.ActiveUsers.setFromCollection(activeUsersCollection)
Kandan.register_plugins()
Kandan.Plugins.init_all()
@initChatArea(channelsCollection)
@initChatbox()
@initTabs()
Kandan.Widgets.init_all()
})
activeUsers = new Kandan.Collections.ActiveUsers()
activeUsers.fetch({success: @onFetchActiveUsers(channelsCollection)})
})
2 changes: 1 addition & 1 deletion app/assets/javascripts/backbone/plugins.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ class Kandan.Plugins
@all: ()->
@plugins

@init_all: ()->
@initAll: ()->
eval(plugin).init() for plugin in @all()
2 changes: 1 addition & 1 deletion app/assets/javascripts/backbone/widgets.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Kandan.Widgets
@all: ()->
@widgets

@init_all: ()->
@initAll: ()->
$.each @widgets, (widget_namespace, el_name)=>
@init(widget_namespace)

Expand Down

0 comments on commit b8fd30e

Please sign in to comment.