-
Notifications
You must be signed in to change notification settings - Fork 2
/
readfile_fx_test.cljs
59 lines (53 loc) · 1.41 KB
/
readfile_fx_test.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
(ns jtk-dvlp.re-frame.readfile-fx-test
(:require
[reagent.core :as reagent]
[re-frame.core :as re-frame]
[jtk-dvlp.re-frame.readfile-fx]))
(defn- col->array
[col]
(-> js/Array
.-prototype
.-slice
(.call col)))
(re-frame/reg-event-fx
:on-readfile-fx-success
(fn [_ [_ result]]
(.debug js/console "success" (clj->js result))))
(re-frame/reg-event-fx
:on-readfile-fx-error
(fn [_ [_ result]]
(.debug js/console "error" (clj->js result))))
(re-frame/reg-event-fx
:on-readfile
(fn [_ [_ files]]
{:readfile
{:files files
:charsets (map #(.-name %) files)
:on-success [:on-readfile-fx-success]
:on-error [:on-readfile-fx-error]}}))
(defn view
[]
[:div
[:p "please readfile the two files \"windows-1252\" and \"utf-8\" from within the repo."]
[:p
[:label
{:for "test-success"}
"test will be successful"]
[:br]
[:input
{:type "file"
:id "test-success"
:multiple true
:on-change #(re-frame/dispatch [:on-readfile (-> % .-target .-files col->array js->clj)])}]]
[:p
[:label
{:for "test-fail"}
"test will fail"]
[:br]
[:input
{:type "file"
:id "test-fail"
:multiple true
:on-change #(re-frame/dispatch [:on-readfile (-> % .-target .-files col->array js->clj (conj "I will cause an error!"))])}]]])
(->> (.getElementById js/document "view")
(reagent/render [view]))