nicobarray / aquedux

Redux over the wire
46 stars 3 forks source link

Towards the next api for aquedux-server #38

Open nicobarray opened 6 years ago

nicobarray commented 6 years ago

While aquedux-client public API is reworked to match a middleware-centric vue, the aquedux-server public API is still cumbersome to use.

The proposal is to have a Koa/Express middleware for aquedux-server with an all-in-one redux store. This way it will simply fit on existing Node.JS apps (nextjs apps 😏?).

The API could be split into two packages:

The aquedux-server API could look like the new aquedux-client api. The koa-aquedux API could look like:

const Koa = require('koa');
const Router = require('koa-router');
+ const Aquedux = require('koa-aquedux')

+ const reducer = require('./shared/reducer')
+ const middlewares = require('./shared/middlewares')

const app = new Koa();
const router = new Router();
+ const aquedux = new Aquedux(reducer, middlewares, {
+  queueLimit: 0,
+  hydratedActionTypes: [],
+  logLevel: process.env.AQUEDUX_LOG_LEVEL || 'info',
+  routePrefix: '',
+  secret: null,
+  redisHost: undefined,
+  redisPort: undefined,
+  doFragmentSnapshot: prevState => prevState,
+  onConnection: _socket => {},
+  onClose: _socket => {}
+ })

// Here we call the actual koa middleware of type "async (ctx, next)"
+ router.get('/aquedux', aquedux.middleware());

app
  .use(router.routes())
  .use(router.allowedMethods());

Need more thoughts on this, summon @chabou 🎉