Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
coffee-react
Advanced tools
Coffee-React provides a JSX-like syntax for building React components with the full awesomeness of CoffeeScript.
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.
neat-component.cjsx
# @cjsx React.DOM
NeatComponent = React.createClass
render: ->
<div className="neat-component">
{<h1>A Component is I</h1> if @props.showTitle}
<hr />
{<p>This line has been printed {n} times</p> for n in [1..10]}
</div>
compile it
$ cjsx -cb neat-component.cjsx
neat-component.js
// Generated by CoffeeScript 1.7.1
var NeatComponent;
NeatComponent = React.createClass({
render: function() {
var n;
return React.createElement(React.DOM.div, {
"className": "neat-component"
}, (this.props.showTitle ? React.createElement(React.DOM.h1, null, "A Component is I") : void 0), React.createElement(React.DOM.hr, null), (function() {
var _i, _results;
_results = [];
for (n = _i = 1; _i <= 10; n = ++_i) {
_results.push(React.createElement(React.DOM.p, null, "This line has been printed ", n, " times"));
}
return _results;
})());
}
});
npm install -g coffee-react
$ 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
As with the coffee-script
module, you need to register .cjsx
with the module loader:
require('coffee-react/register')
Component = require('./component.cjsx')
A recent addition to JSX (and CJSX) is 'spread attributes' which allow merging an object of props into a component, eg:
extraProps = color: 'red', speed: 'fast'
<div color="blue" {... extraProps} />
which is transformed to:
extraProps = color: 'red', speed: 'fast'
React.createElement(React.DOM.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 (basically all of them).
es6-shim and object.assign are two possible choices.
React 0.12 will introduce 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
.
In preparation for this, 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.
require
CJSX files on the server (also possible with coffee-react/register).FAQs
Coffeescript compiler wrapper adding coffee-react-transform CJSX support
The npm package coffee-react receives a total of 1,261 weekly downloads. As such, coffee-react popularity was classified as popular.
We found that coffee-react demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.