Skip to content

Commit f24915e

Browse files
committed
Renamed namespace from rum to rum.core
1 parent e1e68ae commit f24915e

File tree

6 files changed

+61
-67
lines changed

6 files changed

+61
-67
lines changed

README.md

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ Rum provides basic tools that every React app eventually need:
3535

3636
## Using Rum <a href="https://gitter.im/tonsky/rum?utm_source=badge&amp;utm_medium=badge&amp;utm_campaign=pr-badge&amp;utm_content=badge"><img src="https://camo.githubusercontent.com/da2edb525cde1455a622c58c0effc3a90b9a181c/68747470733a2f2f6261646765732e6769747465722e696d2f4a6f696e253230436861742e737667" alt="Gitter" data-canonical-src="https://badges.gitter.im/Join%20Chat.svg" style="max-width:100%;"></a>
3737

38-
1. Add `[rum "0.3.0"]` to dependencies
39-
2. `(require 'rum)`.
38+
1. Add `[rum "0.4.0"]` to dependencies
39+
2. `(require '[rum.core :as rum])`.
4040

4141
Simplest example defines component, instantiates it and mounts it on a page:
4242

4343
```clojure
4444
(ns example
45-
(:require rum))
45+
(:require [rum.core :as rum]))
4646

4747
(rum/defc label [n text]
4848
[:.label (repeat n text)])
@@ -52,14 +52,6 @@ Simplest example defines component, instantiates it and mounts it on a page:
5252

5353
For more examples, see [examples/examples.cljs](examples/examples.cljs). Live version of examples [is here](http://tonsky.me/rum/)
5454

55-
Note: _To suppress warning about single-segmented namespace, add this:_
56-
57-
```clojure
58-
:compiler {
59-
{:warnings {:single-segment-namespace false}}
60-
}
61-
```
62-
6355
## Rum resources
6456

6557
- [Norbert Wójtowicz talk at Lambda Days 2015](https://vimeo.com/122316380) where he explains benefits of web development with ClojureScript and React, and how Rum emulates all main ClojureScript frameworks
@@ -90,7 +82,7 @@ Behind the scenes, `defc` does couple of things:
9082

9183
When called, `name` function will create new React element from built React class and pass through `argvec` so it’ll be available inside `render-body`
9284

93-
To mount component, use `rum/mount`:
85+
To mount component, use `rum.core/mount`:
9486

9587
```clojure
9688
(rum/mount element dom-node)
@@ -121,7 +113,7 @@ or call `request-render` function:
121113

122114
Rum comes with a couple of mixins which emulate behaviors known from `quiescent`, `om` and `reagent`. Developing your own mixin is also very simple.
123115

124-
`rum/static` will check if arguments of a component constructor have changed (with Clojure’s `-equiv` semantic), and if they are the same, avoid re-rendering.
116+
`rum.core/static` will check if arguments of a component constructor have changed (with Clojure’s `-equiv` semantic), and if they are the same, avoid re-rendering.
125117

126118
```clojure
127119
(rum/defc label < rum/static [n text]
@@ -132,7 +124,7 @@ Rum comes with a couple of mixins which emulate behaviors known from `quiescent`
132124
(rum/mount (label 1 "xyz") body) ;; this will cause a re-render
133125
```
134126

135-
`rum/local` creates an atom that can be used as per-component local state. When you `swap!` or `reset!` this atom, component will be re-rendered automatically. Atom can be found in state under `:rum/local` key:
127+
`rum.core/local` creates an atom that can be used as per-component local state. When you `swap!` or `reset!` this atom, component will be re-rendered automatically. Atom can be found in state under `:rum/local` key:
136128

137129
```clojure
138130
(rum/defcs stateful < (rum/local 0) [state title]
@@ -144,9 +136,9 @@ Rum comes with a couple of mixins which emulate behaviors known from `quiescent`
144136
(rum/mount (stateful "Clicks count") js/document.body)
145137
```
146138

147-
Note that we used `defcs` instead of `defc` to get state as first argument to `render`. Also note that `rum/local` is not a mixin value, instead, it’s a function, generator-like: it takes initial value and returns mixin.
139+
Note that we used `defcs` instead of `defc` to get state as first argument to `render`. Also note that `rum.core/local` is not a mixin value, instead, it’s a function, generator-like: it takes initial value and returns mixin.
148140

149-
`rum/reactive` will create “reactive” component that will track references used inside `render` function and auto-update when values of these references change.
141+
`rum.core/reactive` will create “reactive” component that will track references used inside `render` function and auto-update when values of these references change.
150142

151143
```clojure
152144
(def color (atom "#cc3333"))
@@ -161,16 +153,16 @@ Note that we used `defcs` instead of `defc` to get state as first argument to `r
161153
(reset! color "#000") ;; and another one
162154
```
163155

164-
`rum/react` function used in this example works as `deref`, and additionally adds watch on that reference.
156+
`rum.core/react` function used in this example works as `deref`, and additionally adds watch on that reference.
165157

166-
Finally, `rum/cursored` is a mixin that will track changes in references passed as arguments:
158+
Finally, `rum.core/cursored` is a mixin that will track changes in references passed as arguments:
167159

168160
```clojure
169161
(rum/defc label < rum/cursored [color text]
170162
[:.label {:style {:color @color}} @text])
171163
```
172164

173-
Note that `cursored` mixin creates passive component: it will not react to any changes in references by itself, and will only compare arguments when re-created by its parent. Additional `rum/cursored-watch` mixin will add watches on every `IWatchable` in arguments list:
165+
Note that `cursored` mixin creates passive component: it will not react to any changes in references by itself, and will only compare arguments when re-created by its parent. Additional `rum.core/cursored-watch` mixin will add watches on every `IWatchable` in arguments list:
174166

175167
```clojure
176168
(rum/defc body < rum/cursored rum/cursored-watch [color text]
@@ -328,6 +320,10 @@ This is a detailed breakdown of what happens inside of Rum. By using `rum/defc`,
328320

329321
## Changes
330322

323+
### 0.4.0
324+
325+
- [ BREAKING ] Core namespace was renamed from `rum` to `rum.core` to supress CLJS warnings
326+
331327
### 0.3.0
332328

333329
- Upgraded to React 0.13.3, Sablono 0.3.6, ClojueScript 1.7.48

examples/examples.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(ns examples
22
(:require
33
[clojure.string :as str]
4-
[rum]))
4+
[rum.core :as rum]))
55

66
(enable-console-print!)
77

project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(defproject rum "0.3.0"
1+
(defproject rum "0.4.0"
22
:description "ClojureScript wrapper for React"
33
:license { :name "Eclipse"
44
:url "http://www.eclipse.org/legal/epl-v10.html" }

src/rum.clj renamed to src/rum/core.clj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(ns rum
1+
(ns rum.core
22
(:require
33
[sablono.compiler :as s]))
44

@@ -36,7 +36,7 @@
3636
ctor# (fn [& args#]
3737
(let [state# (args->state args#)]
3838
(rum/element class# state# nil)))]
39-
(with-meta ctor# {::class class#})))))
39+
(with-meta ctor# {:rum/class class#})))))
4040

4141
(defmacro defc
4242
"Defc does couple of things:
@@ -82,8 +82,8 @@
8282
Special properties goes at the end of arguments list and should be namespaced.
8383
For now only :rum/key and :rum/ref are supported"
8484
[ctor & args]
85-
(let [props {::key "key"
86-
::ref "ref"}
85+
(let [props {:rum/key "key"
86+
:rum/ref "ref"}
8787
as (take-while #(not (props %)) args)
8888
ps (->> (drop-while #(not (props %)) args)
8989
(partition 2)

src/rum.cljs renamed to src/rum/core.cljs

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
(ns rum
2-
(:require-macros rum)
1+
(ns rum.core
2+
(:require-macros rum.core)
33
(:require
44
[cljsjs.react]
55
[sablono.core]))
66

7-
#_(enable-console-print!)
8-
97
(let [last-id (volatile! 0)]
108
(defn next-id []
119
(vswap! last-id inc)))
@@ -14,7 +12,7 @@
1412
(aget (.-state comp) ":rum/state"))
1513

1614
(defn id [comp]
17-
(::id @(state comp)))
15+
(:rum/id @(state comp)))
1816

1917
(defn- collect [fn-key classes]
2018
(->> classes
@@ -53,8 +51,8 @@
5351
(fn []
5452
(this-as this
5553
(let [props (.-props this)
56-
state (-> { ::react-component this
57-
::id (next-id) } ;; assign id on mount?
54+
state (-> { :rum/react-component this
55+
:rum/id (next-id) } ;; assign id on mount?
5856
(merge (props->state props)))]
5957
#js { ":rum/state" (volatile! state) })))
6058
:componentWillMount
@@ -71,8 +69,8 @@
7169
(fn [next-props]
7270
(this-as this
7371
(let [old-state @(state this)
74-
next-state (-> { ::react-component this
75-
::id (::id old-state) }
72+
next-state (-> { :rum/react-component this
73+
:rum/id (:rum/id old-state) }
7674
(merge (props->state next-props)))
7775
next-state (reduce #(%2 old-state %1) next-state transfer-state)]
7876
(.setState this #js {":rum/state" (volatile! next-state)}))))
@@ -156,24 +154,24 @@
156154
;; initialization
157155

158156
(defn render->mixin [render-fn]
159-
{ :render (fn [state] [(apply render-fn (::args state)) state]) })
157+
{ :render (fn [state] [(apply render-fn (:rum/args state)) state]) })
160158

161159
(defn render-state->mixin [render-fn]
162-
{ :render (fn [state] [(apply render-fn state (::args state)) state]) })
160+
{ :render (fn [state] [(apply render-fn state (:rum/args state)) state]) })
163161

164162
(defn render-comp->mixin [render-fn]
165-
{ :render (fn [state] [(apply render-fn (:rum/react-component state) (::args state)) state]) })
163+
{ :render (fn [state] [(apply render-fn (:rum/react-component state) (:rum/args state)) state]) })
166164

167165
(defn args->state [args]
168-
{::args args})
166+
{:rum/args args})
169167

170168
(defn element [class state & [props]]
171169
(let [props (or props #js {})]
172170
(aset props ":rum/initial-state" state)
173171
(js/React.createElement class props)))
174172

175173
(defn ctor->class [ctor]
176-
(::class (meta ctor)))
174+
(:rum/class (meta ctor)))
177175

178176
(defn with-key [element key]
179177
(js/React.cloneElement element #js { "key" key } nil))
@@ -186,7 +184,7 @@
186184
(def static {
187185
:should-update
188186
(fn [old-state new-state]
189-
(not= (::args old-state) (::args new-state)))
187+
(not= (:rum/args old-state) (:rum/args new-state)))
190188
})
191189

192190
;; local mixin
@@ -215,18 +213,18 @@
215213
(def ^:dynamic *reactions*)
216214

217215
(defn- reactive-key [state]
218-
(str ":rum/reactive-" (::id state)))
216+
(str ":rum/reactive-" (:rum/id state)))
219217

220218
(def reactive {
221219
:transfer-state
222220
(fn [old new]
223-
(assoc new ::refs (::refs old)))
221+
(assoc new :rum/refs (:rum/refs old)))
224222
:wrap-render
225223
(fn [render-fn]
226224
(fn [state]
227225
(binding [*reactions* (volatile! #{})]
228-
(let [comp (::react-component state)
229-
old-reactions (::refs state #{})
226+
(let [comp (:rum/react-component state)
227+
old-reactions (:rum/refs state #{})
230228
[dom next-state] (render-fn state)
231229
new-reactions @*reactions*
232230
key (reactive-key state)]
@@ -238,13 +236,13 @@
238236
(add-watch ref key
239237
(fn [_ _ _ _]
240238
(request-render comp)))))
241-
[dom (assoc next-state ::refs new-reactions)]))))
239+
[dom (assoc next-state :rum/refs new-reactions)]))))
242240
:will-unmount
243241
(fn [state]
244242
(let [key (reactive-key state)]
245-
(doseq [ref (::refs state)]
243+
(doseq [ref (:rum/refs state)]
246244
(remove-watch ref key)))
247-
(dissoc state ::refs))
245+
(dissoc state :rum/refs))
248246
})
249247

250248
(defn react [ref]
@@ -325,31 +323,31 @@
325323
(def cursored {
326324
:transfer-state
327325
(fn [old new]
328-
(assoc new ::om-args (::om-args old)))
326+
(assoc new :rum/om-args (:rum/om-args old)))
329327
:should-update
330328
(fn [old-state new-state]
331-
(not= (::om-args old-state) (deref-args (::args new-state))))
329+
(not= (:rum/om-args old-state) (deref-args (:rum/args new-state))))
332330
:wrap-render
333331
(fn [render-fn]
334332
(fn [state]
335333
(let [[dom next-state] (render-fn state)]
336-
[dom (assoc next-state ::om-args (deref-args (::args state)))])))
334+
[dom (assoc next-state :rum/om-args (deref-args (:rum/args state)))])))
337335
})
338336

339337
(defn- cursored-key [state]
340-
(str ":rum/cursored-" (::id state)))
338+
(str ":rum/cursored-" (:rum/id state)))
341339

342340
(def cursored-watch {
343341
:did-mount
344342
(fn [state]
345-
(doseq [arg (::args state)
343+
(doseq [arg (:rum/args state)
346344
:when (satisfies? IWatchable arg)]
347345
(add-watch arg (cursored-key state)
348-
(fn [_ _ _ _] (request-render (::react-component state)))))
346+
(fn [_ _ _ _] (request-render (:rum/react-component state)))))
349347
state)
350348
:will-unmount
351349
(fn [state]
352-
(doseq [arg (::args state)
350+
(doseq [arg (:rum/args state)
353351
:when (satisfies? IWatchable arg)]
354352
(remove-watch arg (cursored-key state)))
355353
state)

0 commit comments

Comments
 (0)