Skip to content

Instantly share code, notes, and snippets.

@gdeer81
Created July 5, 2017 15:06
Show Gist options
  • Save gdeer81/b9d69b8c6915cd7f9199a9fa3359e145 to your computer and use it in GitHub Desktop.
Save gdeer81/b9d69b8c6915cd7f9199a9fa3359e145 to your computer and use it in GitHub Desktop.
This set of rules causes all products to be hidden...but why?
;; Filtering
; product visible when no filter
(define [:app :visible-product/id ?e] :- [:not [_ :product-filter/range]]
[:not [_ :product-filter/category]]
[[?e :product/name]])
; product visible when filter active and price in range
(define [:app :visible-product/id ?e]
:- [[_ :product-filter/range ?range]]
[[?e :product/price ?price]]
[:test (<= (first ?range) ?price (second ?range))])
; product visible when filter active and product category = selected category
(define [:app :visible-product/id ?e]
:- [[_ :product-filter/category ?selected-category]]
[[?e :product/category ?category]]
[:test (= ?category ?selected-category)])
@alex-dixon
Copy link

alex-dixon commented Jul 5, 2017

Minor note you should be able to write the third rule as the following instead of using :test:

; product visible when filter active and product category = selected category
(define [:app :visible-product/id ?e]
   :- [[_ :product-filter/category ?selected-category]]
       [[?e :product/category ?selected-category]])

@gdeer81
Copy link
Author

gdeer81 commented Jul 5, 2017

This had nothing to do with the rules. the subscriptions get broken when there is a clojursecript error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment