Permalink
Browse files

Reason everywhere, bye `@phenomic/reason` (#1206)

* Reason everywhere

* Fixed reason example

* Fix reason example
  • Loading branch information...
MoOx committed Nov 28, 2017
1 parent d16e524 commit 4c9fb4a738ee1c26035e53d15ba8878298b9b26c
@@ -3,8 +3,8 @@ import { Router, Route, browserHistory } from "react-router";
import { createApp } from "@phenomic/preset-react-app/lib/client";
const {
wrapReComponent
} = require("@phenomic/reason/lib/js/src/phenomicRootComponent");
createContainer
} = require("@phenomic/preset-react-app/lib/js/src/phenomicPresetReactApp.js");
const Home = require("./lib/js/components/home");
const Post = require("./lib/js/components/post");
@@ -13,11 +13,11 @@ export default createApp(() => (
<Router history={browserHistory}>
<Route
path="/"
component={wrapReComponent(Home.jsComponent, Home.queries)}
component={createContainer(Home.jsComponent, Home.queries)}
/>
<Route
path="blog/*"
component={wrapReComponent(Post.jsComponent, Post.queries)}
component={createContainer(Post.jsComponent, Post.queries)}
/>
</Router>
));
@@ -1,13 +1,18 @@
{
"name": "@phenomic/example-reason-react-app",
"version": "1.0.0-alpha.0",
"refmt": 3,
"reason": {
"react-jsx": 2
},
"sources": [
{
"dir": "components"
}
],
"reason": {
"react-jsx": 2
},
"bs-dependencies": ["reason-react", "@phenomic/reason"]
"bs-dependencies": [
"reason-react",
"@phenomic/preset-react-app",
"@phenomic/plugin-renderer-react",
"@phenomic/api-client"
]
}
@@ -1,30 +1,30 @@
let component = ReasonReact.statelessComponent "Home";
let component = ReasonReact.statelessComponent("Home");
type post = {
id: string,
title: string
};
let make ::posts => {
let make = (~posts) => {
...component,
render: fun _self =>
render: (_self) =>
<div>
<h1> (ReasonReact.stringToElement "Home") </h1>
<h1> (ReasonReact.stringToElement("Home")) </h1>
(
switch (posts: PhenomicContent.edge (list post)) {
switch (posts: PhenomicPresetReactApp.edge(list(post))) {
| Inactive
| Loading => ReasonReact.stringToElement "Loading ..."
| Errored => ReasonReact.stringToElement "An error occured"
| Idle posts =>
| Loading => ReasonReact.stringToElement("Loading ...")
| Errored => ReasonReact.stringToElement("An error occured")
| Idle(posts) =>
<ul>
(
posts
|> List.map (
fun item =>
|> List.map(
(item) =>
<li key=item.id>
<Link href=("blog/" ^ item.id ^ "/")>
(ReasonReact.stringToElement item.title)
</Link>
<PhenomicPresetReactApp.Link href=("blog/" ++ (item.id ++ "/"))>
(ReasonReact.stringToElement(item.title))
</PhenomicPresetReactApp.Link>
</li>
)
|> Array.of_list
@@ -36,25 +36,25 @@ let make ::posts => {
</div>
};
let jsPostToReason jsProps => {id: jsProps##id, title: jsProps##title};
let jsPostToReason = (jsProps) => {id: jsProps##id, title: jsProps##title};
let jsComponent =
ReasonReact.wrapReasonForJs
::component
(
fun jsProps =>
make
posts::(
PhenomicContent.jsEdgeToReason
jsProps##posts
(fun posts => posts##list |> Array.map jsPostToReason |> Array.to_list)
ReasonReact.wrapReasonForJs(
~component,
(jsProps) =>
make(
~posts=
PhenomicPresetReactApp.jsEdgeToReason(
jsProps##posts,
(posts) => posts##list |> Array.map(jsPostToReason) |> Array.to_list
)
);
)
);
let queries _ => {
let queries = (_) => {
let posts =
PhenomicContent.query (
List {path: "posts", by: Some "default", value: None, order: None, limit: None}
PhenomicPresetReactApp.query(
List({path: "posts", by: Some("default"), value: None, order: None, limit: None})
);
{"posts": posts}
};
@@ -1,38 +1,39 @@
let component = ReasonReact.statelessComponent "Home";
let component = ReasonReact.statelessComponent("Home");
type post = {
id: string,
title: string,
body: PhenomicContent.jsBody
body: PhenomicPresetReactApp.BodyRenderer.jsBody
};
let make ::post => {
let make = (~post) => {
...component,
render: fun _self =>
render: (_self) =>
<div>
(
switch (post: PhenomicContent.edge post) {
switch (post: PhenomicPresetReactApp.edge(post)) {
| Inactive
| Loading => ReasonReact.stringToElement "Loading ..."
| Errored => ReasonReact.stringToElement "An error occured"
| Idle post =>
| Loading => ReasonReact.stringToElement("Loading ...")
| Errored => ReasonReact.stringToElement("An error occured")
| Idle(post) =>
<div>
<h1> (ReasonReact.stringToElement post.title) </h1>
<BodyRenderer body=post.body />
<h1> (ReasonReact.stringToElement(post.title)) </h1>
<PhenomicPresetReactApp.BodyRenderer body=post.body />
</div>
}
)
</div>
};
let jsPostToReason jsProps => {id: jsProps##id, title: jsProps##title, body: jsProps##body};
let jsPostToReason = (jsProps) => {id: jsProps##id, title: jsProps##title, body: jsProps##body};
let jsComponent =
ReasonReact.wrapReasonForJs
::component
(fun jsProps => make post::(PhenomicContent.jsEdgeToReason jsProps##post jsPostToReason));
ReasonReact.wrapReasonForJs(
~component,
(jsProps) => make(~post=PhenomicPresetReactApp.jsEdgeToReason(jsProps##post, jsPostToReason))
);
let queries props => {
let post = PhenomicContent.query (Item {path: "posts", id: props##params##splat});
let queries = (props) => {
let post = PhenomicPresetReactApp.query(Item({path: "posts", id: props##params##splat}));
{"post": post}
};
@@ -5,8 +5,7 @@
"@phenomic/cli": "^1.0.0-alpha.13",
"@phenomic/core": "^1.0.0-alpha.13",
"@phenomic/preset-react-app": "^1.0.0-alpha.13",
"@phenomic/reason": "^1.0.0-alpha.13",
"bs-platform": "^2.0.0",
"bs-platform": "^2.1.0",
"npm-run-all": "^4.0.2",
"react": "^16.0.0",
"react-dom": "^16.0.0",
View
@@ -1,5 +1,5 @@
{
"lerna": "2.0.0",
"lerna": "2.5.1",
"version": "1.0.0-alpha.13",
"npmClient": "yarn",
"useWorkspaces": true,
View
@@ -27,7 +27,7 @@
"globby": "^6.1.0",
"husky": "^0.13.3",
"jest": "^21.0.0",
"lerna": "^2.0.0",
"lerna": "^2.5.1",
"lint-staged": "^3.4.0",
"npm-run-all": "^3.0.0",
"prettier": "^1.8.0",
@@ -45,10 +45,10 @@
"posttranspile": "lerna run prepare",
"watch":
"lerna exec --parallel -- babel -w src --optional runtime --out-dir lib --ignore \"__tests__\"",
"prepare": "npm run -s clean && npm run -s transpile",
"prerelease": "npm run prepare",
"prepare": "yarn clean && yarn transpile",
"prerelease": "yarn prepare",
"release": "lerna publish",
"format": "npm run -s format:most && npm run -s format:re",
"format": "yarn format:most && yarn format:re",
"format:most": "prettier --write \"**/*.{js,json,css,md}\"",
"format:re":
"find . -name \"*.re\" | grep -v \"node_modules\" | xargs refmt --in-place",
@@ -60,13 +60,13 @@
"tests": "jest --runInBand --coverage packages",
"examples:build": "babel-node scripts/examples.js",
"examples:tests": "jest --bail examples",
"examples": "npm run -s examples:build && npm run -s examples:tests",
"examples": "yarn examples:build && yarn examples:tests",
"docs:start": "cd docs && npm start",
"docs:test": "cd docs && npm test && jest docs",
"docs:deploy": "cd docs && npm run deploy",
"test": "npm run -s lint && npm run -s tests",
"test-without-lint": "npm run -s tests",
"posttest": "npm run -s examples && npm run -s docs:test"
"docs:deploy": "cd docs && yarn deploy",
"test": "yarn lint && yarn tests",
"test-without-lint": "yarn tests",
"posttest": "yarn examples && yarn docs:test"
},
"lint-staged": {
@@ -0,0 +1,12 @@
{
"name": "@phenomic/api-client",
"refmt": 3,
"reason": {
"react-jsx": 2
},
"sources": [
{
"dir": "src"
}
]
}
@@ -25,5 +25,14 @@
"files": ["lib"],
"dependencies": {
"debug": "^2.6.0"
},
"devDependencies": {
"bs-platform": "^2.1.0"
},
"scripts": {
"reason:cleanup": "bsb -clean-world",
"reason:compile": "bsb -make-world",
"prepare": "npm run reason:compile",
"dev": "npm run reason:compile -- -w"
}
}
@@ -1,46 +1,6 @@
[@bs.module "@phenomic/api-client/lib/query"] external internalQuery : Js.t({..}) => Js.t({..}) =
"query";
type reasonChildren = list(reasonChild)
and reasonChild =
| String(string)
| Element(string, Js.t({.}), reasonChildren)
| Empty;
type jsBody = {. "t": string, "p": Js.t({.}), "c": Js.Null_undefined.t(array(jsBody))};
let rec jsTreeToReason = (jsChild: jsBody) =>
switch [%bs.raw {| Object.prototype.toString.call(jsChild) |}] {
| "[object String]" => String(Js.String.make(jsChild))
| "[object Object]" =>
let tag = Js.String.make(jsChild##t);
let props = jsChild##p;
let children =
switch (Js.Null_undefined.to_opt(jsChild##c)) {
| Some(c) => List.map(jsTreeToReason, Array.to_list(c))
| None => []
};
Element(tag, props, children)
| _ => Empty
};
type edge('a) =
| Idle('a)
| Loading
| Inactive
| Errored;
type jsEdge('a) = {. "status": string, "node": 'a};
let jsEdgeToReason = (jsEdge, convertNode) =>
switch jsEdge##status {
| "loading" => Loading
| "errored" => Errored
| "idle" => Idle(convertNode(jsEdge##node))
| "inactive"
| _ => Inactive
};
type queryConfigItem = {
path: string,
id: string
@@ -1,14 +1,13 @@
{
"name": "@phenomic/reason",
"version": "1.0.0-alpha.12",
"name": "@phenomic/plugin-renderer-react",
"refmt": 3,
"reason": {
"react-jsx": 2
},
"sources": [
{
"dir": "src"
}
],
"reason": {
"react-jsx": 2
},
"refmt": 3,
"bs-dependencies": ["reason-react"]
}
@@ -44,9 +44,16 @@
},
"devDependencies": {
"@phenomic/core": "^1.0.0-alpha.13",
"bs-platform": "^2.1.0",
"jsx-test-helpers": "^3.0.0",
"react": "^16.0.0",
"react-dom": "^16.0.0",
"react-router": "^3.2.0"
},
"scripts": {
"reason:cleanup": "bsb -clean-world",
"reason:compile": "bsb -make-world",
"prepare": "npm run reason:compile",
"dev": "npm run reason:compile -- -w"
}
}
Oops, something went wrong.

1 comment on commit 4c9fb4a

@bloodyowl

This comment has been minimized.

Contributor

bloodyowl commented on 4c9fb4a Nov 28, 2017

👍 great things to come

Please sign in to comment.