nicobarray / aquedux

Redux over the wire
46 stars 3 forks source link

feat(client): Middleware-centric public API #36

Closed nicobarray closed 6 years ago

nicobarray commented 6 years ago

This PR fixes #30 and contains the following changes to the public API:

This change is intended to simplify the use of aquedux-client to:

import { applyMiddleware } from 'redux'
import { createStore, createAquedux } from 'aquedux-client'
import reducer from './reducers'

const aquedux = createAquedux({
  hydratedActionTypes: ['ADD_TODO', 'TOGGLE_TODO'],
  endpoint: `http://localhost:3001/aquedux`,
  channels: [ 'todos' ]
})

const store = createStore(reducer, applyMiddleware(aquedux))

As a result the new api contains 2 methods and 5 action creators:

Internally the changes are as follow:

screen shot 2018-05-23 at 11 28 50

This version uses our event hub extensively to decouple the dependency between the store and the client.

The todo and todomvc are updated to match this version.

On the minor changes:

cc @chabou

nicobarray commented 6 years ago

After some test with the todo example, it seems that removing the restart action adds unfortunate behaviours:

To fix this, the router middleware is now called before the channel middleware that handles the internal subscription state AND the router middleware no longer synchronously call next(action) on internal actionTypes. There is no reason to have an exception here (cc @chabou if you see one here)

nicobarray commented 6 years ago

Ready to be merge for me 🐎 (tested on todo and todomvc examples)

chabou commented 6 years ago

Amazing job 🙏