Git Product home page Git Product logo

redux-scaffolding's People

Contributors

sizeight avatar

Watchers

 avatar  avatar

Forkers

atlasstrategic

redux-scaffolding's Issues

Allow for nested sorting of elems

e.g. the following elems can be sorted on their author's first_name by providing sortKey = 'author__first_name' to the getSortedElems(elems, sortKey, sortDirection) selector.
Use a double underscore to indicate nesting.

// ...
elems = [
  {
    id: 1,
    author: {
      first_name: 'Charlie',
    },
  },
  {
    id: 2,
    author: {
      first_name: 'Alpha',
    },
  },
  {
    id: 3,
    author: {
      first_name: 'Bravo',
    },
  },
  {
    id: 4,
    author: {
      first_name: 'Delta',
    },
  },
];
// ...

For paginated responses, enhance state with more info

// ...
pagination: {
  count: 115,
  next: 'http://www.xyz.com/api/v1/search/?q=gold&limit=10&offset=10',
  previous: null,
  pageSize: 10, // derived
  pageCount: 12, // derived
  pageNumber: 1, // derived
  pages: [ // derived
    {
      pageNumber: 0,
      active: false,
      params: '?q=gold&limit=10&offset=0',
    },
    // ...
}
// ...

becomes

// ...
pagination: {
  count: 115,
  next: 'http://www.xyz.com/api/v1/search/?q=gold&limit=10&offset=10',
  nextQueryParamsString: '?q=gold&limit=10&offset=10', // useful for react-router
  nextQueryParams: {
    q: 'gold',
    limit: 10,
    offset: 10,
  }, // useful for API fetch calls
  previous: null,
  previousQueryParamsString:
  previousQueryParams:
  pageSize: 10, // derived
  pageCount: 12, // derived
  pageNumber: 1, // derived
  pages: [ // derived
    {
      pageNumber: 0,
      active: false,
      queryParamsString: '?q=gold&limit=10&offset=0',
      queryParams: {
        q: 'gold',
        limit: 10,
        offset, 0,
      },
    },
    // ...
}
// ...

Allow for response to be an object with elements array available as an object field

Default response contains object list in an array like this:

[
  { "id": 1 },
  { "id": 2 },
]

But a response could also be an array iside an object like this:

{
  "facets": [
    { "id": 1 },
    { "id": 2 },
  ],
}

We need to be able to indicate to the reduce on setup where to look for response array.

// in reducer.js
// ...

const initialWidgetsState = Object.assign({} initialState, {
  responseElemsKey: 'facets',
});

const widgets = (state = initialWidgetsState, action) => {
  // ...
};

// ...

Introduce a Loading component

Use only CSS to make this is a more versatile component than the current loading component that requires Font awesome. Good to place it here in redux-scaffolding as it usually is used with API calls.

Allow for extra info to be received and stored in state with response

Most responses are shaped as follows:

[
  { "id": 1 },
  { "id": 2 }
]

But a response can also be inside an object with additional information is attached. In the example 'total_cout` is attached and also needs to be stored in state

{
  "total_count": 205, 
  "results": [
    { "id": 1 },
    { "id": 2 }
  ],
}

Solution: If an optional responseElemsKey is provided to reducer, we should save all siblings to this field in an extraInfo field in state similar to the way pagination info is stored in the pagination field.

Pass sortKey and sortDirection in to getElems selector

react-redux hooks enables us to pass on the sortKey and sortDirection values instead of storing these values in Redux store.

e.g.

const [sortKey, setSortKey] = useState(null);
const [sortDirection, setSortDirection] = useState(null);

function onSetSubscriptionSortKey(newSortKey) {
  if (newSortKey !== sortKey) {
    setSortDirection('asc');
  } else {
    setSortDirection('desc');
  }
  setSortKey2(newSortKey);
}
const subscriptions = useSelector(getSubscriptions, sortKey, sortDirection);

Remove 'credentials': 'include' request property

See the docs for Request.credentials

The credentials read-only property of the Request interface indicates whether the user agent should send cookies from the other domain in the case of cross-origin requests.

Then see the docs for Access-Control-Allow-Credentials

The Access-Control-Allow-Credentials response header tells browsers whether to expose the response to frontend JavaScript code when the request's credentials mode (Request.credentials) is include.

Using this library for cross-origin requests causes the browser to not have access to returned response data if 'credentials': 'include' property is set for requests.
image

For paginated responses, enhance state with more info derived from count, next and previous response values

elems: {
  count: 115,
  next: 'http://www.xyz.com/api/v1/search/?q=gold&limit=10&offset=10',
  previous: null,
  results: [
    // ...
  ],
},

becomes

// ...
pagination: {
  count: 115,
  next: 'http://www.xyz.com/api/v1/search/?q=gold&limit=10&offset=10',
  previous: null,
  pageSize: 10, // derived
  pageCount: 12, // derived
  pageNumber: 1, // derived
  pages: [ // derived
    {
      pageNumber: 0,
      active: false,
      params: '?q=gold&limit=10&offset=0',
    },
    // ...
}
// ...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.