-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add live view to cells #88
base: master
Are you sure you want to change the base?
Add live view to cells #88
Conversation
60dc18e
to
4f35dbe
Compare
Codecov Report
@@ Coverage Diff @@
## master #88 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 5 7 +2
Lines 45 54 +9
=====================================
+ Hits 45 54 +9
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #88 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 5 7 +2
Lines 45 54 +9
=====================================
+ Hits 45 54 +9
Continue to review full report at Codecov.
|
4f35dbe
to
0340288
Compare
0340288
to
61e571c
Compare
@@ -2,4 +2,5 @@ defmodule ExCell.MockViewAdapter do | |||
@moduledoc false | |||
def render(cell, template, args), do: [cell, template, args] | |||
def render_to_string(cell, template, args), do: [cell, template, args] | |||
def live_render(conn, cell, args), do: [conn, cell, args] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could also make another file mock_live_view_adapter
with this function, if that is preferred?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need IMO
Awesome 💯 This might introduce some problems/side effects when using cell-js. views/page/template.html.leex <%= live_cell(AlertCell, variant: @variant) %>
<%= @warning %>
<% end %> cells/alert/template.html.eex <%= container({variant: assigns[:variant]}) do %>
<%= @children %>
<% end %> cells/alert/index.js class AlertCell extends Cell {
initialize() {
this.variant = this.params.variant;
this.text = this.element.textContent;
}
} If I understand correctly, when Possible solutions
|
The first approach: The second approach: The third approach: This requires a major overhaul of CellJS to be reactive and observing the variables the same way for example EmberJS does with observables. Things like MobX will be required if this is the wish but introduces another paradigm: functional reactive programming. Alternative approach: CellJS observes mutations on the DOM nodes and calls the The To further elaborate to allow async functions, the function could instead return a promise instead of a value that returns the new value to be set on the |
45d0976
to
61e571c
Compare
Make it possible to have cells as live view
This implementation is an addition to the normal use of
ex_cell
, so normal cells can still be used the same way.How to use live cell
In your project on any template
So it works the same as the cell-helper except you need to provide a
conn
orsocket
.Rendering the live cell
https://github.com/DefactoSoftware/ex_cell/compare/master...GlennGeelen:glenn/add-live-cells?expand=1#diff-7eaa5ae18d45c80081813ff6a1d8edc9R61
I chose to use the
live_render/3
fromPhoenix.LiveView
so the cell will go through themount
andrender
function of theYourLiveCell
.It is also possible to change this to
cell.render/1
because theYourLiveCell
should always have therender/1
function. That way theconn
orsocket
is not necessary to give to everylive_cell
. In my opinion this is not the way to go because the in that case it will skip themount
step.