View Source Hologram.Component behaviour (hologram v0.3.0)

Summary

Callbacks

Initializes component and server structs (when run on the server).

Returns a template in the form of an anonymous function that given variable bindings returns a DOM.

Functions

Resolves the colocated template path for the given component module given its file path.

Returns the AST of template/0 function definition that uses markup fetched from the give template file. If the given template file doesn't exist nil is returned.

Accumulates the given property definition in props module attribute.

Puts the given action spec to the component or server struct's next_action field. Next action will be executed by the runtime synchronously.

Puts the given action spec to the component or server struct's next_action field. Next action will be executed by the runtime synchronously.

Puts the given command spec to the component's next_command field. Next command will be sent asynchronously to the server.

Puts the given command spec to the component's next_command field. Next command will be sent asynchronously to the server.

Puts the given key-value pair to the component's emitted_context field. Context emitted by a component is available to all of its child nodes.

Puts the given page module to the component's next_page field. The client will navigate to this page asynchronously after the current action finished executing.

Puts the given page module and params to the component's next_page field (as a tuple). The client will navigate to this page asynchronously after the current action finished executing.

Puts the given key-value entries to the component state.

If the second arg is a list of keys representing a component state path it puts the value in the nested component state path, otherwise it puts the given key-value pair to the component state.

Returns the AST of code that registers props module attribute.

Types

t()

@type t() :: %Hologram.Component{
  emitted_context:
    %{required(atom()) => any()} | %{required({module(), atom()}) => any()},
  next_action: Hologram.Component.Action.t() | nil,
  next_command: Hologram.Component.Command.t() | nil,
  next_page: module() | {module(), keyword()},
  state: %{required(atom()) => any()}
}

Callbacks

init(map, t, t)

@callback init(%{required(atom()) => any()}, t(), Hologram.Server.t()) ::
  {t(), Hologram.Server.t()} | t() | Hologram.Server.t()

Initializes component and server structs (when run on the server).

template()

@callback template() :: (map() -> list())

Returns a template in the form of an anonymous function that given variable bindings returns a DOM.

Functions

colocated_template_path(templatable_path)

@spec colocated_template_path(String.t()) :: String.t()

Resolves the colocated template path for the given component module given its file path.

maybe_define_template_fun(template_path, behaviour)

@spec maybe_define_template_fun(String.t(), module()) ::
  Hologram.Compiler.AST.t() | nil

Returns the AST of template/0 function definition that uses markup fetched from the give template file. If the given template file doesn't exist nil is returned.

prop(name, type, opts \\ [])

(macro)
@spec prop(atom(), atom(), Hologram.Commons.Types.opts()) :: Macro.t()

Accumulates the given property definition in props module attribute.

put_action(struct, name_or_spec)

@spec put_action(t() | Hologram.Server.t(), atom() | keyword()) ::
  t() | Hologram.Server.t()

Puts the given action spec to the component or server struct's next_action field. Next action will be executed by the runtime synchronously.

put_action(struct, name, params)

@spec put_action(t() | Hologram.Server.t(), atom(), keyword()) ::
  t() | Hologram.Server.t()

Puts the given action spec to the component or server struct's next_action field. Next action will be executed by the runtime synchronously.

put_command(component, name_or_spec)

@spec put_command(t(), atom() | keyword()) :: t()

Puts the given command spec to the component's next_command field. Next command will be sent asynchronously to the server.

put_command(component, name, params)

@spec put_command(t(), atom(), keyword()) :: t()

Puts the given command spec to the component's next_command field. Next command will be sent asynchronously to the server.

put_context(component, key, value)

@spec put_context(t(), any(), any()) :: t()

Puts the given key-value pair to the component's emitted_context field. Context emitted by a component is available to all of its child nodes.

put_page(component, page_module)

@spec put_page(t(), module()) :: t()

Puts the given page module to the component's next_page field. The client will navigate to this page asynchronously after the current action finished executing.

put_page(component, page_module, params)

@spec put_page(t(), module(), keyword()) :: t()

Puts the given page module and params to the component's next_page field (as a tuple). The client will navigate to this page asynchronously after the current action finished executing.

put_state(component, entries)

@spec put_state(t(), keyword() | map()) :: t()

Puts the given key-value entries to the component state.

put_state(component, keys, value)

@spec put_state(t(), atom() | [atom()], any()) :: t()

If the second arg is a list of keys representing a component state path it puts the value in the nested component state path, otherwise it puts the given key-value pair to the component state.

register_props_accumulator()

@spec register_props_accumulator() :: Hologram.Compiler.AST.t()

Returns the AST of code that registers props module attribute.