# p6-service

## Hooks - The heart of our system

### Types

- `before-global` - Run before all service 
- `before-service` - Run before a service, detect by SID
- `after-service` - Run after a service, , detect by SID
- `after-global` - Run after all service

### How to result of service will be solve?

- Run `before-global` -> `beforeGlobalResult`. `ServiceResult` is `beforeGlobalResult`
- Run `before-service` with latest params is `ServiceResult` -> `beforeServiceResult`. `ServiceResult` is `Object.assign({}, ServiceResult, beforeServiceResult)`
- Run `after-service` with latest params is `ServiceResult` -> `afterServiceResult`. `ServiceResult` is `Object.assign({}, ServiceResult, afterServiceResult)`
- Run `after-global` with **ONE** params is `ServiceResult` -> `afterGlobalResult`. `ServiceResult` is `Object.assign({}, ServiceResult, afterGlobalResult)`
- Return `ServiceResult`

### Break the chain

You cann break the chain of hook by using flag `__break` on your return result.

- `before-global` -> break after run **ALL** `before-global` hooks
- `before-service` -> break after run **ALL** `before-global` and `before-service` hooks
- `handler` -> break after run **ALL** `before-global`, `before-service` hooks an your main `handler`
- `after-service` -> break after run **ALL** `before-global`, `before-service` hooks, your main `handler` and `after-service`
- `after-global` As default mode, your service will run through your handler and all hooks