Skip to content

Commit

Permalink
Unload modules in reverse order (microsoft#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
shutchings authored and navneet-g committed Mar 15, 2019
1 parent e104694 commit 5a86149
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/redux-dynamic-modules/src/Managers/ModuleManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ export function getModuleManager<State>(
if (!modulesToRemove) {
return;
}
modulesToRemove = modulesToRemove.filter(module => module);
modulesToRemove = modulesToRemove
.filter(module => module)
.reverse();
modulesToRemove.forEach(module => {
if (_moduleIds.has(module.id)) {
_dispatchActions(module.finalActions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ it("module manager tests", () => {
]);
});

it("Dispose disposes all modules", () => {
it("Dispose disposes all modules in reverse order they are added", () => {
const middlewareManager = getMiddlewareManager();
const moduleManager = getModuleManager(middlewareManager, []);
let actionsDispatched = [];
Expand All @@ -126,13 +126,28 @@ it("Dispose disposes all modules", () => {
sagas: [saga1],
};

// Add first module
const module2 = {
id: "module2",
initialActions: [{ type: "initial2" }, { type: "initial21" }],
reducerMap: { duplicateReducer: reducer, key2: reducer },
finalActions: [{ type: "final2" }, { type: "final21" }],
sagas: [saga1],
};

moduleManager.add([module1]);
moduleManager.add([module2]);
moduleManager.dispose();

expect(actionsDispatched).toEqual([
"@@Internal/ModuleManager/ModuleAdded",
"initial1",
"initial11",
"@@Internal/ModuleManager/ModuleAdded",
"initial2",
"initial21",
"final2",
"final21",
"@@Internal/ModuleManager/ModuleRemoved",
"final1",
"final11",
"@@Internal/ModuleManager/ModuleRemoved",
Expand Down

0 comments on commit 5a86149

Please sign in to comment.