Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a `--live` flag to generate a LiveView enabled phoenix project #3376

Open
wants to merge 3 commits into
base: master
from

Conversation

@aforward
Copy link
Contributor

aforward commented Apr 16, 2019

THIS IS A PROOF OF CONCEPT WITH SEVERAL OPEN QUESTIONS.
Other refactors might need to happen first, and then
will be rebased into this work. I wanted to get the ball rolling,
so here goes.

By running something like

mix phx.new hello_phoenix --no-ecto --live

Then, when you run the app

mix phx.server

You get an example of a LiveView generated page

Screen Shot 2019-04-16 at 8 17 55 AM

This is a follow up to:

#3371

pubsub: [name: <%= web_namespace %>.PubSub, adapter: Phoenix.PubSub.PG2]<%= if live do %>,
live_view: [
signing_salt: "<%= live_view_signing_salt %>"
]<% end %>

This comment has been minimized.

Copy link
@aforward

aforward Apr 16, 2019

Author Contributor

There was a suggestion to remove the separate live_view signing_salt. That will require more coordination between the two projects (and clarification that it's OK to proceed with that route). For now, I have the code generated based on the instructions

use <%= web_namespace %>, :controller

def index(conn, _params) do
Phoenix.LiveView.Controller.live_render(conn, <%= web_namespace %>.PageLiveView, session: %{})

This comment has been minimized.

Copy link
@aforward

aforward Apr 16, 2019

Author Contributor

To simplify this to just be live_render(...), we need to also import the controller helper function

  def controller do
    quote do
      ...
      # Import convenience functions for LiveView rendering
      import Phoenix.LiveView.Controller, only: [live_render: 3]

       ...
    end
  end

I didn't see this explicitly in the instructions, wasn't sure if that was on purpose or not.

This comment has been minimized.

Copy link
@josevalim

josevalim Apr 30, 2019

Member

We should import it, yes!

pubsub: [name: <%= app_module %>.PubSub, adapter: Phoenix.PubSub.PG2]<%= if live do %>,
live_view: [
signing_salt: "<%= live_view_signing_salt %>"
]<% end %>

This comment has been minimized.

Copy link
@aforward

aforward Apr 16, 2019

Author Contributor

See comment here
https://github.com/phoenixframework/phoenix/pull/3376/files#r275770071

The live_view_signing_salt might completely go away.

{:eex, "phx_test/views/layout_view_test.exs", :project, "test/:lib_web_name/views/layout_view_test.exs"},
{:eex, "phx_test/live/page_live_view_test.exs", :project, "test/:lib_web_name/live/page_live_view_test.exs"},
]

This comment has been minimized.

Copy link
@aforward

aforward Apr 16, 2019

Author Contributor

There is definitely overlap with template :html. I wasn't sure how best to manage conflicts with the same name for the sample liveview where the phx_live/controllers/page_controller.ex is different. I also wasn't sure if we wanted to manage all cases

live? html? Description
F F No HTML / Views at all
F T Yes HTML, no LiveView
T F Only show a LiveView example
T T Show both the LiveView AND the RegularView

This comment has been minimized.

Copy link
@josevalim

josevalim Apr 30, 2019

Member

Live implies HTML. If Live is given, we won't generate a HTML. So the fourth row in your table is not necessary.

This comment has been minimized.

Copy link
@josevalim

josevalim Apr 30, 2019

Member

Alternatively, we don't show a Live example here and leave it for later (in a possible phx.gen.live generator). Especially because if we have a Live example, we don't need a controller.

This comment has been minimized.

Copy link
@aforward

aforward Apr 30, 2019

Author Contributor

I have been playing around with generated examples, and I am going to look at having live just add a snippet within the HTML so that both can co-exist as it does provide a nice view of live and non-live code.

I’ll look separately at the generator, which might make more sense in the long run as “—live” might become the default

<%= if live do %>// Enabled LiveView Socket
import LiveSocket from "phoenix_live_view"
let liveSocket = new LiveSocket("/live")
liveSocket.connect()<% end %>

This comment has been minimized.

Copy link
@aforward

aforward Apr 16, 2019

Author Contributor

--live was explicitly asked for, so I left this code directly commented out. When moving towards --live as the default, we possibly might want this shown, but commented out.

@aforward aforward force-pushed the aforward-oss:f/liveview-switch branch 2 times, most recently from 3ff71d9 to f4d80b9 Apr 16, 2019
@aforward aforward force-pushed the aforward-oss:f/liveview-switch branch 8 times, most recently from c4ac9d2 to cd82be2 Apr 24, 2019
aforward added a commit to aforward-oss/phoenix_live_view_example that referenced this pull request May 1, 2019
Based on question posed here
phoenixframework/phoenix#3376 (comment)

And a separate PR into the LiveView documentation here
phoenixframework/phoenix_live_view#198

I am updating the examples to use the approach to import the live_render
instead of using an alias
@aforward aforward force-pushed the aforward-oss:f/liveview-switch branch 2 times, most recently from 89d5738 to bddac6b May 1, 2019
use <%= web_namespace %>, :controller

def index(conn, _params) do
render(conn, "index.html")

This comment has been minimized.

Copy link
@aforward

aforward May 1, 2019

Author Contributor

Moved away from 100% liveview, and instead did an embedded example within the index.html.eex

@@ -0,0 +1,35 @@
<%%= live_render(@conn, <%= web_namespace %>.PageLiveView) %>

This comment has been minimized.

Copy link
@aforward

aforward May 1, 2019

Author Contributor

Moved from full on leex to an embedded version within the index page.

aforward added a commit to aforward-oss/phoenix_live_view_example that referenced this pull request May 1, 2019
Based on question posed here
phoenixframework/phoenix#3376 (comment)

And a separate PR into the LiveView documentation here
phoenixframework/phoenix_live_view#198

I am updating the examples to use the approach to import the live_render
instead of using an alias
@aforward aforward force-pushed the aforward-oss:f/liveview-switch branch from bddac6b to 07d97dd May 18, 2019
@aforward aforward force-pushed the aforward-oss:f/liveview-switch branch from 07d97dd to 1f0fb8c Jul 21, 2019
@aforward aforward force-pushed the aforward-oss:f/liveview-switch branch from 1f0fb8c to 71cb98f Jul 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.