Search documentation of mob

# Mob.Registry (mob v0.6.18)

Copy Markdown View Source

Maps component names (atoms) to their platform-specific NIF constructors.

Each entry maps a component name to a per-platform tuple: `{nif_module, function_name, extra_args}`.

## Example

    Mob.Registry.register(MyReg, :map_view,
      android: {:mob_nif, :create_map_view, []},
      ios:     {:mob_nif, :create_map_view, []}
    )

    {:ok, {mod, fun, args}} = Mob.Registry.lookup(MyReg, :map_view, :android)
    apply(mod, fun, args)

## Default registry

`Mob.Registry` itself is started by the Mob application and pre-populated with the built-in component vocabulary. Third-party packages call `Mob.Registry.register/3` in their `Application.start/2`.

## Summary

### Functions

all(registry \\ __MODULE__)

List all registered component names.

child_spec(arg)

Returns a specification to start this module under a supervisor.

lookup(registry \\ __MODULE__, name, platform)

Look up the NIF spec for a component on a given platform.

register(registry \\ __MODULE__, name, mappings)

Register a component name with platform-specific NIF constructors.

start_link(opts \\ [])

Start a registry Agent.

## Functions

# all(registry \\ __MODULE__)

    @spec all(GenServer.server()) :: [atom()]

List all registered component names.

# child_spec(arg)

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# lookup(registry \\ __MODULE__, name, platform)

    @spec lookup(GenServer.server(), atom(), atom()) ::
      {:ok, {module(), atom(), list()}} | {:error, :not_found}

Look up the NIF spec for a component on a given platform.

Returns `{:ok, {mod, fun, args}}` or `{:error, :not_found}`.

# register(registry \\ __MODULE__, name, mappings)

    @spec register(GenServer.server(), atom(), keyword()) :: :ok

Register a component name with platform-specific NIF constructors.

`mappings` is a keyword list of `platform: {mod, fun, args}` entries. Calling register again for an existing name merges/overwrites platforms.

# start_link(opts \\ [])

    @spec start_link(keyword()) :: Agent.on_start()

Start a registry Agent.

Pass `name: nil` for an anonymous registry (useful in tests). Pass `name: Mob.Registry` for the global application registry.