Refactor afterLoad interface to expose raw plugin context

This commit is contained in:
Kyle Shockey
2017-12-28 16:26:05 -06:00
parent 1646b270f8
commit 9d48c4751a
4 changed files with 118 additions and 14 deletions

View File

@@ -684,13 +684,13 @@ describe("bound system", function(){
})
describe("afterLoad", function() {
it("should call an plugin's `afterLoad` method after the plugin is loaded", function() {
it("should call a plugin's `afterLoad` method after the plugin is loaded", function() {
// Given
const system = new System({
plugins: [
{
afterLoad(system) {
system.wow = system.dogeSelectors.wow
this.rootInjects.wow = system.dogeSelectors.wow
},
statePlugins: {
doge: {
@@ -705,6 +705,89 @@ describe("bound system", function(){
]
})
// When
var res = system.getSystem().wow()
expect(res).toEqual("so selective")
})
it("should call a preset plugin's `afterLoad` method after the plugin is loaded", function() {
// Given
const MyPlugin = {
afterLoad(system) {
this.rootInjects.wow = system.dogeSelectors.wow
},
statePlugins: {
doge: {
selectors: {
wow: () => (system) => {
return "so selective"
}
}
}
}
}
const system = new System({
plugins: [
[MyPlugin]
]
})
// When
var res = system.getSystem().wow()
expect(res).toEqual("so selective")
})
it("should call a function preset plugin's `afterLoad` method after the plugin is loaded", function() {
// Given
const MyPlugin = {
afterLoad(system) {
this.rootInjects.wow = system.dogeSelectors.wow
},
statePlugins: {
doge: {
selectors: {
wow: () => (system) => {
return "so selective"
}
}
}
}
}
const system = new System({
plugins: [
() => {
return [MyPlugin]
}
]
})
// When
var res = system.getSystem().wow()
expect(res).toEqual("so selective")
})
it("should call a registered plugin's `afterLoad` method after the plugin is loaded", function() {
// Given
const MyPlugin = {
afterLoad(system) {
this.rootInjects.wow = system.dogeSelectors.wow
},
statePlugins: {
doge: {
selectors: {
wow: () => (system) => {
return "so selective"
}
}
}
}
}
const system = new System({
plugins: []
})
system.register([MyPlugin])
// When
var res = system.getSystem().wow()
expect(res).toEqual("so selective")