Ink
This commit is contained in:
parent
30c6a83399
commit
7afd02be57
|
@ -0,0 +1 @@
|
|||
babel configuration is important to run `ink`
|
|
@ -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);
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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>
|
||||
));
|
||||
};
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue