 FileDialog = require("./file-dialog.coffee")
 
 fileLoadedBus = new Bacon.Bus()
-renameBus = new Bacon.Bus()
-
 initialApplication = if localStorage.application
     JSON.parse(localStorage.application)
   else

storage = Storage(
  applicationP,
  menubar.itemClickE("file-save")
  renameBus
)
storage.saveResultE.log() # TODO: replace with a feedback
storage.renameResultE.log() # TODO: replace with a feedback

promptNewName = (application) ->
  newName = prompt("Enter new name", application.name + " fork")
  application = _.clone(application)
  application.name = newName
  application

forkE = menubar.itemClickE("file-fork")
  .map(applicationP)
  .flatMap (application) -> promptNewName(application)

fileLoadedBus.plug(forkE)


$ = window.$ = require("jquery")
Bacon = window.Bacon = require("baconjs")
Bacon.Observable :: flatScan = (seed, f) ->
  acc = seed
  @flatMapLatest((newValue) ->
    acc = f(acc, newValue)
  )
  .toProperty(seed)
_ = require("lodash")
$.fn.asEventStream = Bacon.$.asEventStream
examples = require("./examples.coffee")
