Reference 〉 Function

Hooks.add(namestr, functionfunc(mixed), prioritizeboolFalse)

Inserts a function into designated places in the model’s logic. See the Hooks Reference for a complete list of possible hooks and the function signatures necessary to use them.

This method is aliased by the @model.hook function decorator, which is the preferred way to hook functions.

Parameters

  • name str, required

    The name of the hook in which to insert the function.

  • function func(mixed), required

    The function to be hooked in place. The function's signature will depend on the hook. See the Hooks Reference.

  • prioritize bool, optional

    Run the hook before all existing hooks in the queue. Note this parameter does not affect the position of the hook with respect to future functions added to the same hook.

    Default value: False

Notes and Examples

  1. charwick

    Aug 06, 2020 at 3:43

    This snippet hooks the defined function into the modelStep hook. It is equivalent to decorating the function with @heli.hook('modelStep') at the top.

    from helipad import Helipad
    heli = Helipad()
    
    def modelStepFunc(model, stage):
    	#This function will run at each stage of each step of the model
    	pass
    heli.hooks.add('modelStep', modelStepFunc)
  2. Contribute a Note

    Your email address will not be published. Required fields are marked *

    You may use limited HTML for formatting. Please embed blocks of code in <pre><code> </code></pre> tags.

History