Convert Figma logo to code with AI

day8 logore-frame

A ClojureScript framework for building user interfaces, leveraging React

5,463
719
5,463
22

Top Related Projects

4,811

A minimalistic ClojureScript interface to React.js

1,810

Simple, decomplected, isomorphic HTML UI library for Clojure and ClojureScript

A concise routing library for Ring/Clojure

1,024

Simple and powerful tool for building web apps out of highly composable elements in ClojureScript.

6,647

ClojureScript interface to Facebook's React

Quick Overview

re-frame is a popular ClojureScript framework for building user interfaces, particularly for single-page applications. It combines React for rendering with a Redux-like approach to state management, providing a structured and scalable architecture for front-end development.

Pros

  • Simplifies state management with a clear, predictable data flow
  • Encourages modular and composable code structure
  • Excellent documentation and community support
  • Seamless integration with React for efficient UI rendering

Cons

  • Steeper learning curve for developers new to functional programming or Clojure(Script)
  • Limited ecosystem compared to more mainstream JavaScript frameworks
  • Potential performance overhead for very large applications
  • Requires additional setup for ClojureScript compilation

Code Examples

  1. Defining an event handler:
(re-frame/reg-event-db
 :initialize-db
 (fn [_ _]
   {:items []}))

This code registers an event handler that initializes the application state with an empty list of items.

  1. Creating a subscription:
(re-frame/reg-sub
 :items
 (fn [db _]
   (:items db)))

This subscription allows components to access the items list from the application state.

  1. Dispatching an event:
(re-frame/dispatch [:add-item "New Item"])

This code dispatches an event to add a new item to the list.

  1. Using a subscription in a component:
(defn items-list []
  (let [items @(re-frame/subscribe [:items])]
    [:ul
     (for [item items]
       ^{:key item} [:li item])]))

This component renders a list of items by subscribing to the :items subscription.

Getting Started

  1. Add re-frame to your project dependencies:
[re-frame "1.3.0"]
  1. In your core namespace, require re-frame:
(ns your-app.core
  (:require [re-frame.core :as re-frame]))
  1. Initialize your app:
(defn ^:dev/after-load mount-root []
  (re-frame/clear-subscription-cache!)
  (reagent.dom/render [views/main-panel]
                      (.getElementById js/document "app")))

(defn init []
  (re-frame/dispatch-sync [:initialize-db])
  (mount-root))
  1. Run (init) to start your application.

Competitor Comparisons

4,811

A minimalistic ClojureScript interface to React.js

Pros of Reagent

  • Simpler and more lightweight, with a lower learning curve
  • More flexible, allowing for various architectural patterns
  • Closer to vanilla React, making it easier for React developers to adopt

Cons of Reagent

  • Lacks built-in state management, requiring additional libraries or custom solutions
  • Less opinionated, which can lead to inconsistent code organization across projects
  • May require more boilerplate code for complex applications

Code Comparison

Reagent component:

(defn hello-world []
  [:div
   [:h1 "Hello, World!"]
   [:p "Welcome to Reagent"]])

Re-frame component:

(defn hello-world []
  (let [name @(re-frame/subscribe [:name])]
    [:div
     [:h1 (str "Hello, " name "!")]
     [:p "Welcome to Re-frame"]]))

Summary

Reagent is a lightweight and flexible ClojureScript wrapper for React, while Re-frame builds upon Reagent to provide a more structured, opinionated framework with built-in state management. Reagent offers simplicity and flexibility, making it suitable for smaller projects or developers who prefer more control over their application architecture. Re-frame, on the other hand, provides a more comprehensive solution for larger, complex applications with its event-driven architecture and centralized state management.

1,810

Simple, decomplected, isomorphic HTML UI library for Clojure and ClojureScript

Pros of Rum

  • Simpler and more lightweight, with fewer concepts to learn
  • More flexible, allowing for easier integration with other libraries
  • Faster initial render times due to its minimalistic approach

Cons of Rum

  • Less opinionated, which may lead to inconsistent application structure
  • Fewer built-in features and utilities compared to re-frame
  • Smaller community and ecosystem, potentially resulting in fewer resources and extensions

Code Comparison

re-frame:

(rf/reg-event-db
 :initialize-db
 (fn [_ _]
   {:count 0}))

(rf/reg-sub
 :count
 (fn [db]
   (:count db)))

Rum:

(rum/defc counter < rum/reactive
  []
  (let [count (rum/react (rum/cursor-in state [:count]))]
    [:div (str "Count: " count)]))

Both libraries offer reactive programming models for ClojureScript, but re-frame provides a more structured approach with its event-driven architecture, while Rum focuses on simplicity and flexibility. re-frame's code tends to be more verbose but offers clearer separation of concerns, whereas Rum's code is often more concise but may require additional organization in larger applications.

A concise routing library for Ring/Clojure

Pros of Compojure

  • Lightweight and focused on routing, making it easier to learn and use for simple web applications
  • Integrates well with other Ring-based libraries, allowing for a more modular approach to web development
  • Has been around longer, resulting in a more mature ecosystem and extensive community resources

Cons of Compojure

  • Limited to server-side routing and doesn't provide a full-stack solution like re-frame
  • Lacks built-in state management capabilities, which are crucial for complex single-page applications
  • Doesn't offer a standardized structure for larger applications, potentially leading to inconsistent code organization

Code Comparison

Compojure routing example:

(defroutes app-routes
  (GET "/" [] "Hello World")
  (GET "/users/:id" [id] (str "User " id))
  (POST "/data" {body :body} (process-data body)))

re-frame event handling example:

(re-frame/reg-event-db
 :initialize-db
 (fn [_ _]
   {:name "re-frame"}))

While Compojure focuses on HTTP routing, re-frame provides a more comprehensive framework for building interactive front-end applications with state management and event handling.

1,024

Simple and powerful tool for building web apps out of highly composable elements in ClojureScript.

Pros of Hoplon

  • Simpler syntax and more intuitive DOM manipulation
  • Built-in support for client-server communication
  • Allows for a more traditional HTML-like structure in ClojureScript

Cons of Hoplon

  • Smaller community and ecosystem compared to re-frame
  • Less suitable for large-scale applications with complex state management
  • Steeper learning curve for developers coming from React-like frameworks

Code Comparison

Hoplon:

(defelem hello-world []
  (div
    (h1 "Hello, World!")
    (p "Welcome to Hoplon")))

re-frame:

(defn hello-world []
  [:div
   [:h1 "Hello, World!"]
   [:p "Welcome to re-frame"]])

Key Differences

  • Hoplon uses a more HTML-like structure with function calls
  • re-frame uses Hiccup-style syntax for defining components
  • Hoplon integrates view and logic more tightly, while re-frame separates concerns
  • re-frame provides a more robust state management solution
  • Hoplon is better suited for smaller projects, while re-frame scales well for larger applications

Both frameworks offer unique approaches to building ClojureScript applications, with Hoplon focusing on simplicity and re-frame on scalability and state management.

6,647

ClojureScript interface to Facebook's React

Pros of Om

  • Simpler and more lightweight architecture
  • Closer to React's component model
  • Better performance for large-scale applications due to its immutable data structures

Cons of Om

  • Steeper learning curve for developers new to ClojureScript
  • Less opinionated, requiring more boilerplate code for complex applications
  • Smaller community and ecosystem compared to re-frame

Code Comparison

Om component:

(defui HelloWorld
  Object
  (render [this]
    (dom/div nil "Hello, World!")))

(def hello-world (om/factory HelloWorld))

re-frame view:

(defn hello-world []
  [:div "Hello, World!"])

(reg-sub ::greeting (fn [db _] (:greeting db)))
(reg-event-db ::set-greeting (fn [db [_ value]] (assoc db :greeting value)))

Both Om and re-frame are popular ClojureScript frameworks for building user interfaces. Om focuses on leveraging React's component model and immutable data structures, while re-frame provides a more opinionated architecture with a focus on reactive programming and event-driven design. The choice between the two often depends on the specific needs of the project and the team's familiarity with ClojureScript and React concepts.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

re-frame logo

Derived Values, Flowing

This, milord, is my family's axe. We have owned it for almost nine hundred years, see. Of course, sometimes it needed a new blade. And sometimes it has required a new handle, new designs on the metalwork, a little refreshing of the ornamentation ... but is this not the nine hundred-year-old axe of my family? And because it has changed gently over time, it is still a pretty good axe, y'know. Pretty good.

-- Terry Pratchett, The Fifth Elephant
    reflecting on identity, flow and derived values (aka The Ship of Theseus)



Overview

re-frame is a ClojureScript framework for building user interfaces. It has a data-oriented, functional design. Its primary focus is on high programmer productivity and scaling up to larger Single-Page applications.

Developed in late 2014, and released in 2015, it is mature and stable. It is used by both small startups and companies with over 500 developers, and it has delivered into production applications which are 40K lines of code and beyond.

Across the last 6 years, it has outlasted multiple generations of Javascript churn - just imagine your team's productivity if you didn't have to contend with technical churn, and have new magic burn your fingers every two years. Brand new, exciting concepts like recoiljs (in the React world), have been a regular part of re-frame from the beginning.

re-frame is lucky enough to enjoy an unfair advantage - ClojureScript is a Lisp. Alan Kay once described Lisp as "Maxwell's equations of software". Paul Graham described how Lisp was a competitive advantage for his startup. When we use Lisp, we get to leverage 50 years of foliated excellence from the very best minds available. And then there's also a thriving ClojureScript community which delivers modern ideas and best-in-class tooling.

Although re-frame leverages React (via Reagent), it only needs React to be the V in MVC, and no more. re-frame takes a different road to the currently-pervasive idea that Views should be causal (colocated queries, ComponentDidMount, hooks, etc). In re-frame, events are causal, and views are purely reactive.

Documentation

The re-frame documentation is available here.

The Current Version

Clojars Project

For full dependency information, see the Clojars page

Getting Help

Get help on Slack

Licence

re-frame is MIT licenced