JViewer.Handler behaviour (JViewer v0.1.1) View Source
JViewer.Handler is a way to take control over data processing in situations when data representation depends on runtime information, or simply when you want to process data in your own way.
You can find handlers in JViewer.Handlers, or build a custom handler yourself!
A handler should follow a given behaviuor and implement a function call, which takes super_data as a first argument and params as second argument.
super_data
A handler is always applyed to a field of an object, hence super_data is an object in your data.
Link to this section Summary
Functions
Puts handler in schema's field under path.
Puts handlerparams in schema's field under _path.
Link to this section Types
Link to this section Callbacks
Specs
call(super_data(), params()) :: any()
Link to this section Functions
Puts handler in schema's field under path.
Example
@return_schema object(
fields: [
field(
key: "product",
type: object(
fields: [
...
]
)
)
]
)
As result of calling
put_handler(@return_schema, ["product"], MyApp.ProductHandler)
We will have
object(
fields: [
field(
key: "product",
type: object(
fields: [
...
]
),
handler: MyApp.ProductHandler
)
]
)
Puts handlerparams in schema's field under _path.
Example
@return_schema object(
fields: [
field(
key: "product",
type: object(
fields: [
...
]
),
handler: MyApp.ProductHandler
)
]
)
As result of calling
put_handler_params(@return_schema, ["product"], %{key: "value"})
We will have
object(
fields: [
field(
key: "product",
type: object(
fields: [
...
]
),
handler: MyApp.ProductHandler,
handler_params: %{key: "value"}
)
]
)