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

Cleaning up the generator action interface #346

Open
nhunzaker opened this issue Jun 14, 2017 · 1 comment
Open

Cleaning up the generator action interface #346

nhunzaker opened this issue Jun 14, 2017 · 1 comment

Comments

@nhunzaker
Copy link
Contributor

Generator actions are quickly becoming my favorite form of writing actions:

function createUserFlow (params) {
  return function * (repo) {
    yield repo.push(validate, params)

    let user = yield repo.push(createUser, '/users')

    yield repo.push(navigate, '/users/' + user.id)
  }
}

This feels heavy. I wonder if we could clean this up by adding a layer of abstraction:

// 1. A general "send" helper, where you don't need to know about the repo at all
import { send } from 'microcosm'

// 2. Actions themselves can be generators, not just returning a function
function * createUserFlow (params) {
  yield send(validate, params)

  let user = yield send(createUser, '/users')

  yield send(navigate, '/users/' + user.id)
}

Under the hood, send might do something like:

function send (action, ...params) {
  return repo => repo.push(action, ...params)
}

We'd pass repo to the action inside of Microcosm.

@efatsi
Copy link
Contributor

efatsi commented Jun 14, 2017

seems like a good idea to me

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

No branches or pull requests

2 participants