Skip to content

Instantly share code, notes, and snippets.

(deftest conforming-regular-properties
(are [out in] (= out (q/conform in))
'[[:property [:simple a]]]
'[a]
'[[:property [:simple a]]
[:property [:simple b]]]
'[a b]
'[[:property [:simple a]]
(comment
;;;; Non-recursive queries
;; Regular property
(s/conform ::query '[a])
(s/conform ::query '[a b])
(s/conform ::query '[a b c])
;; Link property
(s/conform ::query '[[a _]])
;;;; Test code
(require '[clojure.spec :as s])
(s/def ::simple-value
symbol?)
(s/def ::link-value
(s/tuple symbol? any?)
#_(s/tuple symbol? keyword?)
(do
(om.next/defui
User
static
om.next/IQuery
(query
[this]
[({:user (om.next/get-query User)} '{:id ?user-id})]))
(def user (workflo.macros.view/factory User {}))
(workflo.macros.view/register-view! 'User {:factory user, :view User}))
boot.user=> (clojure.pprint/pprint onyx.plugin.redis/operations)
{:exists #'taoensso.carmine/exists,
:role #'taoensso.carmine/role,
:ping #'taoensso.carmine/ping,
:del #'taoensso.carmine/del,
:zscan #'taoensso.carmine/zscan,
:zremrangebyrank #'taoensso.carmine/zremrangebyrank,
:lpushx #'taoensso.carmine/lpushx,
:command-info #'taoensso.carmine/command-info,
:mget #'taoensso.carmine/mget,
{:onyx/name :redis
:onyx/plugin :onyx.plugin.redis/writer
:onyx/type :output
:onyx/medium :redis
:redis/uri "redis://localhost:6379"
:onyx/batch-size batch-size}
(ns workflo.macros.command
(:require [clojure.spec :as s]
[clojure.spec.gen :as gen]))
(s/def ::command-name
symbol?)
(s/def ::command-description
string?)
;;;; Macro definition
(s/fdef defcommand
:args (s/cat :name ::command-name
:description (s/? ::command-description)
:inputs ::command-inputs
:forms (s/* ::command-form)
:implementation ::command-implementation)
:ret ::s/any)
@Jannis
Jannis / workflo-macros-props-to-om-next-query.cljs
Last active June 22, 2016 12:15
From the `workflo/macros` properties destructuring syntax to Om Next queries with clojure.spec
boot.user=> (require 'workflo.macros.props :reload)
boot.user=> (in-ns 'workflo.macros.props)
;; Validate and parse the properties destructuring syntax using
;; `clojure.spec/conform`:
workflo.macros.props=> (s/conform ::properties-spec '[db [id] {users [user [name email]]} [current-user _]])
[[:properties {:base db, :children [[:name id]]}]
[:property [:join [:properties-join {users [user [name email]]}]]]
[:property [:link {:name current-user, :link-id _}]]]
;;;; Works
(ns workflo.macros.scratch
(:require #?(:cljs [cljs.spec :as s]
:clj [clojure.spec :as s])
[clojure.test.check.generators :as gen]))
(s/def ::item
symbol?)