caleb-bb

caleb-bb

Periscope - tools for debugging and introspection

Introducing Periscope, which is meant to save you time when working with LiveView. Version 0.4.4 is published to hex.

(feel free to star the repo if you like it!)

Engineers waste a lot of time tracking down the module for the currently-loaded LiveView. I’ve seen people grab random chunks of HTML out of the inspect and soft-search VS Code for that chunk. I’ve also seen people looking at the URL, and then waste five minutes scrolling through the router just to figure out what module they’re on.

Periscope solves this problem. Import it in your ies.exs and spin up your app locally with iex -S mix phx.server. Then type which_liveview. Voila, you now know which liveview you’re on!

Another big waste of time is sticking IO.inspect into random places in a module just to view the socket. Periscope also solves this problem. Just import it and type socket and hey presto, you can view the socket! The socket function returns a socket struct, so you can treat it as one. That means you can type socket.assign to see your current assigns.

Can’t find the assigns or socket you’re looking for, because the currently loaded page is in a component? No problem. component_names/0 returns a list of all active components, making it easy to find your module. You can even type assigns_for(YourAppWeb.SomeLiveView.SomeChildComponent) and view all of the assigns for SomeChildComponent.

Finding the routes for a component can be a bear as well. mix phx.routes gives you routes and HTTP verbs, but not module names. Finding the routes to a module requires going to the router and scrolling through to piece together the route bit by bit. Periscope solves this problem as well: just type paths_and_liveviews and you’ll get a map where each key is a fully-qualified module name and each value is a list of routes to that module. Easy-peasy.

Most Liked

BartOtten

BartOtten

Yesterday I had to work in a Django/Wagtail codebase I am unfamiliar with and my workflow was exactly as described. Having a tool like Periscope would have made my day much more productive.

Certainly will add this to my next Phoenix app. If not for me (who knows the codebase) then for a fellow dev who might not.

Tnx!

Sebb

Sebb

Indeed. Periscope.socket is instantly helpful.
What do you think about the following feature:

watch_socket_assigns()

On each change of the assigns, shows a diff.

caleb-bb

caleb-bb

Update - now up to version 0.5.6. Fixed a few bugs.

More importantly, introducing a new feature: deep_has_key?/2. Think of it as a version of Map.has_key?/2 that works for nested maps. It’s there because of this: a single socket can have quite a few lines - the webapp I’m currently working on will, if you execute socket, return well over 2000 lines of code. Nobody wants to search all that. deep_has_key?/2 can reach into the socket and assigns and see if a key exists at any point. So if you’re wondering whether client_id (or some such assign) exists in your socket, you can run deep_has_key?(socket, :client_id) and you’ll get a boolean telling you whether that key is anywhere in the socket. It works by flattening the nested maps, taking only the keys, and then searching for the key passed as second arg.

I like this. It will be a little challenging to implement. I’m thinking of spawning a new process and having liveview hooks in the watched socket to notify the watcher whenever the assigns change. If anybody knows a better way, let me know.

Sebb

Sebb

  • maybe change the LV-behaviour, so no change to the user’s code is necessary. (on each assign to the socket, send it to some debug port). This would be a maintenance nightmare, so ideally that would be part of LV. I think it could be argued, that LV would benefit from such a trace-port. Edit: most likely the better idea: use erlang tracing. Set up a process, that get a message (containing the socket) every time socket changes. There should be a point somewhere in the LV-behaviour that is hit always when socket changes.
  • use polling (like repeatedly typing iex> socket)

Where Next?

Popular in Libraries Top

mhanberg
I just released the first version of Temple: an HTML DSL for Elixir and Phoenix! You can read this blog post or the docs for more info...
New
zoltanszogyenyi
Hey everyone :wave: Excited to join this forum - I am one of the founders and current project maintainers of a popular and open-source U...
New
devonestes
Introducing assertions, the library that helps you write really great test assertions! GitHub: https://github.com/devonestes/assertions ...
New
kevinlang
Hey all, We have made an Ecto3 Adapter for SQLite3, ecto_sqlite3! We have successfully on-boarded the full suite of integration tests (...
New
markmark206
simple_feature_flags is a tiny package that lets you turn features on or off based on which environment (e.g. localhost, staging, product...
New
pkrawat1
Presenting Aviacommerce, open source e-commerce platform in Elixir Aviacommerce is an open source e-commerce platform in Elixir. We at...
New
achempion
Hi, I would like to tell about my initiative to further maintain and develop Waffle project which is the fork of Arc library. The progre...
New
Antrater
Hi everyone! I’m thrilled to announce a huge thing. We have been developing Elixir Moon Design System for quite a while. We are finally ...
New
bryanjos
Hi, I just published version 0.23.0 of Elixirscript. Most of the changes are around JavaScript interop now that Elixirscript uses the ...
New
gabrielpoca
Hello everyone! I want to share with you something that I’m really proud of: https://stillstatic.io/ Still is a static site builder for...
New

Other popular topics Top

pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Sub Categories:

We're in Beta

About us Mission Statement