refactor(outliner): remvoe cursor impl

This commit is contained in:
defclass
2021-02-22 14:31:44 +08:00
parent c4ac7662d6
commit 88121ae9d3
2 changed files with 1 additions and 155 deletions

View File

@@ -2,9 +2,7 @@
(:require [cljs.test :refer [deftest is are testing use-fixtures]]
[frontend.modules.outliner.tree :as tree]
[frontend.db.conn :as conn]
[frontend.db.outliner :as db-outliner]
[datascript.core :as d]
[frontend.util :as util]))
[datascript.core :as d]))
(defn build-block-by-ident
([id]
@@ -181,26 +179,6 @@
(is (= [6 9] old-parent's-children))
(is (= [13 14 3 15] new-parent's-children))))))
(deftest test-get-node-list-with-cursor
(binding [conn/*outline-db* (conn/create-outliner-db)]
(build-sql-records node-tree)
(let [cursor (-> (build-by-block-id 1 nil nil)
(tree/init-cursor))
number 7
{:keys [acc cursor]}
(tree/get-node-list-with-cursor number cursor)]
(is (= [1 2 3 4 5 6 7] (mapv #(-> % :data :block/id) acc)))
(let [{:keys [acc cursor]}
(tree/get-node-list-with-cursor number cursor)]
(is (= [8 9 10 11 12 13 14] (mapv #(-> % :data :block/id) acc)))
(let [{:keys [acc]}
(tree/get-node-list-with-cursor number cursor)]
(is (= [15 16 17] (mapv #(-> % :data :block/id) acc))))))))
(defn- get-block-id
[block]
(get-in block [:data :block/id]))
@@ -244,44 +222,3 @@
[6 [[7 [8]]]]
[9 [10]]]]]]]
result)))))
(comment
(defn build-node-from-sql-record
"build node from RDS records"
[node-id sql-records]
(letfn [(get-right
[node-id children]
(some #(when (= (:left %) node-id)
%)
children))
(sort-children
[parent-node-id children]
(loop [node-id parent-node-id
result []]
(if-let [node (get-right node-id children)]
(let [result (conj result node)]
(recur (:id node) result))
(do
(when (not= (count children) (count result))
(throw (js/Error "children data error, ")))
result))))
(get-children
[node-id]
(filter #(= (:parent %) node-id) sql-records))
(build [node-id depth]
(when (= depth 20)
(throw (js/Error "Recur depth is too large.")))
(let [children (some->> (get-children node-id)
(sort-children node-id))
children (mapv #(build (:id %) (inc depth)) children)]
(->RenderNode node-id children)))]
(build node-id 0)))
(deftest test-serialize-&-deserialize-tree
(let [tree-record (build-render-tree tree)
sql-record (build-sql-records tree-record)
tree (build-node-from-sql-record 1 sql-record)]
(is (= tree tree-record)))))