Skip to content

Commit

Permalink
assert mixin keys, resolves #96
Browse files Browse the repository at this point in the history
  • Loading branch information
roman01la committed Jun 29, 2020
1 parent 135ae4e commit 14ced14
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/rum/core.clj
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
(ns rum.core
(:refer-clojure :exclude [ref deref])
(:require
[rum.cursor :as cursor]
[rum.server-render :as render]
[rum.util :refer [collect collect* call-all]]
[rum.derived-atom :as derived-atom]
[daiquiri.compiler :as compiler])
[rum.cursor :as cursor]
[rum.server-render :as render]
[rum.util :refer [collect collect* call-all]]
[rum.derived-atom :as derived-atom]
[daiquiri.compiler :as compiler]
[rum.specs]
[clojure.set :as set])
(:import
[rum.cursor Cursor]
(rum.server_render JSComponent)))
Expand Down Expand Up @@ -111,6 +113,11 @@
(-defc 'rum.core/build-defcc &env body))

(defn- build-ctor [render mixins display-name]
(let [mixins (->> mixins (mapcat keys) set)]
(assert (set/subset? mixins rum.specs/mixins)
(str display-name " declares invalid mixin keys "
(set/difference mixins rum.specs/mixins) ", "
"did you mean one of " rum.specs/mixins)))
(let [init (collect :init mixins) ;; state props -> state
will-mount (collect* [:will-mount ;; state -> state
:before-render] mixins) ;; state -> state
Expand Down
7 changes: 7 additions & 0 deletions src/rum/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
[cljsjs.react.dom]
[goog.object :as gobj]
[goog.functions :as fns]
[clojure.set :as set]
[rum.specs]
[daiquiri.core]
[rum.cursor :as cursor]
[rum.util :as util :refer [collect collect* call-all]]
Expand All @@ -22,6 +24,11 @@
(gobj/set obj (name k) (clj->js v))))

(defn- build-class [render mixins display-name]
(let [mixins (->> mixins (mapcat keys) set)]
(assert (set/subset? mixins rum.specs/mixins)
(str display-name " declares invalid mixin keys "
(set/difference mixins rum.specs/mixins) ", "
"did you mean one of " rum.specs/mixins)))
(let [init (collect :init mixins) ;; state props -> state
will-mount (collect* [:will-mount ;; state -> state
:before-render] mixins) ;; state -> state
Expand Down
7 changes: 7 additions & 0 deletions src/rum/specs.cljc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(ns rum.specs)

(def mixins
#{:init :will-mount :before-render :wrap-render :did-mount
:after-render :did-remount :should-update :will-update
:did-catch :will-unmount :child-context :class-properties
:static-properties})

0 comments on commit 14ced14

Please sign in to comment.