     mean:  '-'
 
   componentWillMount: ->
-    app_root.events.requests.subscribe(@setState.bind(@))
+    @subscription = app.events.requests.subscribe(@setState.bind(@))
+  componentWillUnmount: ->
+    @subscription.dispose()
+
+  componentDidUpdate: (prevProps, prevState) ->
+    null
+  componentWillUpdate: (nextProps, nextState) ->
+    null
 
   render: ->
-      (R.div {}, [
+      (R.div {style: {float: "left"}}, [
         (R.h2 {}, "Vert.x Request Metrics"),
         '1m: ' + @state['1m'],
         R.br {},

Rx = require('rx')
#Rxdom = require('rx-dom') # may not need

window.app_root = app_root =
  ns:
    Rx: Rx
    #Rxdom: Rxdom
    React: React
  config:
    pkg: pkg
    rest_api:
      sources: "/api/metrics/sources"
      requests: "/api/metrics/meters/requests"
      responseTimes: "/api/metrics/histograms/responseTimes"
    ws_api:
     requests: "/streams/meters/requests"
     responseTimes: "/streams/metrics/histograms/responseTimes"
  events:
    ui: new Rx.Subject()
    requests: new Rx.Subject()
    responseTimes: new Rx.Subject()
  subscriptions:
    # keep track for disposing them later: off/on
    requests_ws: null
    responseTimes_ws: null
  ui_root: null

wsurl = (path) ->
  host = document.location.hostname

  # or just use
  # https://github.com/Reactive-Extensions/RxJS-DOM/tree/master/doc#rxdomfromwebsocketurl-protocol-observeroronnext
  # but I'm including this as an example of how to create a bidirectional subject
  ws = new WebSocket(if url[0] == "/" then wsurl(url) else url)
  observable = Observable.create (obs) ->
    ws.onmessage = obs.onNext.bind(obs)
    ws.onerror = obs.onError.bind(obs)
    ws.onclose = obs.onCompleted.bind(obs)
    # Return way to unsubscribe
    -> ws.close()
  observer = Observer.create (data) ->
    if ws.readyState == WebSocket.OPEN
      ws.send(data)
  Subject.create(observer, observable)

RequestsWidget = React.createClass
  getInitialState: ->
