All Projects → vbedegi → re-alm

vbedegi / re-alm

Licence: MIT license
An Elm Architecture experiment in ClojureScript

Programming Languages

clojure
4091 projects

Projects that are alternatives of or similar to re-alm

breaking-point
BREAKING-POINT lets you quickly define and subscribe to screen (i.e. window) breakpoints in your re-frame application
Stars: ✭ 36 (+50%)
Mutual labels:  reagent, re-frame
tailwind-hiccup
tailwindcss + hiccup = 👍👍
Stars: ✭ 34 (+41.67%)
Mutual labels:  reagent, re-frame
Tincture
Frontend development toolkit for ClojureScript
Stars: ✭ 24 (+0%)
Mutual labels:  reagent, re-frame
Re Frame
A ClojureScript framework for building user interfaces, leveraging React
Stars: ✭ 4,980 (+20650%)
Mutual labels:  reagent, re-frame
learn-re-frame-course-files
🎦 Learn re-frame course files for building Cheffy app
Stars: ✭ 51 (+112.5%)
Mutual labels:  reagent, re-frame
Cljfx
Declarative, functional and extensible wrapper of JavaFX inspired by better parts of react and re-frame
Stars: ✭ 624 (+2500%)
Mutual labels:  reagent, re-frame
Gorilla Notebook
A clojure/clojurescript notebook application/-library based on Gorilla-REPL
Stars: ✭ 73 (+204.17%)
Mutual labels:  reagent, re-frame
Conduit
Real world application built with ClojureScript + re-frame
Stars: ✭ 422 (+1658.33%)
Mutual labels:  reagent, re-frame
re-pressed
re-pressed is a clojurescript library that handles keyboard events for re-frame applications.
Stars: ✭ 150 (+525%)
Mutual labels:  reagent, re-frame
re-frame-semantic-ui-react-github-widget
Using semantic-ui-react with re-frame - sample project
Stars: ✭ 21 (-12.5%)
Mutual labels:  reagent, re-frame
roll
RPG dice roller with both Rust CLI and ClojureScript Web interfaces
Stars: ✭ 14 (-41.67%)
Mutual labels:  reagent, re-frame
rn-shadow-steroid
React Native with shadow-cljs on steroids
Stars: ✭ 57 (+137.5%)
Mutual labels:  reagent, re-frame
Re Frame 10x
A debugging dashboard for re-frame. X-ray vision as tooling.
Stars: ✭ 491 (+1945.83%)
Mutual labels:  reagent, re-frame
Re Com
A ClojureScript library of reusable components for Reagent
Stars: ✭ 690 (+2775%)
Mutual labels:  reagent, re-frame
Re Frame Template
A Leiningen template for creating a re-frame application (client only)
Stars: ✭ 454 (+1791.67%)
Mutual labels:  reagent, re-frame
Re Pollsive
Re-pollsive is a clojurescript library that handles polling events for re-frame applications
Stars: ✭ 27 (+12.5%)
Mutual labels:  reagent, re-frame
Lein template descjop
A Leiningen template(Clojure/ClojureScript Project) for Web based desktop application with Electron (atom-shell).
Stars: ✭ 394 (+1541.67%)
Mutual labels:  reagent, re-frame
Re Frisk
Take full control of re-frame app
Stars: ✭ 396 (+1550%)
Mutual labels:  reagent, re-frame
Ventas
Clojure ecommerce platform
Stars: ✭ 114 (+375%)
Mutual labels:  reagent, re-frame
re-frame-realword-example-app
Exemplary real world application built with Clojurescript and re-frame
Stars: ✭ 16 (-33.33%)
Mutual labels:  reagent, re-frame

re-alm

An Elm Architecture experiment in ClojureScript, powered by Reagent

Clojars Project Dependencies Status

Why?

You want to build SPAs the simplest way possible, using nothing, but pure, composable functions.

Usage

Start a new project:

lein new re-alm <project-name>

You can also add Webpack support, so You can easily use npm modules

lein new re-alm <project-name> +webpack

Basic usage

The simples component I can came up with:

(defn init-counter []
  0)
  
(defn render-counter [model dispatch]
  [:div (str model)
    [:button {:on-click #(dispatch :inc)} "increment"]
    [:button {:on-click #(dispatch :dec)} "decrement"]])
    
(defn update-counter [model msg]
  (match msg
         :inc
         (inc model)

         :dec
         (dec model)

         _
         model))

In the render function you get the model, and a function to dispatch your messages with. The messages are automatically routed to your update function.

In the update function you get the actual model, and the message you should handle. I prefer to use core.match here, but it is optional. The result is the new model, or the model and side effects (more on that later)

And finally, you got to bootstrap your app.

(boot
  (.getElementById js/document "app")
  {:update #'update-counter
   :render #'render-counter}
  (init-counter))

Advanced usage

The result of the update function can be the new model, or possibly some side effects attached to it.

(defn update [model msg]
  (match msg
         :go-and-fetch-some-data
         (with-fx
           (assoc model :loading? true)
           (http/get-fx "/url" {:params {:foo :bar}} :fetch-done))

         [:fetch-done {:ok data}]
         (assoc model
                :loading? false
                :data data)
                
         _
         model))

Every time the model changes, the optionally provided subscriptions function is called, where you can describe what external events you are interested in.

(defn update-foo [model msg]
  (match msg
    [:tick _]
    (update model :ticks-so-far inc)))

(defn subscriptions [model]
  [(time/every 1000 :tick)])

(def foo-component
  {:update        #'update-foo
   :render        #'render-foo
   :subscriptions #'subscriptions})

Middlewares are following the concept you may already know from Ring. The middleware function takes a component (the root component of your app), and the message being dispatched. It returns a tuple (vector) of the new version of the model, the side effects made during the update, and the subscriptions your model currently interested in.

(defn wrap-log [handler]
  (fn [component msg]
    (.log js/console msg)
    (handler component msg)))

(boot
   (.getElementById js/document "app")
   component
   model
   (-> ra/handler
       ra/wrap-log))

Parent/children communication example

; TODO

Using websockets

(defn- update-ws [model msg]
  (match msg
         :send-msg
         (ra/with-fx
           model
           (ws/websocket-fx "/ws" "payload"))

         [:message-from-ws m]
         (update-in model [:messages] conj m)

         _
         model))

(defn- subscriptions [model]
  [(ws/websocket "/ws" :message-from-ws)])

(def ws-controller
  {:render        #'render-ws
   :update        #'update-ws
   :subscriptions #'subscriptions})

Roadmap (just a bunch of what-ifs)

  • the effets (http, ws, storage) may go into a separate package
  • the boot process is a mess, needs some cleanup

License

The license is MIT.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].