From 43a4d55aa2ed856441ca7f9d1c238309e8d5503c Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Thu, 23 Feb 2017 12:02:01 +0200 Subject: [PATCH] Add selector for listings --- src/ducks/sdk.duck.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/ducks/sdk.duck.js b/src/ducks/sdk.duck.js index eae6302f..2150f956 100644 --- a/src/ducks/sdk.duck.js +++ b/src/ducks/sdk.duck.js @@ -1,6 +1,6 @@ /* eslint-disable no-constant-condition, no-console */ import { call, put, take, fork } from 'redux-saga/effects'; -import { updatedEntities } from '../util/data'; +import { updatedEntities, denormalisedEntities } from '../util/data'; const requestAction = actionType => params => ({ type: actionType, payload: { params } }); @@ -96,24 +96,44 @@ export default function sdkReducer(state = initialState, action = {}) { } } +// ================ Selectors ================ // + +/** + * Get the denormalised listing entities with the given IDs + * + * @param {Object} data the state part of the Redux store for this SDK reducer + * @param {Array} listingIds listing IDs to select from the store + */ +export const getListingsById = (data, listingIds) => + denormalisedEntities(data.entities, 'listing', listingIds); + // ================ Action creators ================ // +// All the action creators that don't have the {Success, Error} suffix +// take the params object that the corresponding SDK endpoint method +// expects. + +// SDK method: listings.show export const showListings = requestAction(SHOW_LISTINGS_REQUEST); export const showListingsSuccess = successAction(SHOW_LISTINGS_SUCCESS); export const showListingsError = errorAction(SHOW_LISTINGS_ERROR); +// SDK method: listings.query export const queryListings = requestAction(QUERY_LISTINGS_REQUEST); export const queryListingsSuccess = successAction(QUERY_LISTINGS_SUCCESS); export const queryListingsError = errorAction(QUERY_LISTINGS_ERROR); +// SDK method: listings.search export const searchListings = requestAction(SEARCH_LISTINGS_REQUEST); export const searchListingsSuccess = successAction(SEARCH_LISTINGS_SUCCESS); export const searchListingsError = errorAction(SEARCH_LISTINGS_ERROR); +// SDK method: marketplace.show export const showMarketplace = requestAction(SHOW_MARKETPLACE_REQUEST); export const showMarketplaceSuccess = successAction(SHOW_MARKETPLACE_SUCCESS); export const showMarketplaceError = errorAction(SHOW_MARKETPLACE_ERROR); +// SDK method: users.show export const showUsers = requestAction(SHOW_USERS_REQUEST); export const showUsersSuccess = successAction(SHOW_USERS_SUCCESS); export const showUsersError = errorAction(SHOW_USERS_ERROR);