     @cowriterView = new CowriterView(state.cowriterViewState)
     @modalPanel = atom.workspace.addModalPanel(item: @cowriterView.getElement(), visible: false)
 
-    @textBuffer = ''
-    Acticles = AV.Object.extend 'Acticles'
-    @acticle = new Acticles()
+    # Current document's title
+    @title= 'demo'
+
+    # Save new diff
+    @Acticles = AV.Object.extend 'Acticles'
+
+    # Query for new diff
+    @query = new AV.Query 'Acticles'
+
+    # Base time for syncing
+    @syncTime = new Date()
+
     @editor = atom.workspace.getActiveTextEditor()
+    @oldText = ''
+    @newText = ''
 
     # Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
     @subscriptions = new CompositeDisposable
 
     # Register command that toggles this view
     @subscriptions.add atom.commands.add 'atom-workspace', 'cowriter:toggle': => @toggle()
+
+    # Server: Sends changes when change stops
     @subscriptions.add @editor.onDidStopChanging => @stop()
+
+    # May suffered from unsafe-eval of CSP
+    # Cilent: Refresh view every 3 seconds
+    @interval = setInterval ( => @getDiff() ), 3000
 
   deactivate: ->
     @modalPanel.destroy()

    cowriterViewState: @cowriterView.serialize()

  stop: ->
    textBuffer = @editor.getText()
    @save(textBuffer)
    @cowriterView.setContent(@textBuffer)

  save: (text) ->
    @acticle.save { 'demo': text }, { success: (object) -> alert 'LeanCloud works!' }

  toggle: ->
    console.log 'Cowriter was toggled!'
    if @modalPanel.isVisible()
      @modalPanel.hide()
    else
      @modalPanel.show()

CowriterView = require './cowriter-view'
Diff = require 'diff'
AV = require 'avoscloud-sdk'
{CompositeDisposable} = require 'atom'
AV.initialize 'APPID','APPKEY'
