From e1148b3f570dd9de10db8aeb6c0eaf8576363388 Mon Sep 17 00:00:00 2001 From: Jeff Date: Thu, 2 Jun 2016 15:04:13 -0600 Subject: [PATCH] re-indentation also added editor config and eslint --- .editorconfig | 13 ++++++++ .eslintrc | 43 +++++++++++++++++++++++++ package.json | 3 ++ src/Container.js | 74 ++++++++++++++++++++++--------------------- src/components.js | 57 +++++++++++++++++++++++++++------ src/namespaceStore.js | 38 +++++++++++----------- 6 files changed, 164 insertions(+), 64 deletions(-) create mode 100644 .editorconfig create mode 100644 .eslintrc diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..9055741 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +# This file is for unifying the coding style for different editors and IDEs. +# More information at http://EditorConfig.org + +# No .editorconfig files above the root directory +root = true + +[*] +indent_style = space +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +indent_size = 2 diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..8ab3eaf --- /dev/null +++ b/.eslintrc @@ -0,0 +1,43 @@ +{ + "parserOptions": { + "ecmaVersion": 6, + "sourceType": "module", + "ecmaFeatures": { + "jsx": true, + "experimentalObjectRestSpread": true + } + }, + "env": { + "browser": true, + "jasmine": true, + "es6": true, + "node": true + }, + "rules": { + "react/jsx-uses-react": [1], + "camelcase": [0, {"properties": "always"}], + "indent": [2, 2], // 2 spaces indentation + "semi": [2, "always"], + "keyword-spacing": [2], + "space-before-function-paren": [2, "never"], + "space-before-blocks": [2, "always"], + "space-infix-ops": [2, {"int32Hint": false}], + "quotes": [1, "single", "avoid-escape"], + "max-len": [2, 100, 4], + "eqeqeq": [2, "allow-null"], + "strict": 0, + "no-nested-ternary": [2], + "no-underscore-dangle": 0, + "comma-style": [2], + "one-var": [2, "never"], + "brace-style": [2, "1tbs", { "allowSingleLine": true }], + "consistent-this": [0, "self"] + }, + "plugins": [ + "react" + ], + "globals": { + "jest": true, + "React": true + } +} diff --git a/package.json b/package.json index 988e722..4bd3603 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,8 @@ "babel-preset-react": "^6.5.0", "babel-preset-stage-2": "^6.5.0", "css-loader": "^0.23.1", + "eslint": "^2.11.1", + "eslint-plugin-react": "^5.1.1", "istanbul": "^1.0.0-alpha", "jsdom": "^9.1.0", "less": "^2.7.1", @@ -32,6 +34,7 @@ "deep-equal": "^1.0.1", "enzyme": "^2.3.0", "history": "^2.1.1", + "lodash": "^4.12.0", "myro": "^0.6.2", "react": "^15.0.2", "react-addons-test-utils": "^15.0.2", diff --git a/src/Container.js b/src/Container.js index 878c31d..62ab440 100644 --- a/src/Container.js +++ b/src/Container.js @@ -8,31 +8,31 @@ import style from './style.less' export default class Container extends Component { constructor(props) { - super(props) - this.state = { activeNamespace : null, routes: this.createRoutes() } - this.unlisten = null + super(props) + this.state = { activeNamespace : null, routes: this.createRoutes() } + this.unlisten = null } componentWillMount() { - const history = this.props.history? this.props.history : createHistory() - this.unlisten = history.listen((location) => { - this.setState({activeNamespace: location.hash.replace('#/', '')}) - }) + const history = this.props.history? this.props.history : createHistory() + this.unlisten = history.listen((location) => { + this.setState({activeNamespace: location.hash.replace('#/', '')}) + }) } componentWillUnmount() { - this.unlisten() + this.unlisten() } createRoutes() { - return myro({ - '#': { - name: 'index' - }, - '#/:namespace': { - name: 'namespace' - } - }) + return myro({ + '#': { + name: 'index' + }, + '#/:namespace': { + name: 'namespace' + } + }) } render() { @@ -40,29 +40,31 @@ export default class Container extends Component { const { routes, activeNamespace } = this.state const cards = namespaces[activeNamespace] const navCard = this.renderNavCard(routes, activeNamespace) - return
-

React Cards

- {cards - ?
- { [navCard, ...cards] } -
- :
- - {map(namespaces, (namespace, key) => ( - - - { key } - - - ))} - -
- } -
+ return ( +
+

React Cards

+ {cards + ?
+ { [navCard, ...cards] } +
+ :
+ + {map(namespaces, (namespace, key) => ( + + + { key } + + + ))} + +
+ } +
+ ) } renderNavCard(routes, ns) { return ( - +
home  /  diff --git a/src/components.js b/src/components.js index b3632d0..685a0d1 100644 --- a/src/components.js +++ b/src/components.js @@ -1,6 +1,10 @@ -import React from 'react' +import React ,{Component} from 'react' +import ReactDOM from 'react-dom' import showdown from 'showdown' import style from './style.less' +import Frame from 'react-frame-component' +import {iframeResizer} from 'iframe-resizer' +import iframeResizerContentWindow from 'raw!iframe-resizer/js/iframeResizer.contentWindow.min' const markdownToHtml = str => { const conv = new showdown.Converter() @@ -20,13 +24,48 @@ export const CardList = (props) => (
) -export const Card = (props) => ( -
- {props.title ? {props.title} : null} - {props.doc ? {props.doc} : null} - {props.children} -
+export const MarkdownCard = (props) => ( + {props.children} ) -export const MarkdownCard = (props) => - {props.children} +export class Card extends Component { + constructor(props) { + super(props) + } + + componentDidMount() { + if (!this.props.noframe) { + this.iframeNode = ReactDOM.findDOMNode(this.refs.iframe) + iframeResizer({checkOrigin:false},this.iframeNode) + } + } + + componentWillUnmount(){ + if (!this.props.noframe) { + this.iframeNode.iFrameResizer.close() + } + } + + render() { + const props = this.props; + const iframeContent = ` + + +
+ ` + return ( +
+ {props.title ? {props.title} : null} + {props.doc ? {props.doc} : null} + {props.noframe ? +
{props.children}
: + + {props.children} + + } +
+ ); + } +} diff --git a/src/namespaceStore.js b/src/namespaceStore.js index 75af9f1..2a93b85 100644 --- a/src/namespaceStore.js +++ b/src/namespaceStore.js @@ -1,25 +1,25 @@ // a simplified example for handling namespaces and their corresponding changes const namespaceStore = (initialState = {}) => ({ - namespaces: initialState, - listeners: [], - get(namespace) { - return namespace? this.namespaces[namespace] : this.namespaces - }, - set(namespace, cards) { - this.namespaces[namespace] = cards - this.notify() - }, - subscribe(f) { - this.listeners.push(f) - return () => { - this.listeners = this.listeners.filter(l => { - return l !== f - }) - } - }, - notify() { - this.listeners.map(l => l(this.namespaces)) + namespaces: initialState, + listeners: [], + get(namespace) { + return namespace? this.namespaces[namespace] : this.namespaces + }, + set(namespace, cards) { + this.namespaces[namespace] = cards + this.notify() + }, + subscribe(f) { + this.listeners.push(f) + return () => { + this.listeners = this.listeners.filter(l => { + return l !== f + }) } + }, + notify() { + this.listeners.map(l => l(this.namespaces)) + } }) export default namespaceStore