diff --git a/README.md b/README.md index daed8fe..d887685 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,10 @@ Redux Bluetooth is a project which consists in two components: **webapp** middleware, is a redux middleware to dispatch actions via [web bluetooth](https://developers.google.com/web/updates/2015/07/interact-with-ble-devices-on-the-web#user_gesture_required). **peripheral** store, is a redux store which process actions received over bluetooth and notify changes on every store change. +
+ React Bluetooth - Example +
+ ## Install ```shell diff --git a/docs/example.gif b/docs/example.gif new file mode 100644 index 0000000..667ff5a Binary files /dev/null and b/docs/example.gif differ diff --git a/example/peripheral/package.json b/example/peripheral/package.json index 9682a7a..4b00a3f 100644 --- a/example/peripheral/package.json +++ b/example/peripheral/package.json @@ -50,6 +50,7 @@ "dependencies": { "ink": "^0.1.2", "ink-redux": "^1.0.0", + "prop-types": "^15.5.10", "redux": "^3.7.1", "redux-bluetooth": "^0.1.1" } diff --git a/example/peripheral/src/output.js b/example/peripheral/src/output.js deleted file mode 100644 index 3ba8d9f..0000000 --- a/example/peripheral/src/output.js +++ /dev/null @@ -1,22 +0,0 @@ -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(( - - - - )); -}; diff --git a/example/peripheral/src/output.jsx b/example/peripheral/src/output.jsx new file mode 100644 index 0000000..141069e --- /dev/null +++ b/example/peripheral/src/output.jsx @@ -0,0 +1,38 @@ +/* eslint-disable react/react-in-jsx-scope */ +const { h, mount, Text } = require('ink'); +const { Provider, connect } = require('ink-redux'); +const PropTypes = require('prop-types'); + +export default (store) => { + function Counter({ counter }) { + const color = { + blue: counter > 0, + red: counter < 0, + }; + return ( +
+ Counter: + {counter} +
+ ); + } + + Counter.propTypes = { + counter: PropTypes.number, + }; + Counter.defaultProps = { + counter: 0, + }; + + const mapStateToProps = state => ({ + counter: state, + }); + + const ConnectedCounter = connect(mapStateToProps)(Counter); + + mount( + + + , + ); +}; diff --git a/example/webapp/src/app/component.jsx b/example/webapp/src/app/component.jsx index 4faff3f..fcf67ab 100644 --- a/example/webapp/src/app/component.jsx +++ b/example/webapp/src/app/component.jsx @@ -18,10 +18,15 @@ export default class App extends PureComponent { render() { const { store, status, onIncrement, onDecrement } = this.props; + const counter = Number(store); + let className = 'app-counter'; + if (counter > 0) className += ' app-counter--positive'; + if (counter < 0) className += ' app-counter--negative'; + return (
{status === 'CONNECTED' && -
+
{store}
}
diff --git a/example/webapp/src/app/style.css b/example/webapp/src/app/style.css index 7bbc26e..fbe8fa1 100644 --- a/example/webapp/src/app/style.css +++ b/example/webapp/src/app/style.css @@ -12,9 +12,15 @@ margin-bottom: 40px; line-height: calc(100vh - 200px); font-size: 80vh; - color: red; + color: black; text-align: center; } +.app-counter--positive { + color: blue; +} +.app-counter--negative { + color: red; +} .app-actions { height: 30px;