hof-behaviour-hooks

1.0.2 • Public • Published

hof-behaviour-hooks

HOF Behaviour enabling lifecycle hooks for extending functionality in main form pipeline.

Usage

With mixwith.js

const mix = require('mixwith').mix;
const Hooks = require('hof-behaviour-hooks');
const BaseController = require('hof-form-controller');
 
class MyController extends mix(BaseController).with(Hooks) {
  ...
}

MyController now extends hof-form-controller and has hof-behaviour-hooks functionality mixed in.

Functionality

The following hooks are currently supported, the methods are GET/POST pipeline methods from hof-form-controller:

GET

  • _getErrors - 'pre-getErrors', 'post-getErrors'
  • _getValues - 'pre-getValues', 'post-getValues'
  • _locals - 'pre-locals', 'post-locals'
  • render - 'pre-render', 'post-render'

POST

  • _process - 'pre-process', 'post-process'
  • _validate - 'pre-validate', 'post-validate'
  • saveValues - 'pre-saveValues', 'post-saveValues'
  • successHandler - 'pre-successHandler', 'post-successHandler'

In field config

fields.js

module.exports = {
  'field-1': {
    hooks: {
      'post-locals': (req, res, next) => {
        Object.assign(res.locals, {
          foo: 'bar'
        });
        next();
      },
      'pre-process': (req, res, next) => {
        req.body['field-1'] = req.body['field-1'].toUpperCase();
        next();
      }
    }
  }
}

/hof-behaviour-hooks/

    Package Sidebar

    Install

    npm i hof-behaviour-hooks

    Weekly Downloads

    8

    Version

    1.0.2

    License

    MIT

    Last publish

    Collaborators

    • temitopeayoku
    • mdev246
    • vinodha.s
    • chisomoguibe
    • robertmccann
    • rhyad-zergane-ho
    • rhodine
    • mohameduwais
    • lennym
    • easternbloc
    • joefitter
    • coupey
    • sulthan-ahmed
    • andrew.moody.ho
    • aswann
    • robertdeniszczyc2
    • agraham19
    • aaron.robinson
    • sarahjaneluff
    • cmedland
    • hof-bot-user