jtormey
Hello!
Having written a lot of LiveView code, I’ve made some VS Code snippets to speed up writing callbacks for LiveViews and LiveComponents. I thought I’d share here in case anyone finds them useful, and to see if others have have their own snippets to share.
Guide on creating snippets here: Snippets in Visual Studio Code
And the snippets:
{
"LiveView mount callback": {
"prefix": "lv_mount",
"body": [
"def mount(${1:_params}, ${2:_session}, socket) do",
"\t{:ok, socket$0}",
"end"
]
},
"LiveView handle_params callback": {
"prefix": "lv_params",
"body": [
"def handle_params(${1:params}, ${2:_uri}, socket) do",
"\t{:noreply, socket$0}",
"end"
]
},
"LiveView handle_info callback": {
"prefix": "lv_info",
"body": [
"def handle_info($1, socket) do",
"\t{:noreply, socket$0}",
"end"
]
},
"LiveView (or LiveComponent) handle_event callback": {
"prefix": "lv_event",
"body": [
"def handle_event(\"$1\", ${2:_params}, socket) do",
"\t{:noreply, socket$0}",
"end"
]
},
"LiveView (or LiveComponent) render callback": {
"prefix": "lv_render",
"body": [
"def ${1:render}(assigns) do",
"\t~H\"\"\"",
"\t$0",
"\t\"\"\"",
"end"
]
},
"LiveComponent mount callback": {
"prefix": "lc_mount",
"body": [
"def mount(socket) do",
"\t{:ok, socket$0}",
"end"
]
},
"LiveComponent update callback": {
"prefix": "lc_update",
"body": [
"def update(assigns, socket) do",
"\t{:ok, socket$0}",
"end"
]
},
"LiveComponent preload callback": {
"prefix": "lc_preload",
"body": [
"def preload(list_of_assigns) do",
"\tlist_of_assigns$0",
"end"
]
}
}
Maybe this would be useful as an addition to one of the Elixir VS Code packages out there?
Trending in Guides/Tuts
# ~/src/livebook/.iex.exs
System.cmd("xdg-open", [ LivebookWeb.Endpoint.access_url() ] )
Because Livebook requires a unique passcode on ...
New
You probably already know that <span>{nil}</span> in a HEEX template produces <span> </span> when rendered. I fin...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 2- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
AdamR
Live view scaffold. It populates module name based on the file name and path. Easily adjustable for components so eg, you can have lvc for live view component. If you’re not a fun of render in the same file, just remove it.
Will produce
blakedietz
If you like this you might find my plugin of use: Phoenix LiveView snippets - Visual Studio Marketplace