From 7bd4b39b5a28db18087026113fb684802e840fb9 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Tue, 18 Dec 2018 05:03:38 +0100 Subject: [PATCH] Added lazy loading to action services --- src/container/index.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/container/index.js b/src/container/index.js index 8d4f97da..88f8b6a3 100644 --- a/src/container/index.js +++ b/src/container/index.js @@ -45,7 +45,8 @@ const bottle = new Bottle(); const { container } = bottle; const mapActionService = (map, actionName) => { - map[actionName] = container[actionName]; + // Wrap actual action service in a function so that it is lazily created the first time it is called + map[actionName] = (...args) => container[actionName](...args); return map; }; @@ -137,14 +138,14 @@ bottle.decorator('DeleteShortUrlModal', connectDecorator( { deleteShortUrl, resetDeleteShortUrl, shortUrlDeleted } )); -bottle.serviceFactory('editShortUrlTags', editShortUrlTags, 'ShlinkApiClient'); -bottle.serviceFactory('resetShortUrlsTags', () => resetShortUrlsTags); -bottle.serviceFactory('shortUrlTagsEdited', () => shortUrlTagsEdited); - bottle.serviceFactory('EditTagsModal', EditTagsModal, 'TagsSelector'); bottle.decorator('EditTagsModal', connectDecorator( [ 'shortUrlTags' ], [ 'editShortUrlTags', 'resetShortUrlsTags', 'shortUrlTagsEdited' ] )); +bottle.serviceFactory('editShortUrlTags', editShortUrlTags, 'ShlinkApiClient'); +bottle.serviceFactory('resetShortUrlsTags', () => resetShortUrlsTags); +bottle.serviceFactory('shortUrlTagsEdited', () => shortUrlTagsEdited); + export default container;