• Stars
    star
    413
  • Rank 104,801 (Top 3 %)
  • Language
    CoffeeScript
  • License
    MIT License
  • Created over 10 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

DEPRECATED – Unfancy JavaScript with React JSX markup

Coffee-React

CoffeeScript 2 has JSX built in. You should use that instead

STATUS: DEPRECATED

This tool is no longer maintained. If you need to transition your codebase from it, a codemod is available to do so: cjsx-codemod. You can also use CoffeeScript 2, which has JSX built in.

This project started as a way for me to explore how JSX could fit into Coffeescript syntax, as a quickly hacked together prototype. While I never really promoted it, it quickly took on a life of its own, and before long people were asking for it to support all kinds of different use cases. On top of that I had no experience writing parsers, so the result is something with insurmountable limitations.

As I eventually stopped using Coffeescript I ended up neglecting this project, but as people were using it I didn't want to kill it. I really should have, however, because it meant that people were using a crappy, ill-conceived, unmaintained tool. Now, long overdue, I'm putting it out to pasture.

Original readme follows:

Coffee-React provides a JSX-like syntax for building React components with the full awesomeness of CoffeeScript.

Try it out.

Included is the cjsx executable, which is wrapper for coffee, using coffee-react-transform and coffee-script to transform CJSX to Javascript. You can also require() CJSX components under node for server-side rendering.

Example

neat-component.cjsx

NeatComponent = React.createClass
  render: ->
    <div className="neat-component">
      {<h1>A Component is I</h1> if @props.showTitle}
      <hr />
      {<p key={n}>This line has been printed {n} times</p> for n in [1..5]}
    </div>

compile it

$ cjsx -cb neat-component.cjsx

neat-component.js

// Generated by CoffeeScript 1.9.1
var NeatComponent;

NeatComponent = React.createClass({displayName: "NeatComponent",
  render: function() {
    var n;
    return React.createElement("div", {
      "className": "neat-component"
    }, (this.props.showTitle ? React.createElement("h1", null, "A Component is I") : void 0), React.createElement("hr", null), (function() {
      var i, results;
      results = [];
      for (n = i = 1; i <= 5; n = ++i) {
        results.push(React.createElement("p", {
          "key": n
        }, "This line has been printed ", n, " times"));
      }
      return results;
    })());
  }
});

Installation

npm install -g coffee-react

Version compatibility

  • 5.x - React 0.13.x - 0.15.x
  • 4.x - React 0.13.x - 0.14.x
  • 3.x - React 0.13.x - 0.14.x
  • 2.1.x - React 0.12.1
  • 2.x - React 0.12
  • 1.x - React 0.11.2
  • 0.x - React 0.11 and below

Usage

$ cjsx -h

Usage: cjsx [options] path/to/script.cjsx -- [args]

If called without options, `cjsx` will run your script.

  -b, --bare         compile without a top-level function wrapper
  -c, --compile      compile to JavaScript and save as .js files
  -e, --eval         pass a string from the command line as input
  -h, --help         display this help message
  -j, --join         concatenate the source CoffeeScript before compiling
  -m, --map          generate source map and save as .map files
  -n, --nodes        print out the parse tree that the parser produces
      --nodejs       pass options directly to the "node" binary
      --no-header    suppress the "Generated by" header
  -o, --output       set the output directory for compiled JavaScript
  -p, --print        print out the compiled JavaScript
  -s, --stdio        listen for and compile scripts over stdio
  -l, --literate     treat stdio as literate style coffee-script
  -t, --tokens       print out the tokens that the lexer/rewriter produce
  -v, --version      display the version number
  -w, --watch        watch scripts for changes and rerun commands

Output compiled JS to a file of the same name:

$ cjsx -c my-component.cjsx

Require .cjsx files under node

As with the coffee-script module, you need to register .cjsx with the module loader:

require('coffee-react/register')

Component = require('./component.cjsx')

Spread attributes

JSX/CJSX 'spread attributes' allow merging in an object of props when creating an element, eg:

extraProps = color: 'red', speed: 'fast'
<div color="blue" {...extraProps} />

which is transformed to:

extraProps = color: 'red', speed: 'fast'
React.createElement("div", Object.assign({"color": "blue"},  extraProps)

If you use this syntax in your code, be sure to include a shim for Object.assign for browsers/environments which don't yet support it. object.assign, core-js and es6-shim are some possible choices.

React.createElement

React 0.12 introduced changes to the way component descriptors are constructed, where the return value of React.createClass is not a descriptor factory but simply the component class itself, and descriptors must be created manually using React.createElement or by wrapping the component class with React.createDescriptor.

coffee-react-transform (and as a result, coffee-react) now outputs calls to React.createElement to construct element descriptors from component classes for you, so you won't need to wrap your classes using React.createFactory. However, for this to work you will need to be using at least React 0.11.2, which adds React.createElement.

If you want the older style JSX output (which just desugars into function calls) then you need to use the 0.x branch, eg. 0.5.1.

Additionally, as of 1.0.0, all input files will be CJSX transformed, even if they don't have a .cjsx extension or # @cjsx pragma.

Related projects

More Repositories

1

react-native-htmlview

A React Native component which renders HTML content as native views
JavaScript
2,710
star
2

react-native-refreshable-listview

Deprecated. A pull-to-refresh ListView which shows a loading spinner while your data reloads
JavaScript
1,384
star
3

little-virtual-computer

Learn how computers work by simulating them in Javascript
JavaScript
854
star
4

pce

Emulates Mac Plus, PC, & Atari ST in the browser using WebAssembly
C
829
star
5

coffee-react-transform

DEPRECATED – Provides React JSX support for Coffeescript
CoffeeScript
433
star
6

ReactNativeHackerNews

React Native Hacker News app
JavaScript
256
star
7

browserify-incremental

incremental rebuild for browserify
JavaScript
175
star
8

webpack-combine-loaders

Combine an array of webpack loaders into a loader string
JavaScript
105
star
9

react-ratchet

React components for the Ratchet mobile app UI library
JavaScript
86
star
10

sprockets-coffee-react

DEPRECATED – Sprockets preprocessor for CJSX (Coffeescript with React JSX markup)
Ruby
85
star
11

react-layout

Dynamic subview layout for React
CoffeeScript
83
star
12

goose64

untitled goose game demake for nintendo 64
C++
78
star
13

n64-sdk-demo

n64 homebrew demo app
Objective-C
66
star
14

github-reason-react-tutorial

OCaml
39
star
15

react-commits-graph

react component to render an svg graph of git commits
CoffeeScript
37
star
16

react-form-for

An expressive and intuitive form builder for React in the style of Rails' form_for
JavaScript
37
star
17

deep-freeze

recursively Object.freeze() on objects and functions
JavaScript
32
star
18

hacker-news-mobile

Hacker News mobile web app built in 'Isomorphic' React
JavaScript
27
star
19

lisp.rs

Scheme Interpreter in Rust
Rust
25
star
20

ed64log

printf() and error stacktraces for n64 sdk-based homebrew games running on everdrive64 flashcarts
C
19
star
21

only-if-changed-webpack-plugin

Webpack plugin to only run build if dependent files have changed
JavaScript
18
star
22

flux-coffee

Implements Facebook's Flux pattern in CoffeeScript
CoffeeScript
16
star
23

lisp.re

A LISP interpreter written in ReasonML, targeting native and browser environments
OCaml
16
star
24

inspect-react-element

Prettyprints ReactElements and their children
JavaScript
16
star
25

reason-routing-tutorial

A tutorial for routing in Reason React
JavaScript
15
star
26

applescript-raytracer

a raytracer written in applescript
AppleScript
14
star
27

hacker-news-mobile-api

Turns official Hacker News Firebase API into a REST JSON API
JavaScript
14
star
28

duktape64

javascript on nintendo 64
C
12
star
29

cjsx-codemod

A codemod for migrating off of coffee-react CJSX
JavaScript
11
star
30

strictify

browserify v2 plugin for enforcing strict mode
JavaScript
11
star
31

BussIK-js

Selectively Damped Least Squares for Inverse Kinematics, in JavaScript
JavaScript
11
star
32

find-index

finds an item in an array matching a predicate function, and returns its index
JavaScript
11
star
33

n64soundtools

tools for compiling sound and music data for n64 sdk homebrew games
JavaScript
11
star
34

hacker-news-serverless-api

A hacker news API published as JSON files on S3 by an AWS Lambda function
JavaScript
10
star
35

loader64

USB uploader tool for Everdrive64
C
10
star
36

browserify-cache-api

JavaScript
10
star
37

webpack_rails

DEPRECATED – Integrates Webpack with Rails/Sprockets
Ruby
9
star
38

traceviewer

simple traceviewer renderer
JavaScript
7
star
39

webserial-ed64log

connect to an everdrive 64 from your web browser
JavaScript
6
star
40

oky

An okayish framework for mobile apps with Backbone.
JavaScript
6
star
41

they-live

serverless server monitoring with near-zero running costs
JavaScript
5
star
42

perv

A tool to watch your filesystem and display logged activity via a web interface. Originally created to assist with time tracking.
JavaScript
5
star
43

nvm_auto

automatically `nvm use` when entering a directory with an .nvmrc
Shell
5
star
44

robot-control

3d web ui to simulate and control a robotic arm
JavaScript
4
star
45

cached-loader

DEPRECATED. Adds persistent on-disk caching to webpack loaders
JavaScript
4
star
46

n64-gameoflife

conway's game of life on n64
C
4
star
47

theunarchiver

Automatically exported from code.google.com/p/theunarchiver
C
4
star
48

jamesfriend.com.au

my website
JavaScript
3
star
49

jest-alias-module-loader

JavaScript
3
star
50

rinsefm-feed

Generates iTunes-compatible podcast feeds of Rinse FM via scraping
CoffeeScript
3
star
51

pcejs-embed

easily embed a pcejs emulator anywhere
JavaScript
3
star
52

cosmos

reactjs based cms
CoffeeScript
3
star
53

podcastgen

generate itunes-compatible podcasts from cson or json
CoffeeScript
3
star
54

ruby_node_task

Run node.js scripts from Ruby with a persistent worker
Ruby
3
star
55

bit-packing-explorer

play around with storing multiple pieces of data in a single number value using bit packing
JavaScript
2
star
56

css-modules-loader-core-sync

synchronous version of css-modules-loader-core
JavaScript
2
star
57

minivmac

Browser port of Mini vMac classic mac emulator (and repo mirror)
C
2
star
58

exif2csv

Mac app for dumping image EXIF data to a CSV
Python
2
star
59

aiff-explorer

visualize the contents of an AIFF file
JavaScript
2
star
60

bantam

super lightweight python game engine
Python
1
star
61

fridgemagnets

Realtime alphabet fridgemagnets node.js/browser demo
JavaScript
1
star
62

jspace

space shooter written with only built-in java stuff
Java
1
star
63

spaaaace

love2d game
Lua
1
star
64

scaletoy

chord palette with webmidi output
TypeScript
1
star
65

ReasonPhysics

simple physics simulation for reasonml
OCaml
1
star
66

webaudio

JavaScript
1
star
67

jsdf

github pages
1
star
68

melb-react-animation-talk

JavaScript
1
star
69

robot-arm

robot arm based on the Adafruit PCA9685 board
Python
1
star
70

planetarium

a beat-synced music visualization which controls rgb led strips via bluetooth
JavaScript
1
star