diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..018235f --- /dev/null +++ b/.babelrc @@ -0,0 +1,4 @@ +{ + "stage": 0, + "loose": "all" +} diff --git a/.editiorconfig b/.editiorconfig new file mode 100644 index 0000000..c380e58 --- /dev/null +++ b/.editiorconfig @@ -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 diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..a65b417 --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +lib diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..811e6a8 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,13 @@ +{ + "extends": "vgno", + + "parser": "babel-eslint", + + "env": { + "es6": true + }, + + "ecmaFeatures": { + "modules": true + } +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..392b220 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +node_modules +*.log +.DS_Store +lib diff --git a/README.md b/README.md new file mode 100644 index 0000000..65a2637 --- /dev/null +++ b/README.md @@ -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 ( + +
Some content
+
+ ); + } +} +``` + +### Server +```javascript +// … +import React from 'react'; +import { renderToString } from 'react-dom/server'; +import ServerStatus from 'server-status'; +// … +const page = renderToString(); +this.status = ServerStatus.rewind() || 200; +/// … +``` + +## TODO +* [ ] Publish on NPM diff --git a/package.json b/package.json new file mode 100644 index 0000000..0cd3832 --- /dev/null +++ b/package.json @@ -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": "git@github.schibsted.io: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" + } +} diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..7d4d2cc --- /dev/null +++ b/src/index.js @@ -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); + } +}