lifecyclemixin

0.1.1 • Public • Published

lifecyclemixin NPM version Build Status

Fire React lifecycle events on your Backbone models, collections and views.

Installation

$ npm install --save lifecyclemixin

Methods

lifecyclemixin searches your state for Backbone objects and automatically binds the events. Use these methods for models outside your state.

@addLifecycleListener(foo: Backbone.Model)

@removeLifecycleListener(foo: Backbone.Model)

Usage

var React = require('react');
var Backbone = require('backbone');
var lifecyclemixin = require('lifecyclemixin');
 
var Model = Backbone.Model.extend({
    initialize: function() {
        this.on('componentWillMount', this.componentWillMount, this);
    },
    componentWillMount: function() {
        console.log('My parent component is about to mount');
    }
});
 
var myModel = new Model();
var Component = React.createClass({
    mixins: [lifecyclemixin],
    getInitialState: function() {
        return {
            model: new Model()
        };
    },
    componentWillMount: function() {
        this.addLifecycleListener(myModel);
    },
    componentWillUnmount: function() {
        this.removeLifecycleListener(myModel);
    },
    render: function() {
        return <div> Hello World </div>;
    }
});

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.1
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.1.1
    0
  • 0.1.0
    0

Package Sidebar

Install

npm i lifecyclemixin

Weekly Downloads

0

Version

0.1.1

License

ISC

Last publish

Collaborators

  • charliedowler