-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DX-324] full async plugins initialisation #795
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,27 +81,28 @@ module.exports.init = function(pluginsToRegister, callback) { | |
}; | ||
|
||
const loadPlugin = function(plugin, cb) { | ||
const done = _.once(cb); | ||
|
||
if (registered[plugin.name]) { | ||
return cb(); | ||
return done(); | ||
} | ||
|
||
if (!plugin.register.dependencies) { | ||
plugin.register.dependencies = []; | ||
} | ||
|
||
if (!dependenciesRegistered(plugin.register.dependencies)) { | ||
return defer(plugin, cb); | ||
return defer(plugin, done); | ||
} | ||
|
||
const dependencies = _.pick(registered, plugin.register.dependencies); | ||
|
||
plugin.register.register( | ||
plugin.options || {}, | ||
dependencies, | ||
plugin.callback || _.noop | ||
); | ||
registered[plugin.name] = plugin.register.execute; | ||
cb(); | ||
plugin.register.register(plugin.options || {}, dependencies, err => { | ||
const pluginCallback = plugin.callback || _.noop; | ||
pluginCallback(err); | ||
registered[plugin.name] = plugin.register.execute; | ||
done(err); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. now the callback is called actually after the registration is completed |
||
}); | ||
}; | ||
|
||
const terminator = function(err) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,29 +105,24 @@ describe('registry : domain : plugins-initialiser', () => { | |
{ | ||
name: 'getValue', | ||
register: { | ||
register: function(options, deps, cb) { | ||
register: (options, deps, cb) => { | ||
passedOptions = options; | ||
cb(); | ||
}, | ||
execute: function(key) { | ||
return passedOptions[key]; | ||
} | ||
execute: key => passedOptions[key] | ||
}, | ||
options: { | ||
a: 123, | ||
b: 456 | ||
} | ||
options: { a: 123, b: 456 } | ||
}, | ||
{ | ||
name: 'isFlagged', | ||
register: { | ||
register: function(options, deps, cb) { | ||
flag = true; | ||
cb(); | ||
register: (options, deps, cb) => { | ||
setTimeout(() => { | ||
flag = true; | ||
cb(); | ||
}, 10); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With this artificial timeout, I am testing that the callback is actually called after the registration (test failed before the code change) |
||
}, | ||
execute: function() { | ||
return flag; | ||
} | ||
execute: () => flag | ||
} | ||
} | ||
]; | ||
|
@@ -148,8 +143,8 @@ describe('registry : domain : plugins-initialiser', () => { | |
}); | ||
|
||
it('should be make the functionality usable', () => { | ||
const a = result.getValue('a'), | ||
flagged = result.isFlagged(); | ||
const a = result.getValue('a'); | ||
const flagged = result.isFlagged(); | ||
|
||
expect(a).to.equal(123); | ||
expect(flagged).to.equal(true); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allows robustness against plugins that would erroneously call the done() callback multiple times:
https://github.com/opencomponents/oc-hobknob/blob/master/index.js#L25