Redux’s Connect Method Explained.

Sorry but all the explanations this far have been bad so I thought I’d simplify it.

In plain Redux without connect you need to manually bind up your store.dispatch to your components as well as subscribe to updates so you can call store.getState(). But your components are suppose to be dumb.

const store = createStore(reducer);

const render = () => ReactDOM.render( // turns ReactDOM.render into executable function
    onIncrement={() => store.dispatch({ type: 'INCREMENT' })}
    onDecrement={() => store.dispatch({ type: 'DECREMENT' })}


So rather than manually linking dispatch and subscribing to updates we create two mapping functions, both of which bind the dispatch and the state to props of the ‘connected component’. So in this case all updates to are mapped to this.props.value and rather than mapping dispatch directly, we just wrap it and pass it in as a prop.

// create component
class ContainerComponent extends React.Component {
  render() {
      onDecrement={this.props.onDecrement} />
// create state mapping
function mapStateToProps(state) {
  return { 
    value: state.value
// add dispatch mapper 
function mapDispatchToProps(dispatch) { 
  return { 
    onIncrement: function() { 
    onDecrement : function() { 
export default connect(mapStateToProps,mapDispatchToProps)(ContainerComponent);

Now when you call your components you can simply call the value passed in like so.

export default class PresentationComponent extends React.Component {
render() {
    return (      
<button onClick={this.props.onIncrement}>Increment</button>
<button onClick={this.props.onDecrement}>Decrement</button>

For more information you can checkout both of these github projects for reference.

JavaScript has become Java, sigh…

  • If I wanted to work with compiled languages, I would have stuck with Java.
  • If I wanted complicated build systems, I would have stuck with Java.
  • If I wanted complicated all encompassing frameworks, I would have stuck with Java.
  • If I wanted complicated unreadable error messages, I would have stuck with Java.
  • If I wanted to run server side code (Node) in my browser, I would have stuck with Java.

Something needs to happen to fix JavaScript making it more and more like Java is not the answer. Or is it time to move to another language with less ceremony??? error

If you’ve ever seen this error:

MinOZW: error while loading shared libraries: cannot open shared object file: No such file or directory


Error: cannot open shared object file: No such file or directory

Just type this and it did the trick for me (Ubuntu 14.04).

sudo ldconfig /usr/local/lib64


Simple React Example

So I’ve been trying to find a simple React example, one that uses a flux implementation that works out of the box in a browser without any compilation or node stuff. I couldn’t find one so I built one. Here it is:

This requires, RefluxJS, ReactJS, React-Dom and a Browser. You can use node to run it if you want, but that’s not required. Enjoy! (Copy-Paste & ES5 Compatible)

    // the action, nothing special
    var myAction = Reflux.createAction();

    // the store, holds state and listens to action.
    var myStore = Reflux.createStore({
        times: 0,
        init: function () {
            this.listenTo(myAction, this.actionCallback);
        actionCallback: function () {

    // the react component, which subscribtes to the store and updates it's state via listen
    var CountBox = React.createClass({
        displayName: 'CountBox',
        getInitialState: function () {
            return {count: 0};
        componentDidMount: function () {
            var self = this;
            myStore.listen(function (data) {
                self.setState({count: data});
        render: function () {
            return (
                // the component in plain old JS no JSX
                    React.createElement('div', {className: "countBox"},
                            "Count Value =  " + this.state.count

            React.createElement(CountBox, {count: 0}),

    document.querySelector("#test").addEventListener("click", function() {

Openzwave Binary Sensors

I’ve been struggling a bit with openzwave items because its so poorly documented. I’ve finally figured out how to get results from a door sensors with the node package node-openzwave-shared.

If you follow the install script, then just add this event handler below, you can receive updates.

zwave.on('node event', function(nodeid, nodeEvt) {
 console.log(new Date(), 'node event', nodeid, nodeEvt);

More live examples coming soon here:

And via npm via npm-install node-openzwave-examples

Simple WebSocket & NodeJS Server Example

I’ve been searching for a NodeJS server for web sockets, but, required both the client and server to be run from within node. I wanted to connect to this server via a normal web page using WebSockets from HTML5. Here’s some code, hope you find it useful:

Server Code

var WebSocketServer = require('ws').Server;
var wss = new WebSocketServer({port: 3000});

wss.on('connection', function (ws) {
    ws.on('message', function (message) {
        console.log('received: %s', message);
        ws.send(message + "!!!!");

Client Code

    var websocket = new WebSocket('ws://localhost:3000');
    websocket.onopen = function (evt) {
        websocket.send("This Rocks!");
    websocket.onmessage = function (evt) {
        console.log('RESPONSE: ' +;


Home Grown Script Loader

I was wondering how RequireJS and AMD worked. So I created this snip. It might not be correct but it worked for me.

load('foo', function (foo){
        var f = new foo();
        f.a = 100;
        f.b = 200;

    function define(name, callback) {
        modules[name] = callback;

    function load(file, callback) {
        var script = document.createElement('script');
        script.type = 'text/javascript';
        script.async = true;
        script.src = file + ".js";
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(script);
        script.onload = function() {

    var modules = [];

// foo.js
define("foo", function() {
    var foo = {
        a: 1,
        b: 2,
        add: function () {
            return this.a + this.b;
    return foo;

Created A Chevelle Blog

I decided to create a blog for my chevelle because there was so many things I was learning about it and thought I should help out some other folks working on their car.

I’ve researched a lot on YouTub and the internet as well as Chevelles.Com, but making a post there about what I learned just didn’t seem right.

To learn more visit:

Dead APC Back-Ups & Alternative Batteries

I recently had an UPS failure. My UPS and APC 650 ES, has a battery they call for is the RBC17. Which on Amazon.Com is $39.99. However when you peal the sticket off you get Vision UB1290. This battery (which is the same battery) cost around $15.00.

I imaging this happens a lot with companies looking to make a cheap buck. Hopefully this post catches someone search on “Alternative APC Battery” or something similar.