Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Official FAQ #1312

Closed
markerikson opened this issue Jan 29, 2016 · 56 comments
Closed

Official FAQ #1312

markerikson opened this issue Jan 29, 2016 · 56 comments

Comments

@markerikson
Copy link
Contributor

I've noticed a LOT of FAQs appearing in Reactiflux, SO, the issues list, etc. Stuff like "sharing state between reducer branches", and "any good-sized Redux examples?", and so on. Is there a good place to create an FAQ list for Redux? Should there be a new page in the docs folder? Add a wiki to this repo? Create a separate repo? I can always go create my own FAQ repo, but figure it's probably worth coordinating with everyone else on this.

@gaearon
Copy link
Contributor

gaearon commented Jan 29, 2016

This would make a great top-level doc entry.
I'm happy to collaborate on this if you take the initiative and gather the common questions.

@gaearon gaearon added the docs label Jan 29, 2016
@pedrottimark
Copy link
Contributor

Here is a resource which starts out a bit negative but has practical advice (for example, use that insight to improve your site’s content) and links to more.

http://alistapart.com/article/infrequently-asked-questions-of-faqs

@markerikson
Copy link
Contributor Author

@pedrottimark , thanks for the pointer.

Throwing together a scratch list of initial possible questions / topics as I skim through the issues list and SO questions:

  • Sharing state between reducers ("Reducer B needs to know state at key 'A')
  • Are there any larger real Redux projects?
  • Why should "type" be a string, or at least serializable?
  • Do I have to put all my state into Redux / should I ever use React's setState()?
  • Do I have to only connect my top-level component? (yes, React-Redux specific, but relevant)
  • Do I have to deep-copy my state? Isn't copying my state going to be slow?
  • Can I / should I create multiple stores?
  • Won't calling "all my reducers" for each action be slow?
  • Should I have 1-1 mappings between reducers and actions?
  • Do I have to use combineReducers?

Related "docs"-tagged issues and assorted discussions:

That's a quick first cut. @gaearon , you've obviously been answering a lot more questions about Redux for longer than anyone else. Any suggestions for topics you'd like to have some centralized answers covered?

@markerikson
Copy link
Contributor Author

In general, a lot of questions seem to be about structuring reducers and areas of responsibility (Redux state vs component state, logic in actions vs logic in reducers). Also storing non-primitives/objects in the state. I know that the "combineReducers" doc page talks about structuring reducers, but perhaps there ought to be a more comprehensive page on that topic?

@Dattaya
Copy link

Dattaya commented Jan 31, 2016

Lots of questions are answered in the docs but I guess it's still good to have a short question--short answer section with links to articles/sections of the docs/discussions.
Few more possible Q&As (draft stage):

Structuring

  • My reducer is too big, how do I subdivide it (related to 'Should I have 1-1 mappings between reducers and actions?')
    • A reducer could be subdivided into subreducers with e.g. reduce-reducers. Subscribing to the same action in more than one reducer is also acceptable and could be used to split reducer into multiple pieces.
  • Where is the best place to keep my selectors?
    • The common practice it to keep them alongside the corresponding reducer.

Performance

  • My selector takes too much time to complete and is called on every update of a component; as a result my app performs poorly. How to solve this problem?

Other

@Dattaya
Copy link

Dattaya commented Jan 31, 2016

Some other things that we can transform into questions if necessary:

  • Dispatch multiple actions as one/receive multiple actions at once: redux-batched-updates, redux-batched-subscribe
  • Alternative to normalizr, lodash/keyBy, might be enough for simple projects if all we need is to transform an array returned from the server into a map id => item: products: keyBy(products, '_id')

@markerikson
Copy link
Contributor Author

More ideas:

  • Can/should the store be referenced be importing it elsewhere in the app, for manually passing down to components and binding actions? Is there a good reason to keep from referencing it directly?
  • Size of the state / "giant objects" / memory usage

@pci
Copy link

pci commented Feb 15, 2016

This is a great idea. Other points you might consider:

  • General guidelines on designing state structure
  • Not really a question, but it would be great to cover that a number of bigger redux projects put the complexity into the selectors, getting started this was something that tripped me up. I guess it comes under the heading of managing a larger project

I'm only just starting out with redux, but if I can be of any help putting these together, even if it's only answering "are these answers non-expert friendly", then I'll be happy to help.

@markerikson
Copy link
Contributor Author

Thanks for the links. I'm hoping to have some time to throw together a first draft sometime this week.

@markerikson
Copy link
Contributor Author

Here's an initial draft outline for the FAQ page:

  • Reducers
    • How do I share state between two reducers?
    • Do I have to use combineReducers?
    • Do I have to use a switch statement to handle actions?
  • Organizing State
    • Do I have to put all my state into Redux? Should I ever use React's setState?
    • Can I put functions, promises, or other non-serializable items in my store state?
    • How do I organize nested/duplicate data in my state?
  • Store Setup
    • Can I / should I create multiple stores?
    • Is it OK to have more than one middleware chain in my store enhancer?
    • How do I subscribe to only a portion of the state?
  • Actions
    • Why should my action types be constants?
    • Why should "type" be a string, or at least serializable?
    • Should I have a 1-1 mapping between reducers and actions?
    • How can I represent "side effects" such as AJAX calls?
    • Should I dispatch multiple actions in a row from one action creator?
  • Code Structure
    • How should I group my actions and reducers in my project?
    • Where should my selectors go?
  • Performance
    • Won't calling "all my reducers" for each action be slow?
    • Do I have to deep-copy my state in a reducer? Isn't copying my state going to be slow?
    • How can I reduce the number of store update events?
    • Will having "one state tree" cause memory problems?
  • React-Redux
    • Why isn't my component re-rendering, or my mapStateToProps running?
    • Why is my component re-rendering too often?
    • How can I speed up my mapStateToProps?
  • Community
    • Are there any larger, "real" Redux projects?

The intent would be to give a reasonably short answer to each question, along with links to further reading. I would also want to write up a full page on structuring reducers, since that seems to be a topic worth a lot more detail.

Would appreciate suggestions, comments, critiques on this list.

@sompylasar
Copy link

Wow awesome list 👍

Tiny note from me:

Actions
Why should "type" be a string, or at least serializable?

I think the whole action objects should be serializable, not just "type".

And there is one more question: if a middleware requires "name", not "type", what should I do? I have this in mind: https://github.com/gajus/redux-convention

@gaearon
Copy link
Contributor

gaearon commented Feb 16, 2016

Great stuff 👍

@markerikson
Copy link
Contributor Author

I will take a thumbs-up from @gaearon as the signal to go ahead :)
I'll start trying to put this together. Progress will be over at https://github.com/markerikson/redux/tree/create-faq-page .

@markerikson
Copy link
Contributor Author

Okay, semi-related issue. Cloned my fork, npm install, npm run docs:prepare, Gitbook installed. Ran npm run docs:build, and got an error:

Template render error: (D:\Projects\redux\docs\basics\ExampleTodoList.md) [Line 143, Column 21]
  expected variable end (In file "docs/basics/ExampleTodoList.md")

Looking at it, it's a code sample that's doing inline styles, and thus has a style={{someObject}} chunk in it. Adding spaces between the curly braces fixed it. Also had the same error in UsageWithReact.md line 123. Fixing both of those allowed Gitbook to build the docs correctly.

Any particular reason why this hasn't noticed and fixed already by someone else? I'd expect it to actually have blocked major edits to the docs.

@markerikson
Copy link
Contributor Author

Argh. Um. One more question: the CONTRIBUTING page says to use typography stuff like smart quotes. I'm trying to follow suit and do so, but the result isn't coming out well. The resulting HTML is coming out as everyone's favorite Unicode diamond question mark characters instead. I've tried copying and pasting the smart quote characters from CONTRIBUTING.md, typing them in manually (I'm on Windows, so ALT+0147/0148), etc. They actually seem to render okay over at http://jbt.github.io/markdown-editor , but not in Gitbook's output. Is there some trick I'm missing to this?

@gaearon
Copy link
Contributor

gaearon commented Feb 17, 2016

Looking at it, it's a code sample that's doing inline styles, and thus has a style={{someObject}} chunk in it. Adding spaces between the curly braces fixed it. Also had the same error in UsageWithReact.md line 123. Fixing both of those allowed Gitbook to build the docs correctly.

Interesting. Maybe a regression in Gitbook?
I am using Gitbook 2.4.3 (specified in book.json). I have plugins resolved like this:

info: install plugin edit-link from npm (gitbook-plugin-edit-link) with version 1.4.2 
info: >> plugin edit-link installed with success 
info: No version specified, resolve plugin prism 
info: install plugin prism from npm (gitbook-plugin-prism) with version 1.0.0 
info: >> plugin prism installed with success 
info: No version specified, resolve plugin github 
info: install plugin github from npm (gitbook-plugin-github) with version 1.1.0 
info: >> plugin github installed with success 

Any particular reason why this hasn't noticed and fixed already by someone else? I'd expect it to actually have blocked major edits to the docs.

Can’t reproduce it.

The resulting HTML is coming out as everyone's favorite Unicode diamond question mark characters instead.

Do you have the same problem on the current docs website?

@markerikson
Copy link
Contributor Author

Yeah, NPM installed Gitbook 2.4.3 here as well.

Looking at redux.js.org, smart quotes render okay in my browser. Looking at the fresh build on my local box, smart quotes render okay in pages such as "Prior Art", but not in the FAQ page I was creating myself. Clearly there's something different about how I'm trying to use them.
I'll try this again tonight.

@gaearon
Copy link
Contributor

gaearon commented Feb 17, 2016

For now, just do as you find convenient (i.e. you can work on FAQ from Github interface, not use smart qoutes, etc). We’ll prettify before merging.

@Dattaya
Copy link

Dattaya commented Feb 20, 2016

@markerikson this is a great list 👏

Actions
Why should "type" be a string, or at least serializable?

I think the whole action objects should be serializable, not just "type".

In the answer we might want to note that an action could be unserializable initially, but should be serializable eventually after it's gone through a middleware chain.

More questions to consider:

@markerikson
Copy link
Contributor Author

Got my initial progress over at https://github.com/markerikson/redux/blob/create-faq-page/docs/FAQ.md . Actual feedback on the content so far would be appreciated :)

@Dattaya : yeah, a couple of items on middleware might be useful also. As for the reducers, that stuff would go into the "Structuring Reducers" page I'm hoping to add as part of this rather than directly into the FAQ list itself.

@gaearon gaearon changed the title FAQ location? Official FAQ Feb 21, 2016
@markerikson
Copy link
Contributor Author

Been busy the last couple nights, so the pace has slowed down to one or two answers written up per evening. But, making progress - 11 questions down, 14 to go at the moment.

@gaearon
Copy link
Contributor

gaearon commented Feb 26, 2016

@gaearon
Copy link
Contributor

gaearon commented Feb 26, 2016

@markerikson
Copy link
Contributor Author

@gaearon , I'd kinda skimmed past your "action in timeout" and "multiple dispatch" answers previously, but just had a chance to look at them again. No kidding, those deserve to be a new docs page right there.

@kennetpostigo
Copy link

Just bringing it up because I see it asked alot and this is a FAQ 😅

@gaearon
Copy link
Contributor

gaearon commented Feb 26, 2016

Just bringing it up because I see it asked alot and this is a FAQ 😅

Agreed.
Here’s a good article: https://auth0.com/blog/2016/01/04/secure-your-react-and-redux-app-with-jwt-authentication/

@markerikson
Copy link
Contributor Author

Sure, valid point, and I have asked for feedback :) I'm not entirely against putting that into the FAQ, but at the moment I would say it's less of a priority because it's not concerned with core Redux behavior. It's also a topic I'm not nearly as familiar with myself. If you or someone else had time to write it up, though, I'd totally take it as a PR against the branch I'm working on in my fork.

@kennetpostigo
Copy link

I would love to help out and do that. Can you make the initial FAQ so I can structure what I put so that it matches with what you are going to write up?

@markerikson
Copy link
Contributor Author

Yep. Re-pasting the link, the current WIP is at https://github.com/markerikson/redux/blob/create-faq-page/docs/FAQ.md . Basic format is a couple paragraphs explaining the answer in general, followed by 3-4 links to relevant Redux docs, issues, SO questions, or other relevant articles.

@kennetpostigo
Copy link

Okay I'll get to it.

@kennetpostigo
Copy link

@markerikson Made some changes you should have received a notification.

@gaearon
Copy link
Contributor

gaearon commented Feb 27, 2016

Difference between Backbone and Redux: https://news.ycombinator.com/item?id=11187727

@markerikson
Copy link
Contributor Author

Yeah, could maybe toss that in along with a "When should I use Redux?" question.

Doing some traveling tomorrow. Will see if I can crank out a few more answers during the trip.

@gaearon
Copy link
Contributor

gaearon commented Feb 27, 2016

Doing some traveling tomorrow.

I read that as “doing some time traveling tomorrow”. 😂

@markerikson
Copy link
Contributor Author

Well, given that I'm crossing a couple time zones, that's not entirely inaccurate... :)

@gaearon
Copy link
Contributor

gaearon commented Feb 27, 2016

This is probably already in the FAQ but I wrote again about combineReducers(): http://stackoverflow.com/a/35674297/458193

@gaearon
Copy link
Contributor

gaearon commented Feb 27, 2016

@markerikson
Copy link
Contributor Author

Still cranking away on this. Got to 14 of 26 questions answered as of this evening, but then added two more to be answered ("When should I use Redux?" and "How many components should I connect?").

If anyone else would like to chip in, PRs still totally welcome :)

@markerikson
Copy link
Contributor Author

Getting there. Spent most of the day on this, and I'm up to 23 of 29 questions complete. Might actually get the initial writeup completed within the next day or two.

@markerikson
Copy link
Contributor Author

And there we go - all current 29 questions in the outline have answers written up.

Can I get some feedback on the current writeup before I submit a PR?

@gaearon
Copy link
Contributor

gaearon commented Mar 7, 2016

PR is an easier way to get feedback 😉
Great job.

@markerikson
Copy link
Contributor Author

Sure. In the interest of keeping the history a bit cleaner, I'll try creating a second branch that has the content, but only one commit (unless you'd rather I just submit the PR as-is)

@gaearon
Copy link
Contributor

gaearon commented Mar 7, 2016

No big deal about it, do anyhow you like. We barely make any source changes at this point so we don’t care much about clean history.

@markerikson
Copy link
Contributor Author

Heh. Well, it's up - #1489.

@markerikson
Copy link
Contributor Author

Related observation: it'd be nice to be able to link directly to certain questions once this is published in the docs. I know you can link to headings in Github Markdown, and Github provides those nice on-hover anchor icons to be able to copy the relative links. I see that Gitbook does add ID tags to headers, such as "#is-there-always-a-1-1-mapping-between-reducers-and-actions", but there's no easy way to copy that. Would adding something like https://github.com/rlmv/gitbook-plugin-anchors to Redux's Gitbook setup be a good idea?

@mkozhukharenko
Copy link

@markerikson, you are doing a great job! I've found a lot of answers and useful links in your FAQ.

@markerikson
Copy link
Contributor Author

So. The core FAQ page is finally published. Per my last comment, it'd be nice if we could get easily-copyable anchors or shortcuts or something. Also up for discussion of further edits and improvements, like adding a ToC or splitting it up into sub-pages.

Thoughts/suggestions?

@gaearon
Copy link
Contributor

gaearon commented Mar 30, 2016

@gaearon
Copy link
Contributor

gaearon commented Apr 2, 2016

The FAQ is great. I think I already see less people asking the same questions. Let’s keep it up as it is for a while. You’re a collaborator so you should be able to reorganize it freely as you see fit. I made some minor stylistic edits in #1567 so if you can maintain those while changing things, it would be rad, but if not, not a big deal 😄 . I very much appreciate your work on this!

@gaearon gaearon closed this as completed Apr 2, 2016
@markerikson
Copy link
Contributor Author

Sure. I'm putting together a Table of Contents right now, with shortened anchors to making linking to each question easier.

One question: per my earlier comments, I had trouble getting smart quotes and other typographical niceties to render properly for some reason. How are you going about entering those?

@gaearon
Copy link
Contributor

gaearon commented Apr 2, 2016

Hmm. I’m usually editing markdown right in my editor and only view the result before publishing.

@markerikson
Copy link
Contributor Author

Right, but how are you actually typing them in? I'm on a Windows box, and tried both copying and pasting smart quotes from other docs files into this one, and also using ALT+somenumber to enter them. The values looked okay in Markdown, but not in the output. Maybe I had my text editor set to a bad codepage or something?

@gaearon
Copy link
Contributor

gaearon commented Apr 2, 2016

I’m on OS X which has different shortcuts. Could it be that you only had problems locally? I think I’ve seen this happen occasionally. Maybe you could try testing them in GitHub Preview. (or in this comment field :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants