-
-
Save drcode/617351ed39533e11ff43 to your computer and use it in GitHub Desktop.
Example for error: "No queries exist for component path (lisperati.core/Parent lisperati.core/RectLayout)"
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
(ns rectlayout.core | |
(:require [goog.dom :as gdom] | |
[cljs.reader :refer [read-string]] | |
[om.next :as om :refer-macros [defui]] | |
[om-tools.dom :as dom :include-macros true] | |
[datascript.core :as d])) | |
(def conn (d/create-conn {})) | |
(d/transact! conn | |
[{:db/id -1 | |
:rect/color "purple" | |
:rect/dimwidth 3 | |
:rect/dimheight 2 | |
:rect/left 0 | |
:rect/top 0 | |
:rect/width 100 | |
:rect/height 100} | |
{:db/id -2 | |
:rect/color "orange" | |
:rect/dimwidth 2 | |
:rect/dimheight 2 | |
:rect/left 200 | |
:rect/top 0 | |
:rect/width 50 | |
:rect/height 50}]) | |
(enable-console-print!) | |
(defmulti read om/dispatch) | |
(defmethod read :rects [{:keys [state selector]} _ _] | |
(let [foo {:value (d/q '[:find [(pull ?e ?selector) ...] | |
:in $ ?selector | |
:where [?e :rect/color ?color]] | |
(d/db state) | |
selector)}] | |
foo)) | |
(defui Child | |
static om/IQuery | |
(query [this] | |
[:rect/color :rect/width :rect/height :rect/left :rect/top]) | |
Object | |
(render [this] | |
(let [{:keys [:rect/color :rect/width :rect/height :rect/top :rect/left]} (om/props this)] | |
(dom/div {:style {:background-color color | |
:position "absolute" | |
:width (or width 0) | |
:height (or height 0) | |
:left (or left 0) | |
:top (or top 0)}} | |
color | |
)) | |
)) | |
(def child (om/factory Child {:keyfn :db/id})) | |
(defui RectLayout | |
static om/IQuery | |
(query [this] | |
[{:rects [:db/id :rect/dimwidth :rect/dimheight]}]) | |
Object | |
(componentDidMount [this] | |
(om/set-state! this {:foo :bar})) | |
(render [this] | |
(let [children (om/children this)] | |
(apply dom/div | |
{:style {:position "absolute" | |
:background-color "blue" | |
:height "100%" | |
:width "100%"}} | |
children)))) | |
(def rect-layout (om/factory RectLayout)) | |
(defui Parent | |
static om/IQuery | |
(query [this] | |
(update-in (om/get-query RectLayout) | |
[0 :rects] | |
(fn [fields] | |
(vec (distinct (concat fields (om/get-query Child))))))) | |
Object | |
(render [this] | |
(let [{:keys [rects]} (om/props this)] | |
(dom/div (apply rect-layout {} | |
(for [item rects] | |
(child item))))))) | |
(def reconciler | |
(om/reconciler | |
{:state conn | |
:parser (om/parser {:read read})})) | |
(om/add-root! reconciler | |
Parent (gdom/getElement "app")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment