reduxjs / redux

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

Discussion: Full Stack Redux #313

Closed wmertens closed 9 years ago

wmertens commented 9 years ago

Concept: Redux actions are sent to the web server, over some channel, likely a websocket. The server can also send actions to the browser.

wmertens commented 9 years ago

Some possibilities:

A very similar architecture is what https://github.com/share/ShareJS uses to provide multi-user manipulation of shared state. There are probably important lessons and shareable code there. It would also be simple to embed ShareJS operations into actions for having a subtree of the state shared.

sergey-lapin commented 9 years ago

Maybe this issues are relevant in some way https://github.com/gaearon/redux/issues/211 https://github.com/gaearon/redux/issues/307 I implemented pretty raw syncing stores here, I will publish to npm soon.

wmertens commented 9 years ago

Preliminary conclusions:

gaearon commented 9 years ago

The naive concept of sending all app actions to the server and vice versa, storing the same state in two places, does not seem useful.

I know @elierotenberg has done a lot of experimentation with this. See his work on Nexus Flux. Only the needed state should be synced.

nsisodiya commented 9 years ago

I wrote a detailed blog on Advantage of having Flux on WebWorker. Flux on Server or Webworker work exactly same. communication differs.

nsisodiya commented 9 years ago

I made my first implementation of "Flux inside Webworkers" using "Bridge API" - Bridge API can load your code into webworker - https://github.com/nsisodiya/bl-layer-loader . Its a Communication API. Bridge API load Flux inside Local UI thread for the Browsers which do not support WebWorkers.

nsisodiya commented 9 years ago

Bridge API has Two Adapter - 1) Local 2) postMessageAPI (Web workers) I am trying to write another adapter so can FLUX can work on Server using WebSocket.

jokeyrhyme commented 9 years ago

Could be related to the Netflix Falcor discussion: #560

tiye commented 9 years ago

I started a project called Cumulo exploring similar ideas. The Web Servers are to maintain the store(like an in-memory database), all clients are synced with the server.

In Cumulo, an app is divided into some parts: Database, Store, View, Action.

The data flow is like:

Database --> Stores --> Views
   ^------ Actions ------/

Considering the networks it's like

Database --> Stores(Server) --> WebSocket --> Store(each Client) --> View
   ^--------- Actions --------- WebSocket <--------- Actions ---------/

I name the function from Database to Store expand. It's somehow like what React.render does with Store, but now with Database.

We already knew React is using diff/patch to keep View consistent to its store. And in Cumulo I'm trying to perform JSON diff/patch to keep Stores synced with Database. It's like saying:

Stores are DataViews rendered by Database, and updated with JSON patch, also, over the wire.

Cumulo is currently in very early stage, you may see here if interested: https://github.com/Cumulo And some experiments at https://github.com/Cumulo/immutable-chat/tree/master/src/backend

By the way my current problems are dealing with database backend(raw JSON by now) and merge operation sequences in various orders(due to network delay), and diffing data could be slow(even on immutable data).

gaearon commented 9 years ago

I'm closing this as inactive. Please feel free to continue the discussion. This is not currently on our radar, but I'm happy to see userland developments here.

wmertens commented 9 years ago

Yup, I'm working on a proposal of what a server would look like given a message bus and the Redux architecture…

On Thu, Sep 24, 2015, 14:44 Dan Abramov notifications@github.com wrote:

I'm closing this as inactive. Please feel free to continue the discussion. This is not currently on our radar, but I'm happy to see userland developments here.

— Reply to this email directly or view it on GitHub https://github.com/rackt/redux/issues/313#issuecomment-142917183.

Wout. (typed on mobile, excuse terseness)

quirinpa commented 9 years ago

I would love this from what i understand..

wmertens commented 9 years ago

WiP: https://gist.github.com/wmertens/a408e15a08301081ebad but you get the idea