Creating our plugin
Creating a Rematch plugin is as easy as creating an object with some properties, as you'll remember from Chapter 8, The Rematch Plugins Ecosystem. Rematch plugins accept certain properties; in this chapter, we're going to use two of them: onModel and createMiddleware.
onModel
The onModel
hook is executed when the whole setup for the model is completed, that is, when the reducers and dispatchers are correctly injected and ready to use. The onModel
hook is executed for each model, allowing us to pick or overwrite values from any model.
In our case, we want to save a cache of each typings
property of each model. This is a required step for our plugin because we'll need to access these typings
properties later to use the plugin in the createMiddleware
hook.
Let's next add to the exposed
property a new property called onModel
:
onModel: (model) => { TYPINGS_CACHE[model.name] = model.typings; }
The TYPINGS_CACHE
variable...