Periscope (periscope v0.4.6)

Tools for dealing with liveview processes, components, sockets, assigns. Pulls this information directly from the list of BEAM processes.

Link to this section Summary

Functions

Merges maps. If a key has different values in each map, they are aggregated into a list.

Returns a list of liveview module names. Expect to see stuff like MyApp.CustomerWorkflow or some such name. This does NOT list the names of components. Use components/0 for that.

Returns the sockets for all active liveviews in a 0-indexed map. So all_sockets(0) will return the first socket in the map.

Returns the name of your top-level application. This is used by other search functions when they need to find/list modules.

Returns the assigns for the fully-qualified component name, e.g. assigns_for(MyappWeb.MainView.Table) will return the assigns for that component.

Returns a list of active component names. These are module names, so you only see one per module. Even if one component is rendered many times, you will only see its name once. If you want to see how many instances of a component are rendered. use components/0.

Returns a map whose keys are component names (as those found in component_names) and whose values are the assigns for those components.

Takes a route and returns true if it's a route to a liveview module.

liveview_pids returns the PID of every process iff that process contains a liveview.

Will return a list of tuples where the first element of each tuple is the router path that accesses a given liveview and the second element is the name of that liveview. Useful if you want to access a component fast without having to scroll through the router and figure out its URL.

Takes the last part of a schema module name and returns all the fields in that schema. So running schema_fields(Comments) in an app called MyBlog will return all fields for MyBlog.Schemas.Comments. Note that this isn't a string, so you pass in Comments, not "Comments".

Returns a single socket. You can access the assigns using socket.assigns. However, socket.assigns will not show the assigns on the components (see component_names).

as socket/1, but for liveview names.

Link to this section Functions

Link to this function

aggregate_merge(a, b)

Merges maps. If a key has different values in each map, they are aggregated into a list.

examples

Examples

iex> Periscope.aggregate_merge(%{a: 1, b: [2, 3], c: [4]}, %{a: [5, 6], b: 7, c: [8, 9, 10, 11]}) %{a: [1, 5, 6], b: [2, 3, 7], c: [4, 8, 9, 10, 11]}

Link to this function

all_liveviews()

Returns a list of liveview module names. Expect to see stuff like MyApp.CustomerWorkflow or some such name. This does NOT list the names of components. Use components/0 for that.

Returns the sockets for all active liveviews in a 0-indexed map. So all_sockets(0) will return the first socket in the map.

Link to this function

application_name()

Returns the name of your top-level application. This is used by other search functions when they need to find/list modules.

Link to this function

assigns_for(component)

Returns the assigns for the fully-qualified component name, e.g. assigns_for(MyappWeb.MainView.Table) will return the assigns for that component.

Link to this function

component_names()

@spec component_names() :: list()

Returns a list of active component names. These are module names, so you only see one per module. Even if one component is rendered many times, you will only see its name once. If you want to see how many instances of a component are rendered. use components/0.

Note that components have their own assigns. If you want to see the assigns for a component, you can use assigns_for/1.

Link to this function

components_to_assigns()

Returns a map whose keys are component names (as those found in component_names) and whose values are the assigns for those components.

Link to this function

is_a_liveview_route?(route)

Takes a route and returns true if it's a route to a liveview module.

Link to this function

liveview_pids()

liveview_pids returns the PID of every process iff that process contains a liveview.

Link to this function

liveviews_to_paths()

Will return a list of tuples where the first element of each tuple is the router path that accesses a given liveview and the second element is the name of that liveview. Useful if you want to access a component fast without having to scroll through the router and figure out its URL.

Link to this function

schema_fields(schema_module)

Takes the last part of a schema module name and returns all the fields in that schema. So running schema_fields(Comments) in an app called MyBlog will return all fields for MyBlog.Schemas.Comments. Note that this isn't a string, so you pass in Comments, not "Comments".

Link to this function

socket(socket_index \\ 0)

Returns a single socket. You can access the assigns using socket.assigns. However, socket.assigns will not show the assigns on the components (see component_names).

Link to this function

which_liveview(socket_index \\ 0)

as socket/1, but for liveview names.