Hook Tutorial

WARNING! v0.13 was just released, and the tutorial is currently undergoing final testing. It's recommended that you DO NOT follow along until this message is removed (please check back tomorrow).

A tutorial for learning to create your own hooks

Step 3: Specify Dependencies

In this step we're going to specify our hook's dependencies, so we'll have access to the data we need when the hook loads.

You can view the finished code for this step by checking out the step-3 branch.

Hook Dependencies

While some hooks are completely stand-alone, most hooks don't operate that way, and expect certain data (generated by other hooks) to be available by the time that hook loads.

An example of a stand-alone hook is lore-hook-models, which loads the model config files provided in src/models and converts them all to instances of a Model from the lore-models package. Whether this is the first hook that gets loaded or the last doesn't matter.

The actions hook on the other hands expects lore.models to exist before it loads, because it needs those Model classes in order to build the action creators. In other words, the actions hook depends on the models hook.

The bindActions hook is another hook with dependencies, as it's responsibility is to bind every action to thedispatch method of the Redux store. So the bindActions hook depends on both the actions hook and the reduxhook, because it's need the actions to be created first, as well as the Redux store, so that it can perform that binding.

Specify Dependencies

Our hook is going to be responsible for creating a container that will invoke an action on a given interval. In order to do that, we need to make sure the actions are all built (and bound to the Redux store) before we create a polling wrapper around them. This means our hook has a dependency on the bindActions hook.

To specify this dependency, add a reference to the bindActions hook in the dependencies array like this:

...
  dependencies: ['bindActions'],
...

That's it! With the array populated, Lore will figure out which order to load the hooks in based on their dependency chains, and we are guaranteed that our hook will load only after the actions exist and are bound to the Redux store.

Next Steps

Next we're going to make our hook configurable.