Skip to content

Instantly share code, notes, and snippets.

@garlicnation
Created September 15, 2015 08:49
Show Gist options
  • Save garlicnation/6cc066375224d10347b6 to your computer and use it in GitHub Desktop.
Save garlicnation/6cc066375224d10347b6 to your computer and use it in GitHub Desktop.
behavior singleton model
(function(){
var SocketConnection = function() {
this.connection = instanceConnection();
};
// This is a globally shared connection.
var singletonConnection = null;
window.SocketConnectionBehavior = {
properties: {
connection: {
type: Object,
value: function() {
return getConnection();
}
}
},
// This function returns the global connection and creates an instance of it if necessary.
getConnection: function() {
if (singletonConnection === null) {
singletonConnection = new SocketConnection();
}
return singletonConnection;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment