Skip to content

Instantly share code, notes, and snippets.

View tylertreat's full-sized avatar

Tyler Treat tylertreat

View GitHub Profile
$ node r.js -o name=main out=main-built.js baseUrl=.
JAVASCRIPT_DIR := ./static/js
js:
bower install
jsx $(JAVASCRIPT_DIR)/src $(JAVASCRIPT_DIR)/build
node $(JAVASCRIPT_DIR)/lib/r.js/dist/r.js -o $(JAVASCRIPT_DIR)/build/buildconfig.js
/** @jsx React.DOM */
var MyJSXComponent = React.createClass({
render: function() {
return <div>Hello, {this.props.name}</div>;
},
});
// This is the compiled output of MyJSXComponent.
var MyJSComponent = React.createClass({
render: function() {
var Button = React.createClass({
getInitialState: function() {
return {count: 0};
},
render: function() {
return (
<button type="button" onClick={this.handleClick}>
{'Clicked ' + this.state.count + ' time(s)'}
</button>
var Foo = React.createClass({
render : function() {
return <div>foo</div>;
},
});
var Bar = React.createClass({
render : function() {
return <div>bar</div>;
},
if __name__ == '__main__':
app = create_app()
server = SocketIOServer(
('0.0.0.0', 5000),
SharedDataMiddleware(app, {}),
policy_server=False)
server.serve_forever()
@blueprint.route('/socket.io/<path:path>')
def run_socketio(path):
socketio_manage(
request.environ, {'/notifications': NotificationsNamespace})
return ''
class NotificationsNamespace(BaseNamespace, BroadcastMixin):
"""Socket.IO namespace for broadcasting notifications."""
def __init__(self, *args, **kwargs):
global _redis
_redis = redis.StrictRedis('localhost', 6379, db=0)
self.pubsub = _redis.pubsub()
self.pubsub.subscribe('notifications')
super(NotificationsNamespace, self).__init__(*args, **kwargs)
def notify(event, payload):
"""Publish an event notification to all subscribers.
Args:
event: the name of the event.
payload: dict consisting of the event payload.
"""
global _redis
if _redis:
var dispatcher = _.clone(Backbone.Events);
var fooView = new FooView({
dispatcher: dispatcher
});
var barView = new BarView({
dispatcher: dispatcher
});
var bazView = new BazView({
dispatcher: dispatcher
});