-
Notifications
You must be signed in to change notification settings - Fork 65
/
spec.cljs
49 lines (34 loc) · 1.51 KB
/
spec.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
(ns hoplon.spec
(:require [cljs.spec.alpha :as spec]))
;; Attribute Specs ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(spec/def ::elem any?)
(spec/def ::attr keyword?)
(spec/def ::class
(spec/or
:map map?
:string string?
:collection (spec/coll-of (spec/or :keyword keyword? :string string?))))
(spec/def ::value
(spec/or
:string string?
:boolean boolean?))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Attribute Provider Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn attr [vspec]
(spec/cat :element ::elem :attribute ::attr :value vspec))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Attribute Provider Spec Multimethods ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn dispatcher [[_elem key _val]]
(if-let [n (namespace key)] (keyword n "*") key))
(defmulti elem! dispatcher :default ::default)
(defmethod elem! ::default [_] any?)
(defmulti do! dispatcher :default ::default)
(defmethod do! ::default [_] any?)
(defmulti on! dispatcher :default ::default)
(defmethod on! ::default [_] (attr fn?))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Attribute Provider Specs ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(spec/def ::elem! (spec/multi-spec elem! ::elem!))
(spec/def ::do! (spec/multi-spec do! ::do!))
(spec/def ::on! (spec/multi-spec on! ::on!))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;