Skip to content

Commit a802bdd

Browse files
authored
Merge pull request #6 from gigantz/ojr/res-component
[Updates] Res sub-components
2 parents 5991721 + 1e64985 commit a802bdd

31 files changed

+2891
-412
lines changed

.babelrc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
{
2-
"presets": [
3-
"@babel/preset-env"
4-
],
2+
"presets": ["@babel/preset-env"],
53
"plugins": ["@babel/plugin-transform-react-jsx"]
6-
}
4+
}

.eslintrc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"extends": ["airbnb", "prettier"],
3+
"plugins": ["prettier"],
4+
"rules": {
5+
"prettier/prettier": ["error"],
6+
"react/prop-types": "warn",
7+
"react/jsx-filename-extension": 0,
8+
"react/jsx-one-expression-per-line": 0,
9+
"react/jsx-props-no-spreading": 0,
10+
"react/require-default-props": 0,
11+
"react/forbid-prop-types": 0,
12+
"jsx-a11y/alt-text": 0,
13+
"import/prefer-default-export": 0,
14+
"import/no-extraneous-dependencies": 0
15+
}
16+
}

.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"printWidth": 100,
3+
"singleQuote": true
4+
}

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ It works with express.js framework to run Node.js server. Custom renderer we hav
1818
### Code Example
1919

2020
```js
21-
import React from "react";
22-
import { ReactXpress, App, Static, Router, Get, Post } from "../lib";
21+
import React from 'react';
22+
import { ReactXpress, App, Static, Router, Get, Post } from '../lib';
2323

2424
const HomePage = () => <h1>Welcome to home page</h1>;
2525
const AboutPage = () => <h1>About Company</h1>;
@@ -35,7 +35,7 @@ const ExpressApp = () => (
3535
<Get path="/about" content={<AboutPage />} />
3636
</Router>
3737
<Router path="/api">
38-
<Post path="/status" content={{ msg: "It is okay, bro" }} />
38+
<Post path="/status" content={{ msg: 'It is okay, bro' }} />
3939
</Router>
4040
</App>
4141
);

examples/advanced/components.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import React from "react";
1+
import React from 'react';
22

33
export const PostItem = ({ userId, id, title, body }) => (
4-
<div style={{ width: 500, margin: "0 auto" }}>
4+
<div style={{ width: 500, margin: '0 auto' }}>
55
<p>
66
UserID: {userId} / PostID: {id}
77
</p>

examples/advanced/handlers.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
import React from "react";
2-
import axios from "axios";
1+
import React from 'react';
2+
import axios from 'axios';
33

4-
import { PostItem } from "./components";
4+
import { PostItem } from './components';
55

66
export const postHandler = async (req, res, _, renderPage) => {
77
const { id } = req.params;
88
try {
9-
const { data } = await axios(
10-
`https://jsonplaceholder.typicode.com/posts/${id}`
11-
);
9+
const { data } = await axios(`https://jsonplaceholder.typicode.com/posts/${id}`);
1210
renderPage(() => <PostItem {...data} />);
1311
} catch (error) {
14-
res.status(500).end("Error");
12+
res.status(500).end('Error');
1513
}
1614
};
1715

1816
export const postsHandler = async (req, res, _, renderPage) => {
1917
try {
20-
const { data } = await axios("https://jsonplaceholder.typicode.com/posts");
18+
const { data } = await axios('https://jsonplaceholder.typicode.com/posts');
2119
renderPage(() => data.map((post) => <PostItem key={post.id} {...post} />));
2220
} catch (error) {
23-
res.status(500).end("Error");
21+
res.status(500).end('Error');
2422
}
2523
};

examples/advanced/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import React from "react";
2-
import { ReactXpress, App, Static, Router, Get } from "../../lib";
3-
import { postHandler, postsHandler } from "./handlers";
1+
import React from 'react';
2+
import { ReactXpress, App, Static, Router, Get } from '../../lib';
3+
import { postHandler, postsHandler } from './handlers';
44

55
const ExpressApp = () => (
66
<App port={8080}>
77
<Static publicPath="/public" />
88
<Router path="/">
99
<Get path="/posts" handler={postsHandler} />
1010
<Get path="/posts/:id" handler={postHandler} />
11-
<Get path="*" content="Not Found" status={404} />
11+
<Get path="*" text="Not Found" status={404} />
1212
</Router>
1313
</App>
1414
);

examples/basic/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import React from "react";
2-
import { ReactXpress, App, Static, Router, Get } from "../../lib";
1+
import React from 'react';
2+
import { ReactXpress, App, Static, Router, Get } from '../../lib';
33

44
const ExpressApp = () => (
55
<App port={8080}>
66
<Static publicPath="/public" />
77
<Router path="/">
88
<Get
9-
content={() => (
9+
render={() => (
1010
<div>
1111
<h1>Hello World</h1>
1212
</div>
1313
)}
1414
/>
15-
<Get path="*" content="Not Found" status={404} />
15+
<Get path="*" text="Not Found" status={404} />
1616
</Router>
1717
</App>
1818
);

lib/components/App.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import React from "react";
2-
import PropTypes from "prop-types";
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
33

44
export const App = ({ children, port }) => <app port={port}>{children}</app>;
55

lib/components/Res.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
const Render = ({ component }) => <param type="render" content={component} />;
5+
6+
Render.propTypes = {
7+
component: PropTypes.func,
8+
};
9+
10+
const Content = ({ json, contentType, text }) => {
11+
const ComponentsArray = [];
12+
13+
if (contentType)
14+
ComponentsArray.push(<param key="contentType" type="content-type" content={contentType} />);
15+
if (json) ComponentsArray.push(<param key="json" type="json" content={json} />);
16+
if (text) ComponentsArray.push(<param key="text" type="text" content={text} />);
17+
18+
return ComponentsArray;
19+
};
20+
21+
Content.propTypes = {
22+
json: PropTypes.any,
23+
contentType: PropTypes.string,
24+
text: PropTypes.string,
25+
};
26+
27+
const Status = ({ statusCode }) => <param type="status" content={statusCode} />;
28+
29+
Status.propTypes = {
30+
statusCode: PropTypes.number,
31+
};
32+
33+
const Redirect = ({ path, statusCode }) => <param type="redirect" content={{ path, statusCode }} />;
34+
35+
Redirect.propTypes = {
36+
path: PropTypes.string.isRequired,
37+
statusCode: PropTypes.number,
38+
};
39+
40+
const SendFile = ({ path, options, onError = () => {} }) => (
41+
<param type="send-file" content={{ path, options, onError }} />
42+
);
43+
44+
SendFile.propTypes = {
45+
path: PropTypes.string.isRequired,
46+
options: PropTypes.object,
47+
onError: PropTypes.func,
48+
};
49+
50+
export const Res = {
51+
Render,
52+
Content,
53+
Status,
54+
Redirect,
55+
SendFile,
56+
};

0 commit comments

Comments
 (0)