ecowden / pluto.js

JavaScript Dependency Injection
MIT License
8 stars 3 forks source link

Bundle Bootstrapping #28

Closed ecowden closed 7 years ago

ecowden commented 7 years ago

After we have asynchronous injection (#25), the old .eagerlyLoadAll(...) doesn't make as much sense. Instead, this is our opportunity to "bootstrap" the whole shebang (probably the whole application). It should try to load all injectables, resolve all promises as needed, and return an object holding the fully bootstrapped set of components.

  const anInstance = Promise.resolve({}) // Promises will be resolved
  const bind = pluto()
  bind('myInstance').toInstance(anInstance)

  // ... eagerly load everything. Maybe `.bootstrap()`?
  const app = yield bind.eagerlyLoadAll()

  // ...and then everything can be retrieved synchronously
  t.is(app.get('myInstance'), anInstance)
ecowden commented 7 years ago

Fixed on one-oh-redesign branch.