GithubHelp home page GithubHelp logo

plumpmath / reagent-react-integration Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thheller/reagent-react-integration

0.0 2.0 0.0 239 KB

Clojure 20.29% HTML 8.85% CSS 21.80% JavaScript 49.06%

reagent-react-integration's Introduction

Integrating Reagent into JavaScript/React

WARNING: This won't be easy, you are about to marry together two separate realms.

Or use shadow-cljs

What is it trying to achieve?

You want to start gradually using ClojureScript/Reagent in an existing JavaScript/React project.

Problems

  1. How to export ClojureScript into JavaScript
  2. How to share common dependencies (React, etc.) between ClojureScript/Reagent and JavaScript/React code
  3. How to enable hot-reloading for ClojureScript code

Solving step by step

How to export ClojureScript into JavaScript

  1. Bootstrap ClojureScript project and write your Reagent component
  2. Use reagent.core/reactify-component to adapt Reagent component for usage with JS/React
  3. Use ^:export meta on component's function to export it into a global scope (window object)
  4. Put <script> tag referring ClojureScript output bundle into your HTML before JS project's script
  5. Use Reagent components in your JS project

How to share common dependencies

In JavaScript project
  1. In your JS project create a module that imports shared dependencies and exports them into global scope (window object)
  2. Configure two builds (here using Webpack)
  3. Put <script> tag referring shared deps bundle into your HTML before ClojureScript project's script
In ClojureScript project
  1. Exclude cljsjs/react and cljsjs/react-dom transitive dependencies from reagent dependency
  2. Using :foreign-libs option alias react and react-dom with globally exported (from JS project) ones
  3. Set :infer-externs to true so that compiler can infer external references to shared deps

How to enable hot-reloading for ClojureScript code

On every change to ClojureScript source Figwheel will apply a patch to the code running in the browser. In order to reflect those changes on the screen you have to re-render the app so the new code will be executed.

In JavaScript project
In ClojureScript project

reagent-react-integration's People

Contributors

roman01la avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.