 toArray = (obj, cond=null) ->
   if _.isArray(cond ? obj) then obj else [obj]
 
+
+# Main
+# -------------------------
+getVimState = (args...) ->
+  [editor, file, callback] = []
+  switch args.length
+    when 1 then [callback] = args
+    when 2 then [file, callback] = args
+
+  waitsForPromise ->
+    atom.packages.activatePackage(packageName)
+
+  waitsForPromise ->
+    file = atom.project.resolvePath(file) if file
+    atom.workspace.open(file).then (e) ->
+      editor = e
+
+  runs ->
+    pack = atom.packages.getActivePackage(packageName)
+    main = pack.mainModule
+    vimState = main.getEditorState(editor)
+    {editorElement} = vimState
+    editorElement.addEventListener 'keydown', (e) ->
+      atom.keymaps.handleKeyboardEvent(e)
+
+    callback(vimState, new VimEditor(vimState))
+
 class VimEditor
   constructor: (@vimState) ->
     {@editor, @editorElement} = @vimState

  constructor: (@message) ->
    @name = 'SpecError'

getVimState = (args...) ->
  [editor, file, callback] = []
  switch args.length
    when 1 then [callback] = args
    when 2 then [file, callback] = args

  waitsForPromise ->
    atom.packages.activatePackage(packageName)

  waitsForPromise ->
    file = atom.project.resolvePath(file) if file
    atom.workspace.open(file).then (e) ->
      editor = e

  runs ->
    pack = atom.packages.getActivePackage(packageName)
    main = pack.mainModule
    vimState = main.getEditorState(editor)
    {editorElement} = vimState
    editorElement.addEventListener 'keydown', (e) ->
      atom.keymaps.handleKeyboardEvent(e)

    callback(vimState, new VimEditor(vimState))

getView = (model) ->
  atom.views.getView(model)

mockPlatform = (editorElement, platform) ->
  wrapper = document.createElement('div')

    if mocked
      unmockPlatform(element)

module.exports = {getVimState, getView, dispatch}
