jshprentz

jshprentz

Programming Phoenix LiveView B10.0: Some readers do not use VSCode (page 191)

Page 191 shows two screenshots of helpful warning messages about faulty calls to function components. The book explains:

The Elixir Language Server extension in VSCode provides us with these helpful warnings.

This is the first and only mention of VSCode in the book. Some users might not use VSCode. (I use Vim.)

I suggest showing the consequences of the faulty calls when VSCode is not used.

The first survey_live.html.heex example calls the hero component with a content attribute that has an invalid type.

<Component.hero content={123} >
  Please fill out our survey
</Component.hero>

The Phoenix server logs this warning:

warning: attribute "content" in component PentoWeb.SurveyLive.Component.hero/1 must be a :string, got: 123
  lib/pento_web/live/survey_live.html.heex:1: (file)

The survey web page displays the content 123.

The second example calls the hero component without any inner_block content.

<Component.hero content="Survey" />

The Phoenix server logs this error with a stack trace:

** (exit) an exception was raised:
    ** (KeyError) key :inner_block not found in: %{__changed__: nil, __given__: %{__changed__: nil, content: "Survey"}, content: "Survey"}

The web browser displays an error page with the error message, a listing of the hero component, and a stack trace.

It is interesting that Phoenix reports no warning or error when the inner_block content is omitted with either of these representations:

<Component.hero content="Survey" >
</Component.hero>

or

<Component.hero content="Survey" ></Component.hero>

In both cases, the web browser displays a reasonable page with no inner_block content.

The source HTML shows the two header elements of the hero component with the content attribute value and empty inner_block content interpolated:

<h1 class="font-heavy text-3xl">
  Survey
</h1>
<h3>
  
</h3>

Where Next?

Popular Pragmatic Bookshelf topics Top

jimschubert
In Chapter 3, the source for index introduces Config on page 31, followed by more code including tests; Config isn’t introduced until pag...
New
iPaul
page 37 ANTLRInputStream input = new ANTLRInputStream(is); as of ANTLR 4 .8 should be: CharStream stream = CharStreams.fromStream(i...
New
mikecargal
Title: Hands-On Rust (Chapter 11: prefab) Just played a couple of amulet-less games. With a bit of debugging, I believe that your can_p...
New
jdufour
Hello! On page xix of the preface, it says there is a community forum "… for help if your’re stuck on one of the exercises in this book… ...
New
raul
Page 28: It implements io.ReaderAt on the store type. Sorry if it’s a dumb question but was the io.ReaderAt supposed to be io.ReadAt? ...
New
leba0495
Hello! Thanks for the great book. I was attempting the Trie (chap 17) exercises and for number 4 the solution provided for the autocorre...
New
patoncrispy
I’m new to Rust and am using this book to learn more as well as to feed my interest in game dev. I’ve just finished the flappy dragon exa...
New
Charles
In general, the book isn’t yet updated for Phoenix version 1.6. On page 18 of the book, the authors indicate that an auto generated of ro...
New
taguniversalmachine
It seems the second code snippet is missing the code to set the current_user: current_user: Accounts.get_user_by_session_token(session["...
New
New

Other popular topics Top

AstonJ
SpaceVim seems to be gaining in features and popularity and I just wondered how it compares with SpaceMacs in 2020 - anyone have any thou...
New
AstonJ
Curious to know which languages and frameworks you’re all thinking about learning next :upside_down_face: Perhaps if there’s enough peop...
New
AstonJ
I’ve been hearing quite a lot of comments relating to the sound of a keyboard, with one of the most desirable of these called ‘thock’, he...
New
AstonJ
Inspired by this post from @Carter, which languages, frameworks or other tech or tools do you think is killing it right now? :upside_down...
New
PragmaticBookshelf
“Finding the Boundaries” Hero’s Journey with Noel Rappin @noelrappin Even when you’re ultimately right about what the future ho...
New
PragmaticBookshelf
“A Mystical Experience” Hero’s Journey with Paolo Perrotta @nusco Ever wonder how authoring books compares to writing articles?...
New
wmnnd
Here’s the story how one of the world’s first production deployments of LiveView came to be - and how trying to improve it almost caused ...
New
rustkas
Intensively researching Erlang books and additional resources on it, I have found that the topic of using Regular Expressions is either c...
New
PragmaticBookshelf
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New
New

Sub Categories: