Skip to content

Commit e1148b3

Browse files
committed
re-indentation also added editor config and eslint
1 parent 151516f commit e1148b3

File tree

6 files changed

+164
-64
lines changed

6 files changed

+164
-64
lines changed

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# This file is for unifying the coding style for different editors and IDEs.
2+
# More information at http://EditorConfig.org
3+
4+
# No .editorconfig files above the root directory
5+
root = true
6+
7+
[*]
8+
indent_style = space
9+
end_of_line = lf
10+
charset = utf-8
11+
trim_trailing_whitespace = true
12+
insert_final_newline = true
13+
indent_size = 2

.eslintrc

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"parserOptions": {
3+
"ecmaVersion": 6,
4+
"sourceType": "module",
5+
"ecmaFeatures": {
6+
"jsx": true,
7+
"experimentalObjectRestSpread": true
8+
}
9+
},
10+
"env": {
11+
"browser": true,
12+
"jasmine": true,
13+
"es6": true,
14+
"node": true
15+
},
16+
"rules": {
17+
"react/jsx-uses-react": [1],
18+
"camelcase": [0, {"properties": "always"}],
19+
"indent": [2, 2], // 2 spaces indentation
20+
"semi": [2, "always"],
21+
"keyword-spacing": [2],
22+
"space-before-function-paren": [2, "never"],
23+
"space-before-blocks": [2, "always"],
24+
"space-infix-ops": [2, {"int32Hint": false}],
25+
"quotes": [1, "single", "avoid-escape"],
26+
"max-len": [2, 100, 4],
27+
"eqeqeq": [2, "allow-null"],
28+
"strict": 0,
29+
"no-nested-ternary": [2],
30+
"no-underscore-dangle": 0,
31+
"comma-style": [2],
32+
"one-var": [2, "never"],
33+
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
34+
"consistent-this": [0, "self"]
35+
},
36+
"plugins": [
37+
"react"
38+
],
39+
"globals": {
40+
"jest": true,
41+
"React": true
42+
}
43+
}

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
"babel-preset-react": "^6.5.0",
1717
"babel-preset-stage-2": "^6.5.0",
1818
"css-loader": "^0.23.1",
19+
"eslint": "^2.11.1",
20+
"eslint-plugin-react": "^5.1.1",
1921
"istanbul": "^1.0.0-alpha",
2022
"jsdom": "^9.1.0",
2123
"less": "^2.7.1",
@@ -32,6 +34,7 @@
3234
"deep-equal": "^1.0.1",
3335
"enzyme": "^2.3.0",
3436
"history": "^2.1.1",
37+
"lodash": "^4.12.0",
3538
"myro": "^0.6.2",
3639
"react": "^15.0.2",
3740
"react-addons-test-utils": "^15.0.2",

src/Container.js

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,61 +8,63 @@ import style from './style.less'
88
export default class Container extends Component {
99

1010
constructor(props) {
11-
super(props)
12-
this.state = { activeNamespace : null, routes: this.createRoutes() }
13-
this.unlisten = null
11+
super(props)
12+
this.state = { activeNamespace : null, routes: this.createRoutes() }
13+
this.unlisten = null
1414
}
1515

1616
componentWillMount() {
17-
const history = this.props.history? this.props.history : createHistory()
18-
this.unlisten = history.listen((location) => {
19-
this.setState({activeNamespace: location.hash.replace('#/', '')})
20-
})
17+
const history = this.props.history? this.props.history : createHistory()
18+
this.unlisten = history.listen((location) => {
19+
this.setState({activeNamespace: location.hash.replace('#/', '')})
20+
})
2121
}
2222

2323
componentWillUnmount() {
24-
this.unlisten()
24+
this.unlisten()
2525
}
2626

2727
createRoutes() {
28-
return myro({
29-
'#': {
30-
name: 'index'
31-
},
32-
'#/:namespace': {
33-
name: 'namespace'
34-
}
35-
})
28+
return myro({
29+
'#': {
30+
name: 'index'
31+
},
32+
'#/:namespace': {
33+
name: 'namespace'
34+
}
35+
})
3636
}
3737

3838
render() {
3939
const { namespaces } = this.props
4040
const { routes, activeNamespace } = this.state
4141
const cards = namespaces[activeNamespace]
4242
const navCard = this.renderNavCard(routes, activeNamespace)
43-
return <div className={style.container}>
44-
<h1>React Cards</h1>
45-
{cards
46-
? <div className='react-cards-namespace-cards'>
47-
<CardList namespace={ activeNamespace }>{ [navCard, ...cards] }</CardList>
48-
</div>
49-
: <div className="react-cards-menu">
50-
<CardList>
51-
{map(namespaces, (namespace, key) => (
52-
<Card key={key}>
53-
<a className={style.nav} href={ routes.namespace({ namespace: key }) }>
54-
{ key }
55-
</a>
56-
</Card>
57-
))}
58-
</CardList>
59-
</div>
60-
}
61-
</div>
43+
return (
44+
<div className={style.container}>
45+
<h1>React Cards</h1>
46+
{cards
47+
? <div className='react-cards-namespace-cards'>
48+
<CardList namespace={ activeNamespace }>{ [navCard, ...cards] }</CardList>
49+
</div>
50+
: <div className="react-cards-menu">
51+
<CardList>
52+
{map(namespaces, (namespace, key) => (
53+
<Card key={key} noframe>
54+
<a className={style.nav} href={ routes.namespace({ namespace: key }) }>
55+
{ key }
56+
</a>
57+
</Card>
58+
))}
59+
</CardList>
60+
</div>
61+
}
62+
</div>
63+
)
6264
}
6365
renderNavCard(routes, ns) {
6466
return (
65-
<Card key='navcard'>
67+
<Card key='navcard' noframe>
6668
<div className={style.navCrumbs}>
6769
<a href={ routes.index() }>home</a>
6870
&nbsp;/&nbsp;

src/components.js

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
import React from 'react'
1+
import React ,{Component} from 'react'
2+
import ReactDOM from 'react-dom'
23
import showdown from 'showdown'
34
import style from './style.less'
5+
import Frame from 'react-frame-component'
6+
import {iframeResizer} from 'iframe-resizer'
7+
import iframeResizerContentWindow from 'raw!iframe-resizer/js/iframeResizer.contentWindow.min'
48

59
const markdownToHtml = str => {
610
const conv = new showdown.Converter()
@@ -20,13 +24,48 @@ export const CardList = (props) => (
2024
</div>
2125
)
2226

23-
export const Card = (props) => (
24-
<div className={"reactcards-card "+style.card}>
25-
{props.title ? <CardHeader>{props.title}</CardHeader> : null}
26-
{props.doc ? <Markdown className={style.markdownDoc}>{props.doc}</Markdown> : null}
27-
{props.children}
28-
</div>
27+
export const MarkdownCard = (props) => (
28+
<Card noframe><Markdown>{props.children}</Markdown></Card>
2929
)
3030

31-
export const MarkdownCard = (props) =>
32-
<Card><Markdown>{props.children}</Markdown></Card>
31+
export class Card extends Component {
32+
constructor(props) {
33+
super(props)
34+
}
35+
36+
componentDidMount() {
37+
if (!this.props.noframe) {
38+
this.iframeNode = ReactDOM.findDOMNode(this.refs.iframe)
39+
iframeResizer({checkOrigin:false},this.iframeNode)
40+
}
41+
}
42+
43+
componentWillUnmount(){
44+
if (!this.props.noframe) {
45+
this.iframeNode.iFrameResizer.close()
46+
}
47+
}
48+
49+
render() {
50+
const props = this.props;
51+
const iframeContent = `<!DOCTYPE html>
52+
<html>
53+
<head><script>${iframeResizerContentWindow}</script></head>
54+
<body><div id="content"></div></body>
55+
</html>`
56+
return (
57+
<div className={"reactcards-card "+style.card}>
58+
{props.title ? <CardHeader>{props.title}</CardHeader> : null}
59+
{props.doc ? <Markdown className={style.markdownDoc}>{props.doc}</Markdown> : null}
60+
{props.noframe ?
61+
<div>{props.children}</div> :
62+
<Frame ref="iframe"
63+
initialContent={iframeContent}
64+
mountTarget="#content">
65+
{props.children}
66+
</Frame>
67+
}
68+
</div>
69+
);
70+
}
71+
}

src/namespaceStore.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
// a simplified example for handling namespaces and their corresponding changes
22
const namespaceStore = (initialState = {}) => ({
3-
namespaces: initialState,
4-
listeners: [],
5-
get(namespace) {
6-
return namespace? this.namespaces[namespace] : this.namespaces
7-
},
8-
set(namespace, cards) {
9-
this.namespaces[namespace] = cards
10-
this.notify()
11-
},
12-
subscribe(f) {
13-
this.listeners.push(f)
14-
return () => {
15-
this.listeners = this.listeners.filter(l => {
16-
return l !== f
17-
})
18-
}
19-
},
20-
notify() {
21-
this.listeners.map(l => l(this.namespaces))
3+
namespaces: initialState,
4+
listeners: [],
5+
get(namespace) {
6+
return namespace? this.namespaces[namespace] : this.namespaces
7+
},
8+
set(namespace, cards) {
9+
this.namespaces[namespace] = cards
10+
this.notify()
11+
},
12+
subscribe(f) {
13+
this.listeners.push(f)
14+
return () => {
15+
this.listeners = this.listeners.filter(l => {
16+
return l !== f
17+
})
2218
}
19+
},
20+
notify() {
21+
this.listeners.map(l => l(this.namespaces))
22+
}
2323
})
2424

2525
export default namespaceStore

0 commit comments

Comments
 (0)