Cartograph.LiveViewParams (Cartograph v0.2.0)

View Source

This module provides integration with the Cartograph navigation events for a LiveView process.

To enable cartograph patch and navigate events, simply use Cartograph.LiveViewParams from a LiveView module.

This will also add a @cartograph_uri key to the assigns. This key will always contain the current URI from the latest call to Phoenix.LiveView.handle_params/3.

The LiveViewParams module also provides some conveniences for reducing boilerplate related to Phoenix.LiveView.handle_params/3.

See the documentation for __using__/1 for available options.

See the api documentation for Cartograph.Component for how to send patch and navigation events to the using LiveView.

Summary

Functions

Adds cartograph event handling to a LiveView.

Functions

__using__(opts \\ [])

(macro)

Adds cartograph event handling to a LiveView.

use Cartograph.LiveViewParams,
  cartograph_parser: true,
  handle_params: false,

Options

  • :cartograph_parser - if true (default: true) then run any parsing handlers defined with the @cartograph_parser module attribute on the using LiveView.

  • :handle_params - if true (default: false) then add a default implementation of Phoenix.LiveView.handle_params/3. Useful when using :cartograph_parser to parse the params.

Important

The LiveViewParams must be used AFTER the LiveView behavior or the on_mount/1 hook that sets up the param parsing will not be registered. This is needed even if :cartograph_parser is false because cartograph adds the @cartograph_uri assign to allow relative query patching.

Good:

use Phoenix.LiveView
use Cartograph.LiveViewParams

Bad:

use Cartograph.LiveViewParams
use Phoenix.LiveView