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

Specs

params() :: any()

Specs

super_data() :: map()

Link to this section Callbacks

Link to this callback

call(super_data, params)

View Source

Specs

call(super_data(), params()) :: any()

Link to this section Functions

Link to this function

put_handler(return_schema, path, handler)

View Source

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
      )
    ]
  )
Link to this function

put_params(return_schema, path, params)

View Source

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"}
      )
    ]
  )