This commit is contained in:
Jeronimo Vallelunga 2017-07-14 02:02:47 -03:00
parent 30c6a83399
commit 7afd02be57
6 changed files with 73 additions and 5 deletions

View File

@ -0,0 +1 @@
babel configuration is important to run `ink`

View File

@ -0,0 +1,34 @@
const { h, mount, Component, Text } = require('ink');
class Counter extends Component {
constructor() {
super();
this.state = {
i: 0
};
}
render() {
return h(
Text,
{ green: true },
this.state.i,
' tests passed'
);
}
componentDidMount() {
this.timer = setInterval(() => {
this.setState({
i: this.state.i + 1
});
}, 100);
}
componentWillUnmount() {
clearInterval(this.timer);
}
}
mount(h(Counter, null), process.stdout);

View File

@ -13,7 +13,15 @@
},
"babel": {
"presets": [
"latest"
"es2015-node5"
],
"plugins": [
[
"transform-react-jsx",
{
"pragma": "h"
}
]
]
},
"repository": {
@ -34,11 +42,14 @@
"homepage": "https://github.com/jvallelunga/redux-bluetooth#readme",
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-preset-latest": "^6.24.1",
"babel-plugin-transform-react-jsx": "^6.24.1",
"babel-preset-es2015-node5": "^1.2.0",
"jest": "^20.0.4",
"watch": "^1.0.2"
},
"dependencies": {
"ink": "^0.1.2",
"ink-redux": "^1.0.0",
"redux": "^3.7.1",
"redux-bluetooth": "^0.1.1"
}

View File

@ -2,7 +2,10 @@ import { createStore } from 'redux';
import startPeripheral from 'redux-bluetooth/build/peripheral';
import reducer from './reducer';
import output from './output';
const store = createStore(reducer);
output(store);
startPeripheral('Counter', store);

View File

@ -0,0 +1,22 @@
const { h, mount, Component } = require('ink');
const { Provider, connect } = require('ink-redux');
export default (store) => {
class Counter extends Component {
render(props) {
return `Counter: ${props.counter}`;
}
}
const mapStateToProps = state => ({
counter: state,
});
const ConnectedCounter = connect(mapStateToProps)(Counter);
mount((
<Provider store={store}>
<ConnectedCounter />
</Provider>
));
};

View File

@ -1,7 +1,4 @@
export default function counter(state = 0, { type }) {
console.log('Counter: ---------------------------');
console.log(type);
console.log(state);
switch (type) {
case 'INCREMENT':
return state + 1;