Permalink
Browse files

adding JS listener and emitting FS events

  • Loading branch information...
1 parent 244d093 commit 3356e78b4dc771f3223b40544336f1a93dc8fbe1 @tenderlove committed Jul 30, 2012
Showing with 21 additions and 3 deletions.
  1. +9 −0 app/assets/javascripts/application.js
  2. +12 −3 app/controllers/browser_controller.rb
@@ -13,3 +13,12 @@
//= require jquery
//= require jquery_ujs
//= require_tree .
+
+jQuery(document).ready(function() {
+ setTimeout(function() {
+ var source = new EventSource('/browser');
+ source.addEventListener('refresh', function(e) {
+ window.location.reload();
+ });
+ }, 1);
+});
@@ -10,10 +10,19 @@ def index
sse = Reloader::SSE.new(response.stream)
begin
- loop do
- sse.write({ :time => Time.now })
- sleep 1
+ directories = [
+ File.join(Rails.root, 'app', 'assets'),
+ File.join(Rails.root, 'app', 'views'),
+ ]
+ fsevent = FSEvent.new
+
+ # Watch the above directories
+ fsevent.watch(*directories) do |dirs|
+ # Send a message on the "refresh" channel on every update
+ sse.write({ :dirs => dirs }, :event => 'refresh')
end
+ fsevent.run
+
rescue IOError
# When the client disconnects, we'll get an IOError on write
ensure

0 comments on commit 3356e78

Please sign in to comment.