How to restore the editscript?
FreekPaans opened this issue · 7 comments
Hi, I'm trying to persist the edit script so I can apply it at a later time. How would I go about doing that?
In essence what I want to do:
(patch a (get-edits (diff a b))
Thanks.
The following solves my issue btw:
(defn editscript-patch
[init-val edits]
(reduce editscript.patch/patch*
init-val
edits))
But depends on internals so I hope there's a better way for doing this :)
(patch a (diff a b))
should do.
You keep the result of (diff a b)
, say (def d (diff a b))
, then (patch a d)
.
Of course, if you want to save the raw diff vector of (get-edits d)
, then restore from that, I can add a function to initialize an editscript instance from a raw diff vector.
Of course, if you want to save the raw diff vector of
(get-edits d)
, then restore from that, I can add a function to initialize an editscript instance from a raw diff vector.
That's exactly what I need. I need to store the diff offline, so I can't keep the EditScript
instance.
@FreekPaans a function edits->script
is added. Please let me know if it does what you want. Thanks.
Hi, I finally got around testing this. Unfortunately, I'm running into some issues with this release]. When doing a trivial patch it throws.
(def edit-source {})
(def edit-dest {:x :hello-world})
"this throws"
(let [edits (editscript.edit/get-edits
(editscript/diff edit-source edit-dest))]
(editscript/patch edit-source (editscript.edit/edits->script edits))
)
Throws with:
Execution error (AssertionError) at editscript.edit/edits->script (edit.cljc:198).
Assert failed: Not a vector of valid edits
(valid-edits? edits)
Also, I'm seeing some weird behavior with regard to equality:
(assert (= (editscript.edit/get-edits
(editscript/diff {} {}))
(editscript.edit/get-edits
(editscript/diff {} {})))
"this succeeds")
(def some-edits (editscript.edit/get-edits
(editscript/diff {} {})))
(assert (= some-edits (editscript.edit/get-edits
(editscript/diff {} {})))
"this fails")
I created a full repro repo here: https://github.com/FreekPaans/editscript-repro/blob/master/src/editscript_test/core.clj. Also tested on Clojure 1.10.0, Java version was 11.