Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redesign middleware mechanism #163

Open
leecade opened this issue May 23, 2020 · 1 comment
Open

Redesign middleware mechanism #163

leecade opened this issue May 23, 2020 · 1 comment
Labels

Comments

@leecade
Copy link
Contributor

leecade commented May 23, 2020

Think about the current version vs koa middleware, we've implemented it as an array and it make confusing and chaos here, I think koa middleware is a classic model looks simple and easily to use.

how does it look like

const model = Model(models)

model.use(async (ctx, next) => {
  console.log('1')
  await next()
  console.log('2')
})

model.use(async (ctx, next) => {
  console.log('3')
  await next()
  console.log('4')
})

// 1->3->change state->4->2

It support enhance before and after state change, we should define a middleware interface and provider the most impotant middlewares, no need subscribe api here.

import Model, { middlewares } from 'react-model'
const model = Model(models)

model.use(middlewares.logger())
model.use(middlewares.devTool())

middlewares should works with different model:

const modelA = Model({})
const modelB = Model({})

modelA.use(middlewares.logger())
modelB.use(middlewares.devTool())

const { useStoreA } from modelA
const { useStoreB } from modelB
@leecade
Copy link
Contributor Author

leecade commented May 23, 2020

Don't enable any middleware by default, no one needs to control the order of middleware.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants