Skip to content

Commit 12f62ed

Browse files
committed
Add project
1 parent 33e938e commit 12f62ed

File tree

8 files changed

+207
-1
lines changed

8 files changed

+207
-1
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["es2015-loose", "stage-0", "react"]
3+
}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.log
2+
lib
3+
node_modules

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.log
2+
src

README.md

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,57 @@
1-
# redux-devtools-dispatch
1+
# Redux DevTools Dispatch
22
Dispatch your actions manually to test if your app react well.
3+
4+
### Installation
5+
6+
`npm install --save-dev redux-devtools-dispatch`
7+
8+
### Usage
9+
10+
You can declare your Dispatcher the same way you declare a Monitor in your Dev Tools.
11+
12+
```js
13+
import React from 'react';
14+
import { createDevTools } from 'redux-devtools';
15+
import Dispatcher from 'redux-devtools-dispatch';
16+
17+
export default createDevTools(
18+
<Dispatcher />
19+
);
20+
```
21+
22+
You can also use `<MultipleMonitors>`, a hacky class to use multiple monitors into the `<DockMonitor>`:
23+
24+
```js
25+
import React from 'react';
26+
27+
import { createDevTools } from 'redux-devtools';
28+
import LogMonitor from 'redux-devtools-log-monitor';
29+
import DockMonitor from 'redux-devtools-dock-monitor';
30+
import Dispatcher from 'redux-devtools-dispatch';
31+
import MultipleMonitors from 'redux-devtools-dispatch/lib/MultipleMonitors';
32+
33+
export default createDevTools(
34+
<DockMonitor toggleVisibilityKey="ctrl-h" changePositionKey="ctrl-q" defaultIsVisible={false}>
35+
<MultipleMonitors>
36+
<LogMonitor />
37+
<Dispatcher />
38+
</MultipleMonitors>
39+
</DockMonitor>
40+
);
41+
```
42+
43+
Then, just write an JSON action in the field, click on Dispatch, and that's all!
44+
45+
### Props
46+
47+
Name | Description
48+
------------- | -------------
49+
`initEmpty` | When `true`, the dispatcher is empty. By default, set to `false`, the dispatcher contains : `{ "type": "" }`.
50+
51+
### Contributing
52+
53+
As this package is my first, any comment, pull request, issue is welcome so I can learn more from everyone.
54+
55+
### License
56+
57+
MIT

package.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "redux-devtools-dispatch",
3+
"version": "0.1.0",
4+
"description": "Dispatch your actions manually to test if your app react well",
5+
"main": "lib/index.js",
6+
"scripts": {
7+
"clean": "rimraf lib",
8+
"build": "babel src --out-dir lib",
9+
"prepublish": "npm run clean && npm run build"
10+
},
11+
"repository": {
12+
"type": "git",
13+
"url": "https://github.com/YoruNoHikage/redux-devtools-dispatch.git"
14+
},
15+
"keywords": [
16+
"redux",
17+
"devtools",
18+
"dispatch",
19+
"actions",
20+
"manually"
21+
],
22+
"author": "Alexis Launay <[email protected]> (http://github.com/YoruNoHikage)",
23+
"license": "MIT",
24+
"bugs": {
25+
"url": "https://github.com/YoruNoHikage/redux-devtools-dispatch/issues"
26+
},
27+
"homepage": "https://github.com/YoruNoHikage/redux-devtools-dispatch",
28+
"devDependencies": {
29+
"babel-cli": "^6.3.15",
30+
"babel-core": "^6.1.20",
31+
"babel-loader": "^6.2.0",
32+
"babel-preset-es2015-loose": "^6.1.3",
33+
"babel-preset-react": "^6.3.13",
34+
"babel-preset-stage-0": "^6.3.13",
35+
"rimraf": "^2.3.4",
36+
"webpack": "^1.11.0"
37+
},
38+
"peerDependencies": {
39+
"react": "^0.14.0",
40+
"redux-devtools": "^3.0.0"
41+
},
42+
"dependencies": {}
43+
}

src/Dispatcher.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import React, { Component, PropTypes } from 'react';
2+
3+
const buttonStyles = {
4+
cursor: 'pointer',
5+
fontWeight: 'bold',
6+
borderRadius: '3px',
7+
padding: '4px',
8+
margin: '5px 3px',
9+
fontSize: '0.8em',
10+
color: 'white',
11+
textDecoration: 'none',
12+
backgroundColor: '#4F5A65',
13+
border: 'none',
14+
position: 'absolute',
15+
bottom: '3px',
16+
right: '5px'
17+
};
18+
19+
const contentStyles = {
20+
background: '#2A2F3A',
21+
margin: '5px',
22+
padding: '5px',
23+
borderRadius: '3px',
24+
outline: 'none',
25+
color: 'white',
26+
overflow: 'auto'
27+
};
28+
29+
export default class Dispatcher extends Component {
30+
static contextTypes = {
31+
store: PropTypes.object
32+
};
33+
34+
static update = () => {};
35+
36+
constructor(props, context) {
37+
super(props, context);
38+
}
39+
40+
launchAction() {
41+
this.context.store.dispatch(JSON.parse(this.refs.action.innerText.replace(/\s+/g, ' ')));
42+
}
43+
44+
componentDidMount() {
45+
this.refs.action.innerText = this.props.initEmpty ? '\n' : `{
46+
"type": ""
47+
}`;
48+
}
49+
50+
render() {
51+
return (
52+
<div style={{background: '#4F5A65', fontFamily: 'monaco,Consolas,Lucida Console,monospace'}}>
53+
<div contentEditable='true' style={contentStyles} ref='action'></div>
54+
<button style={buttonStyles} onClick={this.launchAction.bind(this)}>Dispatch</button>
55+
</div>
56+
);
57+
}
58+
}

src/MultipleMonitors.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React, { Component, cloneElement } from 'react';
2+
3+
function childrenMonitorState(props, state, action) {
4+
return props.children.map(child => child.type.update(child.props, state, action));
5+
}
6+
7+
function reducer(props, state = {}, action) {
8+
return {
9+
childrenMonitorState: childrenMonitorState(props, state.childMonitorState, action)
10+
};
11+
}
12+
13+
const defaultStyle = {
14+
height: '100%',
15+
display: 'flex',
16+
flexDirection: 'column',
17+
};
18+
19+
export default class MultipleMonitors extends Component {
20+
static update = reducer;
21+
22+
constructor(props, context) {
23+
super(props, context);
24+
}
25+
26+
render() {
27+
const { monitorState, children, style = defaultStyle, ...rest } = this.props;
28+
29+
const monitors = children.map((e, i) => cloneElement(e, {
30+
...rest,
31+
monitorState: monitorState.childrenMonitorState[i],
32+
key: 'monitor' + i
33+
}));
34+
35+
return (
36+
<div style={style}>
37+
{monitors}
38+
</div>
39+
);
40+
}
41+
}

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default from './Dispatcher';

0 commit comments

Comments
 (0)