mobx-spy-logger
Easy to read, customisable mobx events logger based on mobx.spy.
Requirements
This lib has peer dependencies:
mobx
lodash
(I'll try to remove it if it's a problem)
Usage
The logger has "sane" defaults, for a quick start, you just need two lines of code:
mobxSpyLoggerstart
mobxSpyLogger.start() returns a mobx dispose function. You can stop logging this way if needed.
const stopLogging = mobxSpyLoggerstart
options
Select what should be logged:
mobxSpyLoggerstart spyActions: Boolean = true spyComputed: Boolean = true spyUpdates: Boolean = true
options.loggers
Lets you customize the logs. Your logger function will be called with a parsed event.
mobx-spy-logger
parses the useful information from mobx spy events. Then, you can use it however you want.
mobxSpyLoggerstart loggers: { const actor actorId actionName eventArguments isReaction = parsedAction console } { const storeName actorId key newValue = parsedUpdate console } { const actor actorId key = parsedComputed console }
Parsed properties
- actor: is usually the entity that triggered the event, like the store name or an element that was clicked.
- actorId:
mobx-spy-logger
tries to find a unique id on the actor (eg: actor.id), defaults to mobx unique id. - eventArguments: string representation of the action / event arguments when available.
- isReaction: reaction events are also logged as "actions", this flag indicates if it was a reaction.
- key: in an update or computed event, it's the name of the property that was updated.