coen.bakker

coen.bakker

Suggestions? Importing JavaScript objects into .hooks.js files (Surface UI)

Recently I have started using Surface UI. The ability to colocate my view/component and its hooks has helped me organize my project better.

AppWeb/Live
|_________ aardvark.ex
|_________ aardvark.sface
|_________ aardvark.hooks.js
|_________ baboon.ex
|_________ baboon.sface
|_________ baboon.hooks.js

I like to keep my .hooks.js files nice and tidy, though. So I would like to be able to import objects from other .js files. For example, by providing the relative path of the .js file (relative to the .hooks.js file). Or by colocation. In the latter case you’d get:

AppWeb/Live
|_________ aardvark.ex
|_________ aardvark.sface
|_________ aardvark.hooks.js
|_________ aardvark.js
|_________ baboon.ex
|_________ baboon.sface
|_________ baboon.hooks.js
|_________ baboon.js

Any advice how to go about implementing this? I will also dive into the code base of Surface to see if I can borrow any solutions from there, but I could use some help looking for a solution in the right direction.

Thank you.

First Post!

code-shoily

code-shoily

I kept my JS files inside assets/js folder and imported them from my hooks components as if that existed inside hooks folder.

Here is an example:

https://github.com/code-shoily/covid19/blob/mafinar/try-out-tailwind/lib/covid19_web/components/crd_pie_chart_component.hooks.js

Notice the location of the hooks.js (colocated) file as opposed to their JS imports (assets/js)

Last Post!

coen.bakker

coen.bakker

I think it would work nicely if I can organize my code as follows, if there is a large amount of lines of code:

AppWeb/Live
|_________ helpers (folder)
|_________ aardvark.ex
|_________ aardvark.sface
|_________ aardvark.css
|_________ aardvark.hooks.js
|_________ aardvark.js

But also being able to use fewer files, if there aren’t as many lines of code.

AppWeb/Live
|_________ helpers (folder)
|_________ aardvark.ex
|_________ aardvark.hooks.js

I’m anticipating the maintenance of large projects. That’s why I’m interested in this topic atm.

By the way, I’m not trying to imply putting all files at the top level of AppWeb/Live, that’s also for argument’s sake only.

Where Next?

Popular in Questions Top

ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
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
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36820 110
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement