Skip to content

Conversation

@weaverryan
Copy link
Owner

Accomplishes 3) BACKEND: pass data (writable props) & props separately as live controller values from symfony#500

tl;dr

We now pass props (readonly LiveProp) and data (writable LiveProp) separately to the frontend. But then when we re-render, we still send back just one big array of BOTH mixed together.

Why do we need to differentiate between props and data on the frontend? It's for child components. When a parent re-renders, we will (it's another TODO on the PR) render the parent but with an EMPTY child element, except that we will include the props on that child element - e.g. this will come back from the Ajax request:

<div data-controller="live" ... data & props - all the normal attributes>
    I am a parent component

    <!-- here is the child - it's empty
    <div data-controller="live" data-live-props-value="{...}"></div>
</div>

This will allow us to grab the new props (which may have changed as a result of WHAT the parent component is passing into the child), override the props on the child, and then trigger the child to re-render with all the new stuff. What's important here is that, by differentiating props vs data, we can KEEP any modified "data" that the child has: only overriding the props that changed as a result of the parent component re-rendering.

Copy link

@kbond kbond left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can more logic be moved to the new DehydratedComponent class?

@weaverryan weaverryan force-pushed the component-object-backend-props branch from 2eb7812 to e0ac5d8 Compare October 12, 2022 18:25
Copy link

@kbond kbond left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Also refactored to a new DehydratedComponent
@weaverryan weaverryan force-pushed the component-object-backend-props branch from e0ac5d8 to dad4ad3 Compare October 13, 2022 00:49
@weaverryan weaverryan merged commit 9cbeaba into component-object Oct 13, 2022
@weaverryan weaverryan deleted the component-object-backend-props branch October 13, 2022 00:50
weaverryan added a commit that referenced this pull request Nov 1, 2022
# This is the 1st commit message:

WIP heavy refactoring to Component

Initial "hook" system used to reset model field after re-render

Adding a 2nd hook to handle window unloaded

reinit polling after re-render

Adding Component proxy

# This is the commit message #2:

fixing some tests

# This is the commit message #3:

Refactoring loading to a hook

# This is the commit message #4:

fixing tests

# This is the commit message #5:

rearranging

# This is the commit message #6:

Refactoring polling to a separate class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants