Skip to content

Instantly share code, notes, and snippets.

@guerrerocarlos
Created September 6, 2012 05:07
Show Gist options
  • Star 39 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save guerrerocarlos/3651490 to your computer and use it in GitHub Desktop.
Save guerrerocarlos/3651490 to your computer and use it in GitHub Desktop.
loading socket.io using require.js
// Require.js allows us to configure shortcut alias
require.config({
// The shim config allows us to configure dependencies for
// scripts that do not call define() to register a module
shim: {
'socketio': {
exports: 'io'
},
'underscore': {
exports: '_'
},
'backbone': {
deps: [
'underscore',
'jquery'
],
exports: 'Backbone'
}
},
paths: {
jquery: 'jquery.min',
underscore: 'lodash.min',
backbone: 'backbone',
socketio: '../socket.io/socket.io',
}
});
define([
'jquery',
'backbone',
'socketio',
], function( $, Backbone, io ) {
var socket = io.connect('http://localhost');
socket.on('news', function (data) {
console.log(data);
socket.emit('my other event', { my: 'data' });
});
//Ready to write Backbone Models and Socket.io communication protocol in here :)
});
@flyfly6
Copy link

flyfly6 commented Aug 7, 2014

great! Thanks very much!

@chul-hyun
Copy link

Thanks!! ><

@lwiechec
Copy link

yup, thanks!

@herlon214
Copy link

thanks 😄

@web-jenezis
Copy link

thanks a lot for this tip!!!

@ryang420
Copy link

Thanks! Fixed my issue.

@arbaouimehdi
Copy link

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment