-
-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1660 from neotyk/fix/atomic-block-split
Atomic block split
- Loading branch information
Showing
11 changed files
with
631 additions
and
109 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
(ns athens.common-events.graph.ops | ||
"Building (including contextual resolution) Graph Ops like a boss." | ||
(:require | ||
[athens.common-db :as common-db] | ||
[athens.common-events.graph.atomic :as atomic] | ||
[athens.common-events.graph.composite :as composite] | ||
[athens.common.utils :as utils] | ||
[clojure.set :as set])) | ||
|
||
|
||
(defn build-block-save-op | ||
"Creates `:block/save` op, taking into account context. | ||
So it might be a composite or atomic event, depending if new page link is present and if pages exist." | ||
[db block-uid old-string new-string] | ||
(let [links-in-old (utils/find-page-links old-string) | ||
links-in-new (utils/find-page-links new-string) | ||
link-diff (set/difference links-in-new links-in-old) | ||
new-page-titles (remove #(seq (common-db/get-page-uid-by-title db %)) | ||
link-diff) | ||
atomic-pages (when-not (empty? new-page-titles) | ||
(into [] | ||
(for [title new-page-titles] | ||
(atomic/make-page-new-op title | ||
(utils/gen-block-uid) | ||
(utils/gen-block-uid))))) | ||
atomic-save (atomic/make-block-save-op block-uid old-string new-string) | ||
block-save-op (if (empty? atomic-pages) | ||
atomic-save | ||
(composite/make-consequence-op {:op/type :block/save} | ||
(conj atomic-pages | ||
atomic-save)))] | ||
block-save-op)) | ||
|
||
|
||
(defn build-block-split-op | ||
"Creates `:block/split` composite op, taking into account context." | ||
[db {:keys [parent-uid old-block-uid new-block-uid new-block-order | ||
old-string new-string index]}] | ||
(let [save-block-op (build-block-save-op db | ||
old-block-uid | ||
old-string | ||
(subs new-string 0 index)) | ||
new-block-op (atomic/make-block-new-op parent-uid new-block-uid new-block-order) | ||
new-block-save-op (build-block-save-op db | ||
new-block-uid | ||
"" | ||
(subs new-string index)) | ||
split-block-op (composite/make-consequence-op {:op/type :block/split} | ||
[save-block-op | ||
new-block-op | ||
new-block-save-op])] | ||
split-block-op)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
5ec35e0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: