Move nut-score into website/sandbox

Also move some .gitignore entries from the top-level .gitignore into a
subdirectory .gitignore.
This commit is contained in:
William Carroll 2020-03-24 12:29:34 +00:00
parent 2551b41d73
commit 57b58e9b2f
15 changed files with 7 additions and 9 deletions

View file

@ -0,0 +1,35 @@
'use strict';
var Curry = require("bs-platform/lib/js/curry.js");
var React = require("react");
var initialState = /* record */[/* count */0];
function reducer(state, action) {
if (action) {
return /* record */[/* count */state[/* count */0] - 1 | 0];
} else {
return /* record */[/* count */state[/* count */0] + 1 | 0];
}
}
function ReducerFromReactJSDocs(Props) {
var match = React.useReducer(reducer, initialState);
var dispatch = match[1];
return React.createElement("div", undefined, React.createElement("div", undefined, "Count: ", String(match[0][/* count */0])), React.createElement("div", undefined, React.createElement("button", {
onClick: (function (_event) {
return Curry._1(dispatch, /* Decrement */1);
})
}, "-"), React.createElement("button", {
onClick: (function (_event) {
return Curry._1(dispatch, /* Increment */0);
})
}, "+")));
}
var make = ReducerFromReactJSDocs;
exports.initialState = initialState;
exports.reducer = reducer;
exports.make = make;
/* react Not a pure module */

View file

@ -0,0 +1,39 @@
// This is the ReactJS documentation's useReducer example, directly ported over
// https://reactjs.org/docs/hooks-reference.html#usereducer
// Record and variant need explicit declarations.
type state = {count: int};
type action =
| Increment
| Decrement;
let initialState = {count: 0};
let reducer = (state, action) => {
switch (action) {
| Increment => {count: state.count + 1}
| Decrement => {count: state.count - 1}
};
};
[@react.component]
let make = () => {
let (state, dispatch) = React.useReducer(reducer, initialState);
// We can use a fragment here, but we don't, because we want to style the counter
<div>
<div>
{React.string("Count: ")}
{React.string(string_of_int(state.count))}
</div>
<div>
<button onClick={_event => dispatch(Decrement)}>
{React.string("-")}
</button>
<button onClick={_event => dispatch(Increment)}>
{React.string("+")}
</button>
</div>
</div>;
};