magalhas / backbone-react-component

A bit of nifty glue that automatically plugs your Backbone models and collections into your React components, on the browser and server
http://magalhas.github.io/backbone-react-component/
MIT License
809 stars 72 forks source link

Correct way to listen for events #56

Closed benhowdle89 closed 9 years ago

benhowdle89 commented 9 years ago
module.exports = React.createClass({
    mixins: [BackboneMixin],
    removeProduct: function(product){
        this.getCollection().products.remove(this.getCollection().products.findWhere({
            name: product.name
        }));
    },
    createProduct: function(product){
        return <li onClick={this.removeProduct.bind(this, product)}>{product.name}</li>;
    },
    render: function(){
        return (
            <p>PRODUCTS: <ul>{this.props.products.map(this.createProduct)}</ul></p>
        );
    }
});

When I remove the clicked Model from the passed in Collection instance, the UI does not seem to update. If you could confirm I'm using state/props, etc...correctly, that'd be marvellous.

Should clarify, the Model is successfully removed from the Collection.

magalhas commented 9 years ago

Hi I'm pretty sure the problem have to do with the fact you're not working on a top level component, which is a limitation of the v0.7. That's not a problem anymore on the master branch, can you please try it out? Keep in mind that @state is used instead of @props to keep a JSON representation of the models/collections.

magalhas commented 9 years ago

You can find the list of changes included in the master branch in #55

magalhas commented 9 years ago

@benhowdle89 I've just released v0.8.0-beta.1 to make it easier for everyone to test it out. The only thing missing for a final release is React final version of v0.13 and updating all the docs and examples here in the repo.