Skip to content

Instantly share code, notes, and snippets.

@Anachron
Last active August 29, 2015 14:13
Show Gist options
  • Select an option

  • Save Anachron/de65163808058f5dc2ff to your computer and use it in GitHub Desktop.

Select an option

Save Anachron/de65163808058f5dc2ff to your computer and use it in GitHub Desktop.
App = require 'App'
SingletonFactory = require 'SingletonFactory'
AppFactory = {}
AppFactory.get = (options) ->
return SingletonFactory.getObject 'App', options
AppFactory.has = () ->
return SingletonFactory.hasObject 'App'
}
module.exports = AppFactory
SingletonFactory = {}
SingletonFactory.objects = {}
SingletonFactory.getObject (className, options) ->
if hasObject className then
return this.objects[className]
else
obj = new className(options)
this.objects[className] = obj
return obj
SingletonFactory.hasObject (className) ->
return is className in SingletonFactory.objects
module.exports = SingletonFactory
AppFactory = require 'AppFactory'
App = AppFactory.get()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment