 # coffee  -o node_modules -c diffsync.coffee && echo "require('diffsync').test1()" | coffee
 
 SIMULATE_LOSS = false
-SIMULATE_LOSS = true
+#SIMULATE_LOSS = true
 
 async = require('async')
 diff_match_patch = require('googlediff')  # TODO: this greatly increases the size of browserify output (unless we compress it) -- watch out.

            checksum : required    # checksum(doc0) -> something simple
            patch_in_place : undefined  # patch(d, doc0) modified doc0 in place to become doc1.

        @init(id : opts.id,  doc : opts.doc)

        @_copy           = opts.copy
        @_compute_edits  = opts.diff
        @_patch          = opts.patch
        @_patch_in_place = opts.patch_in_place
        @_checksum       = opts.checksum

    _apply_edits: (edits, doc, cb) =>
        cb(false, @_patch(edits, doc))

    _apply_edits_to_live: (edits, cb) =>
        if @_patch_in_place?
            @_patch_in_place(edits, @live)
            cb()
        else
            @_apply_edits  edits, @live, (err, result) =>

                        @shadow = result
                        @shadow_version  += 1
                        @_apply_edits_to_live(edits.edits, cb)

            else
                if edits.shadow_version < @shadow_version
                    # Packet duplication or loss: ignore -- it will sort itself out later.
