refactors

This commit is contained in:
Niels Lyngsø
2024-01-12 19:09:22 +01:00
parent ba53fb876f
commit 44d148c69f
2 changed files with 44 additions and 37 deletions

View File

@@ -37,16 +37,18 @@ export class ExampleSorterGroup extends UmbElementMixin(LitElement) {
#sorter = new UmbSorterController<ModelEntryType, ExampleSorterItem>(this, {
...SORTER_CONFIG,
performItemInsert: ({ item, newIndex }) => {
const oldValue = [...this._items];
this._items.splice(newIndex, 0, item);
//console.log('inserted', item.name, 'at', newIndex, ' ', this._items.map((x) => x.name).join(', '));
this.requestUpdate('_items');
this.requestUpdate('items', oldValue);
return true;
},
performItemRemove: ({ item }) => {
const oldValue = [...this._items];
const indexToMove = this._items.findIndex((x) => x.name === item.name);
this._items.splice(indexToMove, 1);
//console.log('removed', item.name, 'at', indexToMove, ' ', this._items.map((x) => x.name).join(', '));
this.requestUpdate('_items');
this.requestUpdate('items', oldValue);
return true;
},
});
@@ -64,8 +66,8 @@ export class ExampleSorterGroup extends UmbElementMixin(LitElement) {
return html`
<div class="sorter-container">
${repeat(
this._items,
(item, index) => item.name + '_ ' + index,
this.items,
(item) => item.name,
(item) =>
html`<example-sorter-item name=${item.name}>
<button @click=${() => this.removeItem(item)}>Delete</button>