This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[clojure.spec.alpha :as s]) | |
(require '[clojure.spec.gen.alpha :as gen]) | |
;; I was trying to write a spec for an 5-10 character alpha string with a | |
;; custom generator that uses clojure.spec.gen.alpha/char-alpha | |
(s/def ::test | |
(s/spec (s/and string? #(<= 5 (count %) 10)) | |
:gen (fn [] (gen/fmap #(apply str %) | |
(gen/vector gen/char-alpha 5 10))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn websocket-effect | |
[{:keys [uri on-message on-error on-success on-failure websocket]}] | |
(if websocket | |
(rf/dispatch (conj on-success websocket)) | |
(let [websocket (js/WebSocket. uri)] | |
(log/info "Starting new websocket.") | |
(set! (.-onmessage websocket) #(rf/dispatch (conj on-message %))) | |
(set! (.-onerror websocket) #(rf/dispatch (conj on-failure %))) | |
(set! (.-onopen websocket) (fn on-open [] | |
(set! (.-onerror websocket) #(rf/dispatch (conj on-error %))) |