Commit 2f413b52 authored by Laurent Wouters's avatar Laurent Wouters
Browse files

Initial import

parents
.DS_Store
.merlin
.bsb.lock
.bs.js
.merlin
npm-debug.log
lib/bs/
node_modules/
build/
\ No newline at end of file
# cubicweb-generic-client
## Run Project
```sh
npm install
npm start
# in another tab
npm run webpack
```
After you see the webpack compilation succeed (the `npm run webpack` step), open up `src/index.html` (**no server needed!**). Then modify whichever `.re` file in `src` and refresh the page to see the changes.
**For more elaborate ReasonReact examples**, please see https://github.com/reasonml-community/reason-react-example
## Build for Production
```sh
npm run build
npm run webpack:production
```
This will replace the development artifact `build/Index.js` for an optimized version.
**To enable dead code elimination**, change `bsconfig.json`'s `package-specs` `module` from `"commonjs"` to `"es6"`. Then re-run the above 2 commands. This will allow Webpack to remove unused code.
/* This is the BuckleScript configuration file. Note that this is a comment;
BuckleScript comes with a JSON parser that supports comments and trailing
comma. If this screws with your editor highlighting, please tell us by filing
an issue! */
{
"name": "react-template",
"reason": {
"react-jsx": 2
},
"sources": {
"dir" : "src",
"subdirs" : true
},
"package-specs": [{
"module": "commonjs",
"in-source": true
}],
"suffix": ".bs.js",
"namespace": true,
"bs-dependencies": [
"reason-react"
],
"refmt": 3
}
{
"name": "cubicweb-generic-client",
"version": "0.1.0",
"scripts": {
"build": "bsb -make-world",
"start": "bsb -make-world -w",
"clean": "bsb -clean-world",
"test": "echo \"Error: no test specified\" && exit 1",
"webpack": "webpack -w",
"webpack:production": "NODE_ENV=production webpack"
},
"keywords": [
"BuckleScript"
],
"author": "",
"license": "MIT",
"dependencies": {
"react": "^16.2.0",
"react-dom": "^16.2.0",
"reason-react": ">=0.4.0",
"bootstrap": "^3.3.7"
},
"devDependencies": {
"bs-platform": "^3.1.5",
"webpack": "^4.0.1",
"webpack-cli": "^2.0.10"
}
}
ReactDOMRe.renderToElementWithId(<App message="Hello!" />, "app");
This diff is collapsed.
/* This is the basic component. */
let component = ReasonReact.statelessComponent("Page");
/* Your familiar handleClick from ReactJS. This mandatorily takes the payload,
then the `self` record, which contains state (none here), `handle`, `reduce`
and other utilities */
let handleClick = (_event, _self) => Js.log("clicked!");
/* `make` is the function that mandatorily takes `children` (if you want to use
`JSX). `message` is a named argument, which simulates ReactJS props. Usage:
`<Page message="hello" />`
Which desugars to
`ReasonReact.element(Page.make(~message="hello", [||]))` */
let make = (~message, _children) => {
...component,
render: self =>
<div onClick=(self.handle(handleClick))>
(ReasonReact.string(message))
</div>,
};
/* State declaration */
type state = {
count: int,
show: bool,
};
/* Action declaration */
type action =
| Click
| Toggle;
/* Component template declaration.
Needs to be **after** state and action declarations! */
let component = ReasonReact.reducerComponent("Example");
/* greeting and children are props. `children` isn't used, therefore ignored.
We ignore it by prepending it with an underscore */
let make = (~greeting, _children) => {
/* spread the other default fields of component here and override a few */
...component,
initialState: () => {count: 0, show: true},
/* State transitions */
reducer: (action, state) =>
switch (action) {
| Click => ReasonReact.Update({...state, count: state.count + 1})
| Toggle => ReasonReact.Update({...state, show: ! state.show})
},
render: self => {
let message =
"You've clicked this " ++ string_of_int(self.state.count) ++ " times(s)";
<div>
<button onClick=(_event => self.send(Click))>
(ReasonReact.string(message))
</button>
<button onClick=(_event => self.send(Toggle))>
(ReasonReact.string("Toggle greeting"))
</button>
(self.state.show ? ReasonReact.string(greeting) : ReasonReact.null)
</div>;
},
};
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Cubicweb</title>
<link rel="stylesheet" type="text/css" href="bootstrap.min.css">
</head>
<body>
<div id="app"></div>
<script src="../build/Index.js"></script>
</body>
</html>
\ No newline at end of file
const path = require('path');
const outputDir = path.join(__dirname, "build/");
const isProd = process.env.NODE_ENV === 'production';
module.exports = {
entry: './src/Index.bs.js',
mode: isProd ? 'production' : 'development',
output: {
path: outputDir,
publicPath: outputDir,
filename: 'Index.js',
},
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment