
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
backbone-react-component
Advanced tools
Backbone.React.Component is a wrapper for React.Component and brings all the power of Facebook's React to Backbone.js
Backbone.React.Component
is a mixin and API that glues Backbone models and collections into React components.
When used as a mixin the component is mounted, a wrapper starts listening to models and collections changes to automatically set your component state and achieve UI binding through reactive updates.
Table of Contents generated with DocToc
Using Bower
bower install backbone-react-component
Using Npm
npm install backbone-react-component
If you're not using Bower nor Npm download the source from the dist folder or use CDNJS.
import Backbone from 'backbone';
import backboneReact from 'backbone-react-component';
import React from 'react';
var collection1 = new Backbone.Collection([
{hello: 1},
{hello: 2}
]);
export default class Component extends React.Component {
componentWillMount () {
backboneReact.on(this, {
collections: {
myCollection: collection1
}
});
}
componentWillUnmount () {
backboneReact.off(this);
}
render () {
return (
<div>
{this.state.myCollection.map((model) => model.hello)}
</div>
);
}
}
var MyComponent = React.createClass({
mixins: [Backbone.React.Component.mixin],
render: function () {
return <div>{this.state.model.foo}</div>;
}
});
var model = new Backbone.Model({foo: 'bar'});
ReactDOM.render(<MyComponent model={model} />, document.body);
// Update the UI
model.set('foo', 'Hello world!');
MyComponent
will listen to any model changes, making the UI refresh.
var MyComponent = React.createClass({
mixins: [Backbone.React.Component.mixin],
createEntry: function (entry) {
return <div key={entry.id}>{entry.helloWorld}</div>;
},
render: function () {
return <div>{this.state.collection.map(this.createEntry)}</div>;
}
});
var collection = new Backbone.Collection([
{id: 0, helloWorld: 'Hello world!'},
{id: 1, helloWorld: 'Hello world!'}
]);
ReactDOM.render(<MyComponent collection={collection} />, document.body);
var MyComponent = React.createClass({
mixins: [Backbone.React.Component.mixin],
createEntry: function (entry) {
return <div>{entry.helloWorld}</div>;
},
render: function () {
return (
<div>
{this.state.firstModel.helloWorld}
{this.state.secondModel.helloWorld}
{this.state.firstCollection.map(this.createEntry)}
{this.state.secondCollection.map(this.createEntry)}
</div>
);
}
});
var MyFactory = React.createFactory(MyComponent);
var newComponent = MyFactory({
model: {
firstModel: new Backbone.Model({helloWorld: 'Hello world!'}),
secondModel: new Backbone.Model({helloWorld: 'Hello world!'})
},
collection: {
firstCollection: new Backbone.Collection([{helloWorld: 'Hello world!'}]),
secondCollection: new Backbone.Collection([{helloWorld: 'Hello world!'}])
}
});
ReactDOM.render(newComponent, document.body);
var Backbone = require('backbone');
var backboneMixin = require('backbone-react-component');
var React = require('react');
var model = new Backbone.Model({
helloWorld: 'Hello world!'
});
var HelloWorld = React.createClass({
mixins: [backboneMixin],
render: function () {
return React.DOM.div({}, this.state.model.helloWorld);
}
});
var HelloWorldFactory = React.createFactory(HelloWorld);
// Render to an HTML string
ReactDOM.renderToString(HelloWorldFactory({model: model}));
// Updating the model
model.set('helloWorld', 'Hi again!');
// Rendering to an HTML string again
ReactDOM.renderToString(HelloWorldFactory({model: model}));
Binds all models/collections found inside modelsAndCollectionsObject
to
component
. modelsAndCollectionsObject
takes the following form:
{
models: {
a: new Backbone.Model() // binds to `@state.a`
},
collections: {
b: new Backbone.Collection() // binds to `@state.b`
}
}
Shortcut method to #on
. modelsObject
can either be an object of
Backbone.Model
s or a single instance of one.
Shortcut method to #on
. collectionsObject
can either be an object of
Backbone.Collection
s or a single instance of one.
Teardown method. Unbinds all models and collections from component
.
The following API is under Backbone.React.Component.mixin
(require('backbone-react-component')
):
Inspired by Backbone.View, it's a shortcut to this.$el.find method if jQuery
is present, else it fallbacks to native DOM querySelector
.
Grabs the component's collection(s) or from one of the parents.
Grabs the component's model(s) or from one of the parents.
Hook that can be implemented to return a model or multiple models. This hook is
executed when the component is initialized. It's useful on cases such as when
react-router
is being used.
Hook that can be implemented to return a collection or multiple collections.
This hook is executed when the component is initialized. It's useful on cases
such as when react-router
is being used.
FAQs
Backbone.React.Component is a wrapper for React.Component and brings all the power of Facebook's React to Backbone.js
The npm package backbone-react-component receives a total of 26 weekly downloads. As such, backbone-react-component popularity was classified as not popular.
We found that backbone-react-component demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.