   state:
     selectedAppName: -> Session.get 'selectedAppName'
     appSearchValue: -> Session.get 'appSearchValue'
+    globalErrorMessage: -> Session.get 'globalErrorMessage'
+    globalInfoMessage: -> Session.get 'globalInfoMessage'
 
 , Wrapper
 

{ browserHistory }  = require 'react-router'
{ EventEmitter }    = require 'fbemitter'
routes              = require '../imports/startup/routes.cjsx'

Wrapper = React.createClass
  displayName: 'MeteorDataWrapper'

  onEvent 'app name selected', storeDataInSession('selectedAppName'), (app) -> browserHistory.push("/apps/#{app.name}/#{app.version}")
  onEvent 'app search entered', storeDataInSession('appSearchValue')
  onEvent 'stop instance', (instanceName) -> ddp.call 'stopInstance', instanceName
  onEvent 'remove app', (app) -> ddp.call 'deleteApp', app.name, app.version, (err) ->
    eventEmitter.emit 'show error message', err if err
    eventEmitter.emit 'app removed', app unless err
  onEvent 'app removed', (app) ->
    eventEmitter.emit 'show info message', "App #{app.name}:#{app.version} is deleted."
    browserHistory.push '/apps'
  onEvent 'start app', (app) -> console.log 'start app', app

  onEvent 'show error message', (message) -> Session.set 'globalErrorMessage', ErrorMapper message
  onEvent 'clear error message', -> Session.set 'globalErrorMessage', null
  onEvent 'show info message', (message) -> Session.set 'globalInfoMessage', message
  onEvent 'clear info message', -> Session.set 'globalInfoMessage', null

  emit: (evt, data) -> eventEmitter.emit evt, data
  collections:
