Git Product home page Git Product logo

combine-reducers's Issues

Spread operator does not work

case "ADD_AUTHOR": return { ...state, authors: [...state.authors, action.author] };

Here, you are copying over the properties that are not changing(i,.e., books) but the spread operator does not work in this case. The books property will still have a reference to the array exists in the old state. You could do something like this:

case "ADD_AUTHOR": return { ...state, books: [...state.books], authors: [...state.authors, action.author] };

Code Snippets have no File/Folder locations

Hi there,

Just wanted to pass this along, I noticed in this code along its quite difficult to understand where these code changes are going and being implemented when the snippets themselves don't have any of the file paths at the top for reference.

I hope this could be useful to cohort members in the future! :)

Sincerely,
MD

no repo to download?

This lab feels lazily done - There should be a code repo for students to follow along with. Why not also update the lab so that the code doesn't "have a bug in it."

Incorrect sample code

Hello! In the initial combined reducer, I think the following:

case "REMOVE_AUTHOR":
  idx = state.authors.indexOf(action.id);
  return {
    ...state,
    authors: [state.authors.slice(0, idx), state.authors.slice(idx + 1)]
  };

should be:

case "REMOVE_AUTHOR":
  idx = state.authors.indexOf(action.id);
  return {
    ...state,
    authors: [...state.authors.slice(0, idx), ...state.authors.slice(idx + 1)]
  };

else the function returns an array for authors that consists of 2 arrays (one for the first slice and one for the second) instead of a single array.

Same goes for the REMOVE_BOOK code. Thanks!

Mismatch variable names in last code snippet

Dispatch code in paragraph before last code snippet is:

store.dispatch({ action: 'ADD_BOOK', book: { title: 'huck finn', **authorName**: 'Mark Twain' } });

then in last code snippet, authorsReducer/case 'ADD_BOOK'

      let existingAuthor = state.filter(author => author.name === **action.author.name**)
      if(!existingAuthor) {
        return state.concat(action.author);
      } else {
        return state
      }```

Object.assign is mutating the existing 'state' object

In many examples a pattern like this is used:

case "ADD_BOOK":
  return Object.assign(state, {
    books: state.books.concat(action.book)
});

However, this modifies the existing state object which is bad practice. Object.assign should take an empty object as its first parameter (e.g. Object.assign({}, state, { ...) so that existing state remains un-mutated.

Stray asterisks in this paragraph

Replace the first asterisk with an underscore, and the second asterisked word should just be in italics, with no preceding underscore:
"In the new "ADDBOOK" case, we're checking to see if an authorName matches with the name dispatches from the BookInput component. If the name already exists, state is returned unchanged. If the name is not present, it is added to the author array. Use the example above to modify the manageAuthorsAndBooks reducer and you can see the effect. We have two separate forms, one for adding just authors, and one that adds books _and authors."

Thank you.

Confusing Structure

Code snippets for booksReducer and authorsReducer should mention that they are still in the same manageAuthorsAndBooks .js file. There were no ellipses in the code blocks so I assumed that they were newly created files.

Reducer File Missing uuid Function

During the rewrite of the the manageAuthorsAndBooks file, when adding the "ADD_BOOK" case to the authorsReducer, they make use of the uuid() function even though it was never introduced or imported.

This can be solved by adding this import:

import uuid from 'uuid'

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.