Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions src/deft/core.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns deft.core
(:require
[cljs.analyzer.api :as api]
[deft.core-shared :refer :all]
[deft.core-shared :refer :all :exclude [always-instrument!]]
[malli.core :as m]
[malli.destructure :as md]))

Expand Down Expand Up @@ -293,7 +293,22 @@
~(when (contains? tagged-args :record-like)
`(define-record-like-print-methods ~type-name))

(m/=> ~(symbol (str ">" (name class-name)))

(if @deft.core-shared/always-instrument
(def ~(symbol (str ">" (name class-name)))
(m/-instrument {:schema [:=>
;; TODO deduplicate with above
~(into []
(cons :cat
(mapcat identity
(for [[field type] fields-to-types]
[(if (is-namespaced-key? field)
[:= field]
[:= (keyword (str field))])
type]))))
~class-name]}
~(symbol (str ">" (name class-name)))))
(m/=> ~(symbol (str ">" (name class-name)))
[:=>
;; TODO remove the order restriction once Malli improves
~(into []
Expand All @@ -304,7 +319,9 @@
[:= field]
[:= (keyword (str field))])
type]))))
~class-name]))))
~class-name]))

)))



Expand Down Expand Up @@ -340,4 +357,6 @@

(def get-deft-mutable-registry deft.core-shared/get-deft-mutable-registry-internal)
(def use-deft-malli-registry! deft.core-shared/use-deft-malli-registry-internal!)
;; warning!! this may enforce more things in the future
(def always-instrument! deft.core-shared/always-instrument!)

2 changes: 2 additions & 0 deletions src/deft/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@

(def get-deft-mutable-registry deft.core-shared/get-deft-mutable-registry-internal)
(def use-deft-malli-registry! deft.core-shared/use-deft-malli-registry-internal!)
;; warning!! this may enforce more things in the future
(def always-instrument! deft.core-shared/always-instrument!)
4 changes: 4 additions & 0 deletions src/deft/core_shared.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[clojure.pprint :as pprint]))

(def malli-registry-atom (atom {}))
(def always-instrument (atom false))

#?(:clj
(def-map-type TypeMap [m mta]
Expand Down Expand Up @@ -205,3 +206,6 @@
(mr/composite-registry
(m/default-schemas)
(mr/mutable-registry malli-registry-atom))))

(defn always-instrument! []
(reset! always-instrument true))