frame-js / Frame

Frame is a flow based programming library for databases, APIs, utilities, objects, schemas and more!
MIT License
17 stars 2 forks source link

Singletons should also be allowed to be instances #9

Open bugs181 opened 5 years ago

bugs181 commented 5 years ago

Singletons should also be allowed to be instances when it's fitting. Maybe perhaps determined by initializer. For example a Storage adapter may be a singleton for a specific connection/directory, but another singleton for a different directory. This essentially groups flows into singletons deterministically.

bugs181 commented 5 years ago

I suppose we could leave these up to the blueprint implementations themselves. A top level singleton can choose to create a new instance of itself based on some factor.

Example implementation:

Blueprint = {
   instances: {},
   init: function(props, callback) {
       if (instances[props.path])
           return instances[props.path]

       // Set up a new instance to be shared here.
   }
}