Skip to content

Commit

Permalink
new 'missing scripts' event type
Browse files Browse the repository at this point in the history
  • Loading branch information
sometimeskind committed Feb 14, 2018
1 parent ba80413 commit 5d15668
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/app-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ export default function initAppManager(w: Window) {

events.emit(eventTitles.STATUS_CHANGE, getDefaultStatusDetails());

if (!haveScripts) {
events.emit(eventTitles.EXTERNAL_LINK);
if (!haveScripts && !initialRender) {
events.emit(eventTitles.MISSING_SCRIPTS);
return;
}
} catch (err) {
Expand Down
1 change: 1 addition & 0 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ export const eventTitles = {
STATUS_CHANGE: `${APP_MANAGER_NAMESPACE}-statuschange`,
ERROR: `${APP_MANAGER_NAMESPACE}-error`,
EXTERNAL_LINK: `${APP_MANAGER_NAMESPACE}-external-link`,
MISSING_SCRIPTS: `${APP_MANAGER_NAMESPACE}-missing-scripts`,
};
2 changes: 1 addition & 1 deletion lib/utils/lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export default function initGetLifecycle(fragments: FragmentsMapType, loadScript
} catch (err) {
await handleLifecycleError(slotName, err);
onError(err);
return true;
return false;
}
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "app-manager",
"version": "0.21.0",
"version": "0.21.1",
"description": "Script for managing the lifecycles of multiple apps on a single page",
"main": "es5/index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions test/app-manager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@ describe('app-manager', () => {
expect(mockB.onUpdateStatus.callCount).to.equals(10);
});

it('If a fragment does not have a loadScript function, treat the app as an external link', async () => {
it('If a fragment does not have a loadScript function, emit a missing-scripts event', async () => {
windowStub.history.pushState(null, null, '/app-c');

await awaitEvent(events, 'am-external-link');
await awaitEvent(events, 'am-missing-scripts');

expect((_getState(): any).app.name).to.equals('APP_C');

Expand Down

0 comments on commit 5d15668

Please sign in to comment.