withHooks Factory

Produce a route object that specifies both an enter and an exit hook given either a function to be used as the sole "enter" hook, or an object that defines one or both hooks.

import { withHooks } from 'page-fu';

assertHasBothHooks(withHooks(function myEnter(ctx, next) {}))
assertHasBothHooks(withHooks({ enter() {} }))
assertHasBothHooks(withHooks({ exit() {} }))

function assertHasBothHooks(route) {
  console.assert(typeof route === 'object')
  console.assert(typeof route.enter === 'function')
  console.assert(typeof route.exit === 'function')
}

Instance Constructor

withHooks(spec: Function|Object) -> Object

Parameters (1)

spec
Function|Object

Return Values

route
Object
route.enter
Function
route.exit
Function

Instance Methods

    enter(ctx: page.Context, next: Function)

    The enter routine that gets called when the route is activated.

    Parameters (2)

    ctx
    page.Context
    next
    Function

    Call this if you do not want to activate the route and instead forward to the next one.

    exit(ctx: page.Context, next: Function)

    The routine that gets called when the route is about to become deactivated.

    Parameters (2)

    ctx
    page.Context

    page.js context object.

    next
    Function

    Function to invoke when you're done cleaning up. If you do not call this, the route will never be exited.