File tree Expand file tree Collapse file tree 1 file changed +20
-18
lines changed
frameworks/keyed/re-frame/src/demo Expand file tree Collapse file tree 1 file changed +20
-18
lines changed Original file line number Diff line number Diff line change 70
70
(assoc ::data {})
71
71
(assoc ::data-ids []))))
72
72
73
+ (defn random-label []
74
+ (str (rand-nth adjectives) " "
75
+ (rand-nth colours) " "
76
+ (rand-nth nouns)))
77
+
73
78
(rf/reg-event-db
74
79
::append-data
75
80
(fn [db [_ n]]
76
81
(let [start (::max-id db 0 )
77
82
ids (range (inc start) (+ start n 1 ))
78
- new-data (apply merge
79
- (map (fn [id] {id {:id id
80
- :label (str (rand-nth adjectives) " " (rand-nth colours) " " (rand-nth nouns))}}) ids))]
83
+ new-data
84
+ (into {} (map #(into [%] {:id % :label (random-label )}) ids))]
81
85
(-> db
82
- (assoc ::max-id (last ids ))
86
+ (assoc ::max-id (+ start n ))
83
87
(update ::data-ids into ids)
84
88
(update ::data merge new-data)))))
85
89
86
90
(rf/reg-event-db
87
91
::update-some
88
92
(fn [db _]
89
- (let [ids (map-indexed (fn [idx id]
90
- (when (= 0 (mod idx 10 )) id))
91
- (::data-ids db))
92
- new-data (apply merge
93
- (map (fn [id]
94
- {id {:id id
95
- :label (-> db
96
- ::data
97
- (get id)
98
- :label
99
- (str " !!!" ))}})
100
- ids))]
101
- (-> db
102
- (update ::data merge new-data)))))
93
+ (let [updated-data
94
+ (transduce
95
+ (comp
96
+ (map-indexed vector)
97
+ (filter (fn [[idx _id]] (zero? (mod idx 10 ))))
98
+ (map (fn [[_idx id]]
99
+ [id (-> (get-in db [::data id])
100
+ (update :label str " !!!" ))])))
101
+ merge
102
+ {}
103
+ (::data-ids db))]
104
+ (update db ::data merge updated-data))))
103
105
104
106
(rf/reg-event-db
105
107
::swap-rows
You can’t perform that action at this time.
0 commit comments