From 84d3242b483caafc65ca216e28923fcaa5dbc514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zofia=20Go=CC=81ralewska?= Date: Fri, 13 Apr 2018 12:47:28 +0200 Subject: [PATCH 1/2] Replace nulls with undefineds --- .idea/vcs.xml | 6 ++++++ src/selectors.js | 21 ++++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 .idea/vcs.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/selectors.js b/src/selectors.js index b0fd196b..c6c3c46b 100644 --- a/src/selectors.js +++ b/src/selectors.js @@ -2,11 +2,11 @@ function getRawRequest(state, apiCall, args) { const { actionName } = apiCall; if (!state.bees.requests) { - return null; + return undefined; } if (!state.bees.requests[actionName]) { - return null; + return undefined; } return state.bees.requests[actionName][JSON.stringify(args)]; @@ -14,15 +14,15 @@ function getRawRequest(state, apiCall, args) { export function getEntity(state, handle) { if (!handle) { - return null; + return undefined; } if (!state.bees.entities) { - return null; + return undefined; } if (!state.bees.entities[handle.type]) { - return null; + return undefined; } return state.bees.entities[handle.type][handle.id]; @@ -30,17 +30,20 @@ export function getEntity(state, handle) { export function getRelationship(state, entity, relationshipName) { if (!entity) { - return null; + return undefined; } if (!entity.relationships[relationshipName]) { - return null; + return undefined; } const { data } = entity.relationships[relationshipName]; if (Array.isArray(data)) { - return data.map(handle => getEntity(state, handle)); + return data.reduce((acc, handle) => { + const el = getEntity(state, handle); + return el ? acc.concat([el]) : acc; + }, []); } return getEntity(state, data); @@ -51,7 +54,7 @@ export function getRequestResult(state, apiCall, args) { const request = getRawRequest(state, apiCall, args); if (!request || !request.response) { - return null; + return undefined; } if (Array.isArray(request.response)) { From 3b719aa216673517780d4fa26b0b8d7a4cfb3bdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zofia=20Go=CC=81ralewska?= Date: Fri, 13 Apr 2018 13:00:16 +0200 Subject: [PATCH 2/2] Remove .idea directiory --- .gitignore | 1 + .idea/vcs.xml | 6 ------ 2 files changed, 1 insertion(+), 6 deletions(-) delete mode 100644 .idea/vcs.xml diff --git a/.gitignore b/.gitignore index 491fc359..8c714771 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules lib +.idea \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7f..00000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file