Skip to content

Instantly share code, notes, and snippets.

@rummelonp
Last active August 29, 2015 14:05
Show Gist options
  • Save rummelonp/9d3cda9d410a3847e634 to your computer and use it in GitHub Desktop.
Save rummelonp/9d3cda9d410a3847e634 to your computer and use it in GitHub Desktop.
雑なディスパッチャ
<!DOCTYPE html>
<html>
<head>
<%= javascript_include_tag "application" %>
</head>
<body data-route="<%= controller_name %>#<%= action_name %>">
</body>
</html>
#= require jquery
#= require jquery.dispatcher
$.dispatcher.add 'users#index', ->
alert 'users#index'
$document.ready ->
$.dispatcher.fire($('[data-route]').data('route'))
$.dispatcher = (->
list: []
add: (route, callback) ->
$.dispatcher.list.push([route, callback])
fire: (currentRoute) ->
for [route, callback] in $.dispatcher.list
if route == currentRoute
callback()
)()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment