Skip to content

Commit 7c5c486

Browse files
committed
updated to latest Domino version, added change-history subscription
1 parent a8f5e96 commit 7c5c486

File tree

5 files changed

+89
-18
lines changed

5 files changed

+89
-18
lines changed

README.md

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,76 @@ The schema can now be initialized calling the `:domino.ui.core/init-ctx` re-fram
101101

102102
This event will initialize the domino engine with `domino/initialize` and parse/render the domino-ui components used in the views.
103103

104-
Once the view is initialized, it can be used via the `:domino.ui.core/view` subscription:
104+
Once the view is initialized, it can be used via the `:domino.ui.core/view` subscription.
105105

106+
The following subscriptions are provided:
107+
108+
#### Domino context
109+
```clojure
110+
@(rf/subscribe [::core/ctx :default-ctx])
111+
```
112+
#### Domino model
113+
```clojure
114+
@(rf/subscribe [::core/model :default-ctx])
115+
```
116+
#### view schema
117+
```clojure
118+
@(rf/subscribe [::core/view :default-ctx :default])
119+
```
120+
#### all views for a given context
121+
```clojure
122+
@(rf/subscribe [::core/views :default-ctx])
123+
```
124+
#### Domino DB state
125+
```clojure
126+
@(rf/subscribe [::core/db :default-ctx])
127+
```
128+
#### component state
129+
```clojure
130+
@(rf/subscribe [::core/component-state :default-ctx :first-name])
131+
```
132+
#### component states
133+
```clojure
134+
@(rf/subscribe [::core/component-states :default-ctx])
135+
```
136+
#### subscription to the value associated with a UI component
137+
```clojure
138+
@(rf/subscribe [::core/subscribe :default-ctx :first-name])
139+
```
140+
#### Domino change history for the latest transaction
141+
```clojure
142+
@(rf/subscribe [::core/change-history :default-ctx])
143+
```
144+
145+
Following events are provided
146+
147+
#### initialize Domino context with an initial state
148+
```clojure
149+
@(rf/dispatch [::init-ctx :default-ctx default-schema {:demographics
150+
{:first-name "Bob"}}])
151+
```
152+
153+
#### transact values
106154
```clojure
107-
(defn default-ctx-page []
108-
[:div
109-
[:h3 "default context"]
110-
@(rf/subscribe [::core/view :default-ctx :default])])
155+
@(rf/dispatch [::core/transact :default-ctx
156+
[:first-name "Bob"]
157+
[:last-name "Bobberton"]])
111158
```
159+
#### merge component state
160+
```clojure
161+
@(rf/dispatch [::merge-component-state :default-ctx :first-name {:disabled? true}])
162+
```
163+
#### update component state
164+
```clojure
165+
@(rf/dispatch [::update-component-state :default-ctx :first-name
166+
(fn [state-map] (assoc state-map :disabled? true))])
167+
```
168+
#### trigger effects
169+
```clojure
170+
@(rf/dispatch [::core/trigger :default-ctx [:effect-id]])
171+
```
172+
173+
112174

113175
See [here](https://github.com/domino-clj/domino-ui/blob/master/env/dev/cljs/domino-ui/test_page.cljs)
114176
for a complete example of this in action.

env/dev/cljs/domino-ui/test_components.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
(defmethod component ::c/label [[_ {:keys [context label id]}]]
88
(fn []
9-
[:label label " " @(rf/subscribe [::core/id context id])]))
9+
[:label label " " @(rf/subscribe [::core/subscribe context id])]))
1010

1111
(defmethod component ::c/text-input [[_ {:keys [context id]}]]
1212
(fn []

env/dev/cljs/domino-ui/test_page.cljs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,6 @@
2626
(fn [current-state]
2727
(update current-state :disabled? not))])}
2828
"toggle first name enabled"]
29-
30-
[:button
31-
{:on-click #(rf/dispatch
32-
[::core/trigger
33-
:default-ctx
34-
[:gen-text]])}
35-
"toggle first name enabled"]
3629

3730
[:div
3831
[:label "Last name"]
@@ -42,13 +35,22 @@
4235
[:div
4336
[::component/label
4437
{:id :full-name
45-
:label "Full name"}]]]}
38+
:label "Full name"}]]
39+
40+
[:div
41+
[:button
42+
{:on-click #(rf/dispatch
43+
[::core/trigger
44+
:default-ctx
45+
[:gen-text]])}
46+
"generate text"]
47+
[::component/label {:label "generated text:" :id :text}]]]}
4648
:model [[:demographics
4749
[:first-name {:id :first-name}]
4850
[:last-name {:id :last-name}]
4951
[:full-name {:id :full-name}]]
5052
[:text {:id :text}]]
51-
:effects [{:id :gen-text
53+
:effects [{:id :gen-text
5254
:outputs [:text]
5355
:handler (fn [_ state]
5456
(assoc state :text "hello"))}
@@ -91,10 +93,12 @@
9193
[:div
9294
[:h3 "default context"]
9395
#_[:pre (pprint @(rf/subscribe [::core/ctx :default-ctx]))]
94-
@(rf/subscribe [::core/view :default-ctx :default])
96+
@(rf/subscribe [::core/view :default-ctx :default])
9597
[:hr]
9698
[:label "component states"]
9799
[:pre (pprint @(rf/subscribe [::core/component-states :default-ctx]))]
100+
[:label "change history"]
101+
[:pre (pprint @(rf/subscribe [::core/change-history :default-ctx]))]
98102
[:label "db state"]
99103
[:pre (pprint @(rf/subscribe [::core/db :default-ctx]))]])
100104

project.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
(defproject domino/ui "0.1.3-SNAPSHOT"
1+
(defproject domino/ui "0.1.3"
22
:description "UI component library for Domino"
33
:url "https://github.com/domino-clj/domino-ui"
44
:license {:name "Eclipse Public License"
55
:url "http://www.eclipse.org/legal/epl-v10.html"}
66
:dependencies
77
[[org.clojure/clojure "1.10.0" :scope "provided"]
88
[org.clojure/clojurescript "1.10.520" :scope "provided"]
9-
[domino/core "0.3.1"]
9+
[domino/core "0.3.2"]
1010
[re-frame "0.11.0-rc2"]]
1111

1212
:plugins

src/domino/ui/core.cljs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@
7575
(fn [db [_ ctx-id]]
7676
(get-in db [::contexts ctx-id ::domino/db])))
7777

78+
(rf/reg-sub
79+
::change-history
80+
(fn [db [_ ctx-id]]
81+
(get-in db [::contexts ctx-id ::domino/change-history])))
82+
7883
(defn transact
7984
"runs a Domino transaction using the value from the specified component as the input"
8085
[db [_ ctx-id & id-value-pairs]]

0 commit comments

Comments
 (0)