Skip to content

Commit

Permalink
Inital commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dlmr committed Oct 26, 2015
0 parents commit 40c14c4
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"stage": 0,
"loose": "all"
}
34 changes: 34 additions & 0 deletions .editiorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# EditorConfig helps developers define and maintain consistent coding styles between different editors and IDEs.
# Requires EditorConfig JetBrains Plugin - http://github.com/editorconfig/editorconfig-jetbrains

# Set this file as the topmost .editorconfig
# (multiple files can be used, and are applied starting from current document location)
root = true

[{package.json}]
indent_style = space
indent_size = 2

# Use bracketed regexp to target specific file types or file locations
[*.{js,json}]

# Use hard or soft tabs ["tab", "space"]
indent_style = space

# Size of a single indent [an integer, "tab"]
indent_size = tab

# Number of columns representing a tab character [an integer]
tab_width = 4

# Line breaks representation ["lf", "cr", "crlf"]
end_of_line = lf

# ["latin1", "utf-8", "utf-16be", "utf-16le"]
charset = utf-8

# Remove any whitespace characters preceding newline characters ["true", "false"]
trim_trailing_whitespace = true

# Ensure file ends with a newline when saving ["true", "false"]
insert_final_newline = true
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib
13 changes: 13 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "vgno",

"parser": "babel-eslint",

"env": {
"es6": true
},

"ecmaFeatures": {
"modules": true
}
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
*.log
.DS_Store
lib
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# react-server-status

Based on https://github.com/gaearon/react-side-effect

## Example

### React View
```javascript
import { Component } from 'react';

import ServerStatus from 'react-server-status';

export default class GenericView extends Component {
render() {
return (
<ServerStatus status={ 500 }>
<div>Some content</div>
</ServerStatus>
);
}
}
```

### Server
```javascript
//
import React from 'react';
import { renderToString } from 'react-dom/server';
import ServerStatus from 'server-status';
//
const page = renderToString(<App />);
this.status = ServerStatus.rewind() || 200;
/// …
```

## TODO
* [ ] Publish on NPM
35 changes: 35 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "react-server-status",
"version": "1.0.0",
"description": "A declarative way to set server status",
"main": "lib/index.js",
"scripts": {
"build": "babel src --out-dir lib",
"clean": "rimraf lib",
"test": "npm run lint",
"lint": "eslint .",
"check": "ncu",
"prepublish": "npm test && npm run clean && npm run build"
},
"repository": {
"type": "git",
"url": "[email protected]:vg/react-server-status.git"
},
"author": "Gustaf Dalemar",
"license": "UNLICENSED",
"dependencies": {
"react-side-effect": "~1.0.2"
},
"devDependencies": {
"babel": "~5.8.21",
"babel-eslint": "~4.1.1",
"eslint": "~1.6.0",
"eslint-config-vgno": "~3.0.0",
"eslint-plugin-react": "~3.5.1",
"npm-check-updates": "~2.3.0",
"rimraf": "~2.4.3"
},
"peerDependencies": {
"react": "^0.13.0"
}
}
21 changes: 21 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import withSideEffect from 'react-side-effect';

function reducePropsToState(propsList) {
const innermostProps = propsList[propsList.length - 1];
if (innermostProps) {
return innermostProps.status;
}
}

@withSideEffect(reducePropsToState, Function.prototype)
export default class ServerStatus extends React.Component {

static propTypes = {
status: React.PropTypes.number.isRequired
}

render() {
return React.Children.only(this.props.children);
}
}

0 comments on commit 40c14c4

Please sign in to comment.