-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
CR-JON
committed
Oct 2, 2018
0 parents
commit 459f96c
Showing
28 changed files
with
1,408 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules/* | ||
src/interfaces/* | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = { | ||
extends: 'loris/es5', | ||
root: true, | ||
env: { | ||
node: true, | ||
mocha: true | ||
}, | ||
rules: { | ||
strict: 'off', | ||
'no-unused-vars': ['error', {args: 'none'}], | ||
'no-console': ['warn'] | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/bash | ||
# | ||
# * Check changed js files using eslint. | ||
# | ||
|
||
PATCH_FILE="working-tree.patch" | ||
NPM_BIN="./node_modules/.bin" | ||
|
||
function cleanup { | ||
exit_code=$? | ||
if [ -f "$PATCH_FILE" ]; then | ||
git apply "$PATCH_FILE" 2> /dev/null | ||
rm "$PATCH_FILE" | ||
fi | ||
exit $exit_code | ||
} | ||
|
||
trap cleanup EXIT SIGINT SIGHUP | ||
|
||
# Cancel any changes to the working tree that are not going to be committed | ||
git diff > "$PATCH_FILE" | ||
git checkout -- . | ||
|
||
git_cached_files=$(git diff --cached --name-only --diff-filter=ACMR | grep "\.js$") | ||
if [ "$git_cached_files" ]; then | ||
echo "Start linting..." | ||
|
||
$NPM_BIN/eslint $git_cached_files --quiet || exit 1 | ||
|
||
echo "There are no errors in codestyle." | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
language: node_js | ||
node_js: | ||
- "6" | ||
- "5" | ||
- "4" | ||
script: | ||
- npm run lint | ||
- npm run test-coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2016 Andrey Morozov | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
With the release of the new version [React](https://reactjs.org/blog/2017/09/26/react-v16.0.html#better-server-side-rendering) and Node.js the performance issue has ceased to be so acute. Use last versions of React and Node.js for better performance. | ||
====== | ||
|
||
# [React] Server render [![Build Status](https://travis-ci.org/alt-j/fast-react-render.svg?branch=master)](https://travis-ci.org/alt-j/fast-react-render) [![Coverage Status](https://coveralls.io/repos/github/alt-j/fast-react-render/badge.svg?branch=master)](https://coveralls.io/github/alt-j/fast-react-render?branch=master) | ||
|
||
The module for rendering react-element in the server **3 times as fast** (see [benchmarks](https://github.com/alt-j/react-server-benchmark)) as [traditional react rendering](https://facebook.github.io/react/docs/environments.html) (in production mode). | ||
|
||
## Quick start | ||
|
||
All you need to use it, is only: | ||
|
||
1) install package | ||
|
||
```sh | ||
npm install fast-react-render | ||
``` | ||
|
||
2) replace you render to: | ||
|
||
```js | ||
var ReactRender = require('fast-react-render'); | ||
|
||
var element = React.createElement(Component, {property: 'value'}); | ||
console.log(ReactRender.elementToString(element, {context: {}})); | ||
``` | ||
|
||
## Cache | ||
|
||
React server rendering support cache for component. | ||
|
||
First of all, you must choose cache system. It can be any system, which implement ICache interface ([interface](src/interfaces/i-cache.js)). | ||
For caching, component must implement ICacheableComponent interface ([interface](src/interfaces/i-cacheable-component.js)). | ||
|
||
Example with using LRU cache: [render with LRU cache](examples/cache.js) (install `lru-cache` package first). | ||
|
||
## What's next | ||
|
||
If you need more performance, you can try use [fast-react-server](https://github.com/alt-j/fast-react-server) - is high speed mock for react, which provide rendering **11 times as fast** as traditional, but require more configuration for build system. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* eslint-disable no-console */ | ||
|
||
// You must install all dependencies (react, lru-cache). | ||
var React = require('react'); | ||
var ReactRender = require('../src/index'); | ||
|
||
var LRU = require('lru-cache'); | ||
var cache = LRU({ | ||
max: 500, | ||
maxAge: 60 * 60 | ||
}); | ||
|
||
var Component = React.createClass({ | ||
displayName: 'Component', | ||
|
||
getDefaultProps: function () { | ||
return { | ||
content: 'Some <b>bold</b> text' | ||
}; | ||
}, | ||
|
||
getCacheKey: function () { | ||
return this.props.content; | ||
}, | ||
|
||
render: function () { | ||
return React.createElement('div', { | ||
className: 'text', | ||
dangerouslySetInnerHTML: {__html: this.props.content} | ||
}); | ||
} | ||
}); | ||
|
||
console.log( | ||
ReactRender.elementToString( | ||
React.createElement(Component), | ||
{cache: cache} | ||
) | ||
); | ||
|
||
// Render from cache | ||
console.log( | ||
ReactRender.elementToString( | ||
React.createElement(Component, {content: 'Some <b>bold</b> text'}), | ||
{cache: cache} | ||
) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"name": "fast-react-render", | ||
"version": "1.2.3", | ||
"description": "Fast tool for render react to string", | ||
"main": "src/index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/alt-j/fast-react-render.git" | ||
}, | ||
"keywords": [ | ||
"react", | ||
"render", | ||
"server", | ||
"performance", | ||
"optimization", | ||
"speed", | ||
"html" | ||
], | ||
"author": "Andrey Morozov <[email protected]>", | ||
"license": "MIT", | ||
"publishConfig": { | ||
"registry": "https://registry.npmjs.org/" | ||
}, | ||
"scripts": { | ||
"test": "npm run lint && npm run test-cov", | ||
"test-cov": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- --recursive --check-leaks", | ||
"test-coveralls": "./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage", | ||
"lint": "./node_modules/.bin/eslint . --quiet", | ||
"benchmark": "node ./tools/benchmark" | ||
}, | ||
"devDependencies": { | ||
"chai": "3.5.0", | ||
"coveralls": "2.11.12", | ||
"eslint": "2.5.3", | ||
"eslint-config-loris": "5.1.0", | ||
"git-hooks": "1.1.0", | ||
"istanbul": "0.4.5", | ||
"lru-cache": "4.0.1", | ||
"mocha": "3.0.2", | ||
"mocha-lcov-reporter": "1.2.0", | ||
"react": "15.3.1", | ||
"fast-react-benchmark": "1.3.0" | ||
}, | ||
"dependencies": { | ||
"uuid": "2.0.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = [ | ||
'string', | ||
'boolean', | ||
'number' | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module.exports = [ | ||
'getDefaultProps', | ||
'getInitialState', | ||
|
||
'constructor', | ||
'componentWillMount', | ||
'render', | ||
'componentDidMount', | ||
|
||
'componentWillReceiveProps', | ||
'shouldComponentUpdate', | ||
'componentWillUpdate', | ||
'componentDidUpdate', | ||
|
||
'componentWillUnmount', | ||
|
||
'isMounted', | ||
'setState', | ||
'replaceState', | ||
'forceUpdate' | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module.exports = [ | ||
'area', | ||
'base', | ||
'br', | ||
'col', | ||
'command', | ||
'embed', | ||
'hr', | ||
'img', | ||
'input', | ||
'keygen', | ||
'link', | ||
'meta', | ||
'param', | ||
'source', | ||
'track', | ||
'wbr' | ||
]; |
Oops, something went wrong.