surface v0.1.0-alpha.0 Surface.DataComponent behaviour View Source

Defines a component that serves as a customizable data holder for the parent component.

Example

defmodule Column do
  use Surface.DataComponent

  property title, :string
  property field, :string
end

As you can see, data components don't need to implement a render/1 callback. Instead, this module defines a data/1 callback that you can use to transform, filter or validate properties before sending them to the parent component. By default all properties are sent as they were originally defined.

Link to this section Summary

Callbacks

Implement this callback in order to transform, filter or validate properties before sending them to the parent component.

This optional callback is invoked in order to set up a context that can be retrieved for any descendent component.

Link to this section Callbacks

Link to this callback

data(assigns)

View Source
data(assigns :: map()) :: {:ok, any()}

Implement this callback in order to transform, filter or validate properties before sending them to the parent component.

Link to this callback

init_context(props)

View Source (optional)
init_context(props :: map()) :: map()

This optional callback is invoked in order to set up a context that can be retrieved for any descendent component.