oakes / odoyle-rum

The Unlicense
71 stars 4 forks source link

Why does the rule's first binding (the id) have to not be a symbol? #4

Closed drewverlee closed 2 years ago

drewverlee commented 2 years ago

I get a spec error (below) that says the rules binding can't be a symbol. I wanted it be a symbol so i could join it to another fact. Like

[id name name] [id height height]

to get somethings name and height. Let me know what i should do.

Here is the spec error.

[Figwheel] Failed to compile build dev in 6.431 seconds.
[Figwheel:WARNING] Could not Compile   /home/drewverlee/Personal/clinical-trials/news-app/src/clinical_trials/news_app/core.cljs   line:26  column:3

  -- Spec failed --------------------

  {app-root ...,
   search-results [... [some-id ... ...] ... ...]}
                        ^^^^^^^

should satisfy

  (fn [%] (not (symbol? %)))

-- Relevant specs -------

:odoyle.rum/what-id:
  (clojure.spec.alpha/or
   :value
   (clojure.spec.alpha/and
    :odoyle.rules/id
    (fn*
     [p1__27610#]
     (clojure.core/not (clojure.core/symbol? p1__27610#)))))
:odoyle.rum/what-tuple:
  (clojure.spec.alpha/cat
   :id
   :odoyle.rum/what-id
   :attr
   :odoyle.rules/what-attr
   :value
   :odoyle.rum/what-value
   :opts
   (clojure.spec.alpha/? :odoyle.rules/what-opts))
:odoyle.rum/rule:
  (clojure.spec.alpha/cat
   :what-block
   (clojure.spec.alpha/? :odoyle.rum/what-block)
   :then-block
   :odoyle.rules/then-block)
:odoyle.rum/rules:
  (clojure.spec.alpha/map-of clojure.core/simple-symbol? :odoyle.rum/rule)

-------------------------
Detected 1 error

  21  ;;        (put! middlend/channel [id ::middlend/search search]))]}))
  22  
  23  
  24  ;;TODO don't render directly into body
  25  (def components
  26    (orum/ruleset
        ^---
  27     {app-root
  28      [:then
  29       (let [*session (orum/prop)]
  30         [:div {:style {:display "grid"
  31                        :grid-template-columns "minmax(350px, 900px)"
drewverlee commented 2 years ago

the spec has a doc...

;; the specs for the ruleset macro are mostly the same as odoyle.rules/ruleset, except:
;; 1. the keys are symbols, not keywords
;; 2. :what blocks are optional
;; 3. in the :what block, only values can have bindings
;; 4. :when blocks aren't allowed
;; 5. :then blocks are required
oakes commented 2 years ago

Yeah id bindings aren't allowed because if they were, there could be more than one match for the rule, and then the question becomes how should it behave -- should the component render itself multiple times?

What you really probably want to do is write this as a normal rule (not an odoyle rum rule), then save the results to a derived fact and bring it into an odoyle rum component. For example see how i'm creating the ::all-todos fact in a normal rule, and then bringing it into an odoyle rum rule in odoyle-rum-todo.

drewverlee commented 2 years ago

Thanks for the feedback. I'll use a derived fact for now. It's probably ideal for clarity.