voby / chatte

Simple chat on Redux + socket.io
20 stars 5 forks source link

Reducer not returing state #1

Closed barrystaes closed 8 years ago

barrystaes commented 8 years ago

I understand this is old code using old versions. I'm new to redux, and i wonder what you are doing at this line.

https://github.com/voby/chatte/blob/ef4c197b2d1883c913848273970d1df72f79e6d8/src/stores/ChatteStore.js#L8

Shouldn't it return / keep the state?

voby commented 8 years ago

Hi, there!

You're right, it's a very old example. Especially for javascript-world.

But code is ok. You can think about this action like 'fetch history of messages' and it calls only once on init.

https://github.com/voby/chatte/blob/master/server.js#L30 https://github.com/voby/chatte/blob/master/src/App.js#L12

This app is very simple and intial state is actualy just an array. So you don't need to merge anything on that step.

In other (more complicated) apps you should use something like this in your reducer('store' in this app, they renamed it).

return [...state, newInfo];