вторник, 22 августа 2017 г.

react learning: simple table

(println "js app is started.")

(def excel-data (reagent/atom {:h ["book" "author" "language" "published" "sales"]
                               :b [["The Lord of the Rings" "J. R. R. Tolkien" "English" "1954–1955" "150 million"]
                                   ["Le Petit Prince (The Little Prince)" "Antoine de Saint-Exupéry" "French" "1943" "140 million"]
                                   ["Harry Potter and the Philosopher's Stone" "J. K. Rowling" "English" "1997" "107 million"]
                                   ["And Then There Were None" "Agatha Christie" "English" "1939" "100 million"]
                                   ["Dream of the Red Chamber" "Cao Xueqin" "Chinese" "1754–1791" "100 million"]
                                   ["The Hobbit" "J. R. R. Tolkien" "English" "1937" "100 million"]
                                   ["She: A History of Adventure" "H. Rider Haggard" "English" "1887" "100 million"]]}))

(defn table-body
  (for [row body]
    [:tr (for [cell row]
           [:td cell])]))

(defn table-header
  [:tr (for [e header]
         [:th e])])

(defn excel-app
  "Excel prototype application"
    [:thead (table-header (:h @excel-data))]
    [:tbody (table-body (:b @excel-data))]]])

(reagent/render-component [excel-app excel-data]
                          (.getElementById js/document "app"))

It looks like this:

PS: Use ^{:key (gensym)} before :th, :tr, :td to avoid warning about unique key

воскресенье, 20 августа 2017 г.

react learning: shared state example

(def str-area (reagent/atom "init"))
(def length (reagent/atom 0))

(defn my-text-area [area-value]
  [:textarea {:id :comments
              :defaultValue @area-value
              :on-change #(do
                            (reset! str-area (-> % .-target .-value))
                            (reset! length (count (-> % .-target .-value))))}])

(defn text-counter []
   "Counter: " @length])

(defn text-value []
   "Value: " @str-area])

(defn app []
   [my-text-area str-area]

(reagent/render-component [app]
                          (.getElementById js/document "app"))

It looks like this:

воскресенье, 6 августа 2017 г.

Enable Java Mission Control

Just put these flags as JVM parameters:

-Dcom.sun.management.jmxremote.rmi.port=7091 -Dcom.sun.management.jmxremote.port=7091 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -XX:+UnlockCommercialFeatures -XX:+FlightRecorder

среда, 12 июля 2017 г.

my if

;; what if "if" is unavailable?
;; what if we cannot use  code branch execution fn's? (case, cond, if, etc..)
;; let's create our own if

среда, 14 июня 2017 г.

Event Sourcing part 1

Spacemacs + smartscan

Very handy package - Smartscan for Clojure code editing, renaming local vars in fn, jumping to usages & more.

Spacemacs + Cider + 2 repls

When we use EMACS/Spacemacs and want to use two repls for CLJ and CLJS then
1. just add (add-to-list 'auto-mode-alist '("\.cljs$" . clojurescript-mode)) to init.el to enable clojurescript-mode for cljs files (otherwise it will be clojure mode with some problems in CLJS).
2. Select CLJ file and run cider-jack-in to run Clojure REPL
3. Select CLJS file (check that EMACS in Clojurescript mode) and run cider-jack-in-clojurescript or run cider-jack-in and then  (require'[ figwheel-sidecar.repl-api :as f]) and
(f/start-figwheel!) and (f/cljs-repl)

If I need to work with two different Clojure REPLs and eval S-forms I do following.

Run two REPLs by cider-jack-in command. 

To switch between REPL connections:
1. M-x and choose cider-toogle-request-dispatch to set CIDER variable to static mode
2. choose appropriate repl window and run command: cider-make-connection-default

Now, all S-exp will be evaluated in a default repl process.