Skip to content

Commit

Permalink
adds ability to add the fully bootstrapped plutoApp
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Cowden committed May 24, 2017
1 parent 48e0722 commit 38c205a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/pluto.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ function pluto() {

function bootstrap() {
const result = new Map()
bind('plutoApp').toInstance(result)
const promises = []
for (let name of namesToResolvers.keys()) {
promises.push(get(name).then((value) => {
Expand Down
28 changes: 28 additions & 0 deletions lib/plutoSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,31 @@ test('injects the binder itself under the name `plutoBinder`', function* (t) {
const actual = yield bind.get('factory')
t.is(actual, 'test-data')
})

test('when bootstrapped, injects the bootstrapped app itself under the name `plutoApp`', function* (t) {
class Greeter {
constructor(plutoApp) {
// Note: the plutoApp Map may not be fully populated yet, since we could
// be at any indeterminate part of the bootstrapping process.
// Save it for later, but don't go using it yet.
this._plutoApp = plutoApp
}

greet() {
// By now, the app is fully bootstrapped and the plutoApp Map is safe
// to use.
const greeting = this._plutoApp.get('greeting')
return `${greeting}, World!`
}
}

const bind = pluto()
bind('greeting').toInstance('Bonjour')
bind('greeter').toConstructor(Greeter)

const app = yield bind.bootstrap()

const greeter = app.get('greeter')
const actual = greeter.greet()
t.is(actual, 'Bonjour, World!')
})

0 comments on commit 38c205a

Please sign in to comment.