concept project in category react

This is an excerpt from Manning's book Redux in Action.
Unlike Reflux, Alt stays true to the original Flux ideas and uses the Flux Dispatcher. Alt’s selling points are its adherence to the Flux architecture and a reduction in boilerplate code. Although it once enjoyed an enthusiastic community, at the time of writing, there have been no commits to the project in more than six months.
Listing 8.5 is a look at the desired store structure. You’ll use this structure as a guide to create any actions you need (including payloads) and to create a particular reducer structure. Keep an eye on three things: adding a new top-level projects property, nesting tasks within each project, and the addition of a new top-level page property for storing currentProjectId. Note that you moved and renamed the search filter portion of your state. It’s common to have UI state live in a different part of the tree as you add more typical application state such as projects and tasks. As a result, you renamed the property from searchTerm to tasksSearchTerm, because searchTerm is too generic, given that this piece of state isn’t living directly under tasks.
You can now switch between projects by choosing from the drop-down menu. The role of the App component is varied at this point. It needs to get the right data from Redux, render any children, and implement small wrappers around action dispatches. Its purpose could be described as orchestrator. This is fine for the time being, but it’s something to keep an eye on. If this component becomes too bloated, Parsnip could become more difficult to maintain.
At this point, you have two major pieces of functionality left to update: creating and updating tasks. Loading initial projects data was relatively straightforward. Projects as returned from the API are already in a shape that’s friendly to render. All you needed to do was load the data into the store, adjust part of the code that connects Redux and React, and everyone’s happy.
With creating tasks, you’ll get your first taste of making updates to nested data. To fetch projects, you threw an entire API response directly in the store. Now you need to pluck out individual tasks and operate on them, which won’t be as easy.
With projects, you need one additional step: finding the project that the task belongs to. You first use the projectId from the task as part of the action payload to find the project that you need to update. In the following listing, you start to see real shortcomings with storing lists of objects in an array.
Listing 8.21. Updating the projects reducer – src/reducers/index.js
export function projects(state = initialState, action) { switch (action.type) { ... case 'CREATE_TASK_SUCCEEDED': { const { task } = action.payload; const projectIndex = state.items.findIndex( #1 project => project.id === task.projectId, #1 ); #1 const project = state.items[projectIndex]; #1 const nextProject = { #2 ...project, #2 tasks: project.tasks.concat(task), #2 }; #2 return { ...state, #3 items: [ #3 ...state.items.slice(0, projectIndex), #3 nextProject, #3 ...state.items.slice(projectIndex + 1), #3 ], }; } ... } } #1 Finds the right project to update #2 Merges the new tasks array into the project #3 Inserts the updated project at the correct place in the array !@%STYLE%@! {"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":5,\"ch\":54},{\"line\":5,\"ch\":56}],[{\"line\":6,\"ch\":54},{\"line\":6,\"ch\":56}],[{\"line\":7,\"ch\":54},{\"line\":7,\"ch\":56}],[{\"line\":8,\"ch\":54},{\"line\":8,\"ch\":56}],[{\"line\":28,\"ch\":0},{\"line\":28,\"ch\":2}],[{\"line\":5,\"ch\":54},{\"line\":5,\"ch\":56}],[{\"line\":6,\"ch\":54},{\"line\":6,\"ch\":56}],[{\"line\":7,\"ch\":54},{\"line\":7,\"ch\":56}],[{\"line\":8,\"ch\":54},{\"line\":8,\"ch\":56}],[{\"line\":28,\"ch\":0},{\"line\":28,\"ch\":2}],[{\"line\":5,\"ch\":54},{\"line\":5,\"ch\":56}],[{\"line\":6,\"ch\":54},{\"line\":6,\"ch\":56}],[{\"line\":7,\"ch\":54},{\"line\":7,\"ch\":56}],[{\"line\":8,\"ch\":54},{\"line\":8,\"ch\":56}],[{\"line\":28,\"ch\":0},{\"line\":28,\"ch\":2}],[{\"line\":5,\"ch\":54},{\"line\":5,\"ch\":56}],[{\"line\":6,\"ch\":54},{\"line\":6,\"ch\":56}],[{\"line\":7,\"ch\":54},{\"line\":7,\"ch\":56}],[{\"line\":8,\"ch\":54},{\"line\":8,\"ch\":56}],[{\"line\":28,\"ch\":0},{\"line\":28,\"ch\":2}],[{\"line\":10,\"ch\":54},{\"line\":10,\"ch\":56}],[{\"line\":11,\"ch\":54},{\"line\":11,\"ch\":56}],[{\"line\":12,\"ch\":54},{\"line\":12,\"ch\":56}],[{\"line\":13,\"ch\":54},{\"line\":13,\"ch\":56}],[{\"line\":29,\"ch\":0},{\"line\":29,\"ch\":2}],[{\"line\":10,\"ch\":54},{\"line\":10,\"ch\":56}],[{\"line\":11,\"ch\":54},{\"line\":11,\"ch\":56}],[{\"line\":12,\"ch\":54},{\"line\":12,\"ch\":56}],[{\"line\":13,\"ch\":54},{\"line\":13,\"ch\":56}],[{\"line\":29,\"ch\":0},{\"line\":29,\"ch\":2}],[{\"line\":10,\"ch\":54},{\"line\":10,\"ch\":56}],[{\"line\":11,\"ch\":54},{\"line\":11,\"ch\":56}],[{\"line\":12,\"ch\":54},{\"line\":12,\"ch\":56}],[{\"line\":13,\"ch\":54},{\"line\":13,\"ch\":56}],[{\"line\":29,\"ch\":0},{\"line\":29,\"ch\":2}],[{\"line\":10,\"ch\":54},{\"line\":10,\"ch\":56}],[{\"line\":11,\"ch\":54},{\"line\":11,\"ch\":56}],[{\"line\":12,\"ch\":54},{\"line\":12,\"ch\":56}],[{\"line\":13,\"ch\":54},{\"line\":13,\"ch\":56}],[{\"line\":29,\"ch\":0},{\"line\":29,\"ch\":2}],[{\"line\":16,\"ch\":54},{\"line\":16,\"ch\":56}],[{\"line\":17,\"ch\":54},{\"line\":17,\"ch\":56}],[{\"line\":18,\"ch\":54},{\"line\":18,\"ch\":56}],[{\"line\":19,\"ch\":54},{\"line\":19,\"ch\":56}],[{\"line\":20,\"ch\":54},{\"line\":20,\"ch\":56}],[{\"line\":30,\"ch\":0},{\"line\":30,\"ch\":2}],[{\"line\":16,\"ch\":54},{\"line\":16,\"ch\":56}],[{\"line\":17,\"ch\":54},{\"line\":17,\"ch\":56}],[{\"line\":18,\"ch\":54},{\"line\":18,\"ch\":56}],[{\"line\":19,\"ch\":54},{\"line\":19,\"ch\":56}],[{\"line\":20,\"ch\":54},{\"line\":20,\"ch\":56}],[{\"line\":30,\"ch\":0},{\"line\":30,\"ch\":2}],[{\"line\":16,\"ch\":54},{\"line\":16,\"ch\":56}],[{\"line\":17,\"ch\":54},{\"line\":17,\"ch\":56}],[{\"line\":18,\"ch\":54},{\"line\":18,\"ch\":56}],[{\"line\":19,\"ch\":54},{\"line\":19,\"ch\":56}],[{\"line\":20,\"ch\":54},{\"line\":20,\"ch\":56}],[{\"line\":30,\"ch\":0},{\"line\":30,\"ch\":2}],[{\"line\":16,\"ch\":54},{\"line\":16,\"ch\":56}],[{\"line\":17,\"ch\":54},{\"line\":17,\"ch\":56}],[{\"line\":18,\"ch\":54},{\"line\":18,\"ch\":56}],[{\"line\":19,\"ch\":54},{\"line\":19,\"ch\":56}],[{\"line\":20,\"ch\":54},{\"line\":20,\"ch\":56}],[{\"line\":30,\"ch\":0},{\"line\":30,\"ch\":2}],[{\"line\":16,\"ch\":54},{\"line\":16,\"ch\":56}],[{\"line\":17,\"ch\":54},{\"line\":17,\"ch\":56}],[{\"line\":18,\"ch\":54},{\"line\":18,\"ch\":56}],[{\"line\":19,\"ch\":54},{\"line\":19,\"ch\":56}],[{\"line\":20,\"ch\":54},{\"line\":20,\"ch\":56}],[{\"line\":30,\"ch\":0},{\"line\":30,\"ch\":2}]]"} !@%STYLE%@!The immutability restriction of reducers enables great features within Redux, such as time travel, but it can make updating nested data structures harder. Instead of modifying a project’s task array in place, you must take care to always create new copies of objects. Using arrays to store lists of objects makes this extra problematic, because you have to loop through the entire list to find the project you’d like to work with.

This is an excerpt from Manning's book React Quickly: Painless web apps with React, JSX, Redux, and GraphQL.
Let’s explore your first React code—the quintessential example used for learning programming languages—the Hello World application. (If we don’t do this, the gods of programming might punish us!) You won’t be using JSX yet, just plain JavaScript. The project will print a “Hello world!!!” heading (<h1>) on a web page. Figure 1.4 shows how it will look when you’re finished (unless you’re not quite that enthusiastic and prefer a single exclamation point).
The project in this chapter focuses mainly on demonstrating how to use React Router, some ES6 features, and Webpack. In this project, you’ll build a simple e-commerce storefront for a bookstore (figure 18.1).
That’s all for the bookstore. You’ve used some ES6 features and passed around states with React Router. Now, run the project by building it with npm run build, starting a local web server (WDS or node-static), and navigating to http://localhost:8080/nile, assuming you have a static web server running in a parent folder that has a nile folder (the URL path depends on where you launched the static web server).