Skip to content

Commit 7cda616

Browse files
committed
Added Router and Flux snippets
1 parent 68338e8 commit 7cda616

File tree

5 files changed

+97
-27
lines changed

5 files changed

+97
-27
lines changed

README.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Atom React.js Snippets [![Build Status](https://travis-ci.org/webbushka/atom-react-snippets.svg?branch=master)](https://travis-ci.org/webbushka/atom-react-snippets)
22
====================================================================================================================================================================
33

4-
A React.js snippet library for [Atom](https://atom.io/). This library uses ES6 syntax, if you would prefer ES5 or Coffeescript snippets please use the [Atom React Package](https://atom.io/packages/react).
4+
An [Atom](https://atom.io/) snippet library for React, React Router and Flux. This library uses ES6 syntax, if you would prefer ES5 or Coffeescript snippets please use the [Atom React Package](https://atom.io/packages/react).
55

66
Install
77
-------
@@ -23,10 +23,6 @@ Features
2323
--------
2424

2525
- React Snippets
26-
27-
TODO
28-
----
29-
3026
- React Router Snippets
3127
- Flux Snippets
3228

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "react-snippets",
33
"version": "0.0.1",
4-
"description": "React (JSX) snippets for Atom",
5-
"main": "Gulpfile.js",
4+
"description": "Atom Snippets for React, React Router and Flux",
5+
"main": "./lib/react-snippets",
66
"scripts": {
77
"test": "gulp"
88
},
@@ -12,6 +12,8 @@
1212
},
1313
"keywords": [
1414
"react",
15+
"react router",
16+
"flux",
1517
"snippets",
1618
"es6"
1719
],

snippets/Flux.cson

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
".source.js":
3+
"Flux Action":
4+
prefix: "_fa"
5+
body: "'use strict';\nimport ${1:AppDispatcher} from '../dispatcher/${1:AppDispatcher}';\nimport ${2:constants} from '../constants/${2:constants}';\nimport ${3:utils} from '../utils/${3:utils};'\n\nexport default {\n\t${4}\n};"
6+
7+
"Flux: AppDispatcher":
8+
prefix: "_fd"
9+
body: "'use strict';\nimport { Dispatcher } from 'flux';\n\nlet AppDispatcher = new Dispatcher();\n\nAppDispatcher.handleAction = function(action) {\n\tthis.dispatch({\n\t\tsource: 'VIEW_ACTION',\n\t\taction: action\n\t});};\n\nexport default AppDispatcher;"
10+
11+
"Flux: Store":
12+
prefix: "_fs"
13+
body: "'use strict';\nimport ${1:AppDispatcher} from '../dispatcher/${1:AppDispatcher}';\nimport ${2:appConstants} from '../constants/${2:appConstants}';\nimport { EventEmitter } from 'event';\nimport assign from 'react/lib/Object.assign';\n\nlet _state = {};\n\nlet ${3:store} = assign({}, EventEmitter.prototype, {\n\t${4}\n});\n\nAppDispatcher.register((payload) => {\n\tlet { action } = payload;\n\n\t switch(action.actionType) {\n\n\t\tdefault:\n\t\t\treturn true;\n\t}\n});\n\nexport default ${3:store};"
14+
}

snippets/React (JSX).cson

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,78 @@
11
{
22
".source.js":
33
"React: componentDidMount() { ... }":
4-
prefix: "cdm"
4+
prefix: "_cdm"
55
body: "componentDidMount() {\n\t${1}\n},"
66

77
"React: componentDidUpdate(pp, ps) { ... }":
8-
prefix: "cdup"
8+
prefix: "_cdup"
99
body: "componentDidUpdate(prevProps, prevState) {\n\t${1}\n},"
1010

1111
"React: componentWillMount() { ... }":
12-
prefix: "cwm"
12+
prefix: "_cwm"
1313
body: "componentWillMount() {\n\t${1}\n},"
1414

1515
"React: componentWillReceiveProps(np) { ... }":
16-
prefix: "cwr"
16+
prefix: "_cwr"
1717
body: "componentWillReceiveProps(nextProps) {\n\t${1}\n},"
1818

1919
"React: componentWillUnmount() { ... }":
20-
prefix: "cwun"
20+
prefix: "_cwun"
2121
body: "componentWillUnmount() {\n\t${1}\n},"
2222

2323
"React: componentWillUpdate(np, ns) { ... }":
24-
prefix: "cwu"
24+
prefix: "_cwu"
2525
body: "componentWillUpdate(nextProps, nextState) {\n\t${1}\n},"
2626

2727
"React: cx({ ... })":
28-
prefix: "cx"
28+
prefix: "_cx"
2929
body: "cx({\n\t$1: $2\n});"
3030

3131
"React: forceUpdate(...)":
32-
prefix: "fup"
32+
prefix: "_fup"
3333
body: "forceUpdate(${1:callback});"
3434

3535
"React: getDefaultProps() { return {...} } ":
36-
prefix: "gdp"
36+
prefix: "_gdp"
3737
body: "getDefaultProps() {\n\treturn {\n\t\t${1}\n\t};\n},"
3838

3939
"React: getInitialState() { return {...} } ":
40-
prefix: "gis"
40+
prefix: "_gis"
4141
body: "getInitialState() {\n\treturn {\n\t\t${1}: ${2}\n\t};\n},"
4242

4343
"React: isMounted()":
44-
prefix: "ism"
44+
prefix: "_ism"
4545
body: "isMounted()"
4646

4747
"React: propTypes { ... }":
48-
prefix: "pt"
48+
prefix: "_pt"
4949
body: "propTypes: {\n\t${1}: React.PropTypes.${2:string}\n},"
5050

5151
"React: component skeleton":
52-
prefix: "rcc"
53-
body: "var React = require('react');\n\nvar ${1} = React.createClass({\n\n\trender() {\n\t\treturn (\n\t\t\t${0:<div />}\n\t\t);\n\t}\n\n});\n\nmodule.exports = ${1};"
52+
prefix: "_rcc"
53+
body: "import React from 'react';\n\nexport default React.createClass({\n\n\trender() {\n\t\treturn (\n\t\t\t${1:<div />}\n\t\t);\n\t}\n\n});"
5454

5555
"React: render() { return ... }":
56-
prefix: "ren"
56+
prefix: "_ren"
5757
body: "render() {\n\treturn (\n\t\t${1:<div />}\n\t);\n}"
5858

5959
"React: setState({ ... })":
60-
prefix: "sst"
60+
prefix: "_sst"
6161
body: "setState({\n\t${1}: ${2}\n});"
6262

6363
"React: shouldComponentUpdate(np, ns) { ... }":
64-
prefix: "scu"
64+
prefix: "_scu"
6565
body: "shouldComponentUpdate(nextProps, nextState) {\n\t${1}\n},"
6666

6767
"React: this.props.":
68-
prefix: "props"
68+
prefix: "_props"
6969
body: "this.props.${1}"
7070

7171
"React: this.state.":
72-
prefix: "state"
72+
prefix: "_state"
7373
body: "this.state.${1}"
7474

7575
"React: render(component, container, [callback])":
76-
prefix: "rrc"
76+
prefix: "_rrc"
7777
body: "React.render(${1:<$2 />}, ${3:document.body}${4:, ${5:callback}});"
7878
}

snippets/React Router.cson

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
".source.js":
3+
"Router: router skeleton":
4+
prefix: "_rr"
5+
body: "'use strict';\nimport React from 'react';\nimport Router from 'react-router';\nlet { Route, DefaultRoute, NotFoundRoute } = Router;\n\n// -- Import components\nimport ${1:App} from '${2}';\n\nexport default (\n\t<Route handler={${1:App}} path='/'>\n\t\t${3}\n\t</Route>\n);"
6+
7+
"Router: Router.run( ... )":
8+
prefix: "_run"
9+
body: "Router.run(${1:routes},${2: Router.HistoryLocaion}, (Handler) => {\n\tReact.render(<Handler />, document.${3:getElementById('${4:app}')});\n});"
10+
11+
"Router: Router.create({ ... })":
12+
prefix: "_rc"
13+
body: "var router = Router.create({\n\troutes: ${1:routes},\n\tlocation: Router.HistoryLocatio\n});\nrouter.run((Handler) => {\n\tReact.render(<Handler />, document.${3:getElementById('${4:app}')});\n});"
14+
15+
"Router: <Route />":
16+
prefix: "_rt"
17+
body: "<Route name='${1}' handler={${2}} ${3:path='${4}'} />"
18+
19+
"Router: Nested <Route></Route>":
20+
prefix: "_nrt"
21+
body: "<Route name='${1}' handler={${2}} ${3:path='${4}'}>\n\t${5}\n</Route>"
22+
23+
"Router: <Redirect />":
24+
prefix: "_rrt"
25+
body: "<Redirect from='${1}' to=${2} />"
26+
27+
"Router: <NotFoundRoute />":
28+
prefix: "_nfrt"
29+
body: "<NotFoundRoute handler={${1}}/>"
30+
31+
"Router: <DefaultRoute />":
32+
prefix: "_drt"
33+
body: "<DefaultRoute handler={${1}} />"
34+
35+
"Router: <Link />":
36+
prefix: "_ln"
37+
body: "<Link to={${1}} params={${2}} ${3:query={${4}}}/>"
38+
39+
"Router: willTransitionTo(t, p) { ... }":
40+
prefix: "_wtt"
41+
body: "willTransitionTo(transition, params) {\n\t${1}\n},"
42+
43+
"Router: willTransitionFrom(t, c) { ... }":
44+
prefix: "_wtf"
45+
body: "willTransitionFrom(transition, component) {\n\t${1}\n},"
46+
47+
"Router: transition.abort()":
48+
prefix: "_ta"
49+
body: "transition.abort();"
50+
51+
"Router: transition.retry()":
52+
prefix: "_tr"
53+
body: "transition.retry();"
54+
55+
"Router: transition.redirect()":
56+
prefix: "_trd"
57+
body: "transition.redirect(${1:to}, ${2:params}, ${3:query});"
58+
}

0 commit comments

Comments
 (0)