reduxjs / redux

A JS library for predictable global state management
https://redux.js.org
MIT License
60.94k stars 15.27k forks source link

Official FAQ #1312

Closed markerikson closed 8 years ago

markerikson commented 8 years ago

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 commented 8 years ago

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.

pedrottimark commented 8 years ago

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 commented 8 years ago

@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:

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 commented 8 years ago

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 commented 8 years ago

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

Performance

Other

Dattaya commented 8 years ago

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

markerikson commented 8 years ago

More ideas:

pci commented 8 years ago

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

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.

gaearon commented 8 years ago

Few questions I recently answered:

markerikson commented 8 years ago

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

markerikson commented 8 years ago

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

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 commented 8 years ago

Wow awesome list :+1:

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 commented 8 years ago

Great stuff :+1:

markerikson commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

@markerikson this is a great list :clap:

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 commented 8 years ago

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.

markerikson commented 8 years ago

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 commented 8 years ago

How to display a modal in Redux:

http://stackoverflow.com/questions/35623656/how-can-i-display-a-modal-dialog-in-redux-that-performs-asynchronous-actions/35641680#35641680

gaearon commented 8 years ago

How to reset the state of a Redux store:

http://stackoverflow.com/questions/35622588/how-to-reset-the-state-of-a-redux-store/35641992#35641992

markerikson commented 8 years ago

@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 commented 8 years ago

I also think there is a lot of questions about authentication with redux, the most frequent ones I tend to note on twitter or github issues are "How to authenticate with JWT and Redux?"

You may have already pointed this out but I skimmed over the comments.

markerikson commented 8 years ago

I've certainly seen a few questions to that effect, but on the flip side, I'm really not sure that's actually a Redux-specific question.

kennetpostigo commented 8 years ago

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

gaearon commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

Okay I'll get to it.

kennetpostigo commented 8 years ago

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

gaearon commented 8 years ago

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

markerikson commented 8 years ago

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 commented 8 years ago

Doing some traveling tomorrow.

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

markerikson commented 8 years ago

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

gaearon commented 8 years ago

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

gaearon commented 8 years ago

How to dispatch different actions depending on the route? http://stackoverflow.com/questions/35665724/with-react-redux-router-how-should-i-access-the-state-of-the-route/35674710#35674710

markerikson commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

PR is an easier way to get feedback :wink: Great job.

markerikson commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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

markerikson commented 8 years ago

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 commented 8 years ago

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

markerikson commented 8 years ago

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?