     class SyncView
         constructor: (syncMaster) ->
             @syncMaster = syncMaster
-            @data = '\n'
-
-        update: (data) ->
-            @data = data
-            @syncMaster.update(this, data)
+            @data = syncMaster.data
+
+            amplify.subscribe 'data-updated', (source, data) =>
+                @onUpdate(source, data)
+
+        onDataUpdated: (source, data) ->
+            if this isnt source and @data isnt data
+                @data = data
+                return true
+            else
+                return false
 
     class DocView extends SyncView
         constructor: (syncMaster, doc) ->
             super(syncMaster)
             @doc = doc
-            @doc.setValue(@syncMaster.data)
+            @doc.setValue(@data)
 
             @doc.on 'change', () =>
-                @syncMaster.update(@, @doc.getValue())
-
-            amplify.subscribe 'data-updated', (source, data) =>
-                if source isnt @
-                    if data isnt @doc.getValue()
-                        @doc.setValue(data)
+                @data = @doc.getValue()
+                @syncMaster.update(this, @data)
+
+        onDataUpdated: (source, data) =>
+            if super(source, data)
+                @doc.setValue(@data)
 
 
     class OutlineView extends SyncView

    class SyncMaster
        constructor: () ->
            @data = '\n'
        update: (source, data) ->
            @data = data
            amplify.publish 'data-updated', source, data

    syncMaster = new SyncMaster()

            @outline = outline

            outline.onDidEndChanges () =>
                @syncMaster.update(this, @outline.serialize())

        onDataUpdated: (source, data) =>
            if super(source, data)
                @outline.reloadSerialization(@data)

    panel = new DockPanel()
    panel.id = 'main'
