django-unicorn
django-unicorn copied to clipboard
Feature request: remove component
Hi Adam,
a feature that could be easily integrated and would greatly enhance Unicorn is a client side "remove component" action.
In many cases unicorn components are list elements or table rows that include action buttons like "Delete". You have examples for that using parent components that remove that row and rerender the whole list. This unnecessarily over-complicates the situation, as in IMHO many cases no parent component is needed - just a <ul>
or <table>
element.
What e.g. the Tetra framework does, is to provide a self.client._remove_component()
method, that just removes the whole element from the DOM at the client side.
So a simple component delete action would just be:
class MyComponentView(UnicornView)
def delete():
self.client._remove_component()
and the template:
<tr>
<td>...</td>
<td>
<button ... u:click="delete()">Delete</button>
</td>
</tr>
Adding client side Js functions that can be called from the backend would be generally a huge benefit. (already there)
But the delete()
action is the most important.
Maybe just the client side must be implemented here, as self.call()
in the backend is already there.
0.58.0 of Unicorn
adds a Unicorn.deleteComponent
method to remove a component from internal component store. I could extend this to remove the actual DOM element as well if that would be useful.
I think this is what would be expected then, yes.