Skip to content
This repository has been archived by the owner on Apr 25, 2018. It is now read-only.

dispatching

Aldwin Vlasblom edited this page Dec 10, 2015 · 3 revisions

Dispatching

When defining your routes micro-framework style:

router.get('it', (req, res) => {
  doAsync(() => {
    moreAsync(it => {
      res.send(it);
    });
  });
});

A router-file can quickly grow large. I therefore like to separate my end-points (the middleware that actually does the responding) into "action" files.

In order to replace the common pattern that arises:

router.get('/it', (req, res, next) => require('actions/it/read')(req, res).fork(next, res.send));

There is framework/dispatch:

import dispatch from '../framework/dispatch';
router.get('/it', dispatch('actions/it/read'));
Clone this wiki locally