
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.
bly-react-mixin
Advanced tools
Bly and React make for a really good couple, it's what Bly was designed with in mind. This mixin is the glue to their relationship, letting you access stores and dispatch actions from your React components.
Simply pass in your Bly app to your top level component using the 'bly' prop. This will give it and all of it's children that also use the mixin access to Bly's app.stores
(read-only) and app.inject
. Do this in Bly's app.render
and you're all golden.
var Bly = require('bly');
var React = require('react');
var BlyReactMixin = require('bly-react-mixin');
var MessagesStore = require('./stores/messages-store');
var YourAppComponent = React.createClass({
mixins: [BlyReactMixin],
getInitialState: function() {
// access a store of your bly app
return {
latestMessage: this.stores('messages').last()
};
},
render: function() {
return React.DOM.div({
onClick: this.onClickMessage
}, this.state.lastMessage.text);
// could have been JSX just as easily
// <div onClick={this.onClickMessage}>
// {this.state.lastMessage.text}
// </div>
},
onClickMessage: function(e) {
// dispatch actions
this.inject('MESSAGE_READ', this.state.latestMessage.id);
}
});
var app = new Bly.App();
app.stores('messages', new MessagesStore());
app.action({
name: 'MESSAGE_READ',
handler: function(waitFor, messageId) {
app.stores('messages').onRead(messageId);
}
});
// setup rendering
app.render(function() {
React.renderComponent(YourAppComponent({
bly: app
}), document.documentElement);
});
As long as the components are created inside the top level component or one of it's children, you don't have to pass around the bly
prop manually. However, if a component is created somewhere else, you'll have to pass the app using the bly
prop manually. The easiest way is to use the provided cloneWithBly
method.
var React = require('react');
var BlyReactMixin = require('bly-react-mixin');
var MessageComponent = React.createClass({
mixins: [BlyReactMixin],
getInitialState: function() {
return {
latestMessage: this.stores('messages').last()
};
};
render: function() {
return React.DOM.div({}, 'foo');
}
});
// When creating the child inside a component, you don't have to pass it manually
var FirstMessageApp = React.createClass({
mixins: [BlyReactMixin],
render: function() {
// no need to manually pass bly
return React.DOM.div({},
MessageComponent()
);
}
});
// If the component is created elsewhere, outside of a component with access to the Bly app,
// your bly instance needs to be passed in. You can do this manually, but can also use the
// provided `this.cloneWithBly` for convenience
var SecondMessageApp = React.createClass({
mixins: [BlyReactMixin],
render: function() {
//
return React.DOM.div({},
this.cloneWithBly(this.props.children) // injects bly into the component(s) we're rendering
);
}
});
Retrieve a reference to a store instance.
name
- (required) name of the store you want to retrieve.Inject an action into the system to be dispatched. The dispatching of an action is synchronous and only one action can be dispatched at a time.
action
- (required) the name of the action you want to inject. For example RECEIVE_MESSAGES
.payload
- the payload of the action, can be any value. Defaults to an empty object {}
.Let an 'action creator' (read: function) handle the dispatching of an action, which is especially useful with the more complex actions. All other arguments will be passed to the action creator.
actionCreator
- (required) a function with the signature function(app, args..)
where:
app
- instance of your bly appargs...
- any arguments passed to component.inject
after the action creatorFAQs
React mixin to easily integrate with the Bly flux framework
The npm package bly-react-mixin receives a total of 2 weekly downloads. As such, bly-react-mixin popularity was classified as not popular.
We found that bly-react-mixin 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.