Skip to content

React.js bindings #118

@madelynnblue

Description

@madelynnblue

I've begun work on bindings for react.js (http://godoc.org/github.com/mjibson/react) but, as things currently are, they are unusable due to the generated size. A simple main function with just a println (no react bindings) generates about 2k lines and renders in about 15ms. The example linked in package there generates about 8.2k lines and renders in about 500ms, which is unusably slow. I assume it's due to the way I'm generating objects using the option funcs or something.

Why am I using option funcs, you ask? Because I can't figure out a better way to have react.js be useful. React objects have heavy use of this, and call into functions defined on the this object. It is silly to use interface{} everywhere when trying to call back into my own functions, because a major point of gopherjs is type checking, which that would defeat. Here's some example react.js code from a project of mine that I'd like to convert to gopherjs:

var Track = React.createClass({displayName: 'Track',
    play: function() {
        var params = {
            "clear": true,
            "add": this.props.key
        };
        $.get('/api/playlist/change?' + $.param(params))
            .success(function() {
                $.get('/api/cmd/play');
            });
    },
    render: function() {
        return (
            React.DOM.tr(null, 
                React.DOM.td(null, React.DOM.button({onClick: this.play}, "▶")), 
                React.DOM.td(null, this.props.key)
            )
        );
    }
});

The render function is a react.js required func. play is my own (thus I need some way to define these optional funcs on my go object). props is a react.js properties object that all of its components have. The onClick handler also references this.play. I'm not sure how to create bindings for gopherjs that feel natural in go and don't generate huge piles of code. I assume some of this is not clearly explained, so I'm happy to give more details. Any thoughts on how to improve this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions