-
-
Couldn't load subscription status.
- Fork 366
bugfix/tree-view-relational-updates #1910
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
bugfix/tree-view-relational-updates #1910
Conversation
🦋 Changeset detectedLatest commit: a3ee7fa The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
Didn't break while I was testing it :) /**
* called when X happens
* @type {() => A|B|C}
*/ |
@type will only change the type, but I wanted to hide it entirely because users will not need this information. and it is displaying the function body in the value which is hella ugly 😄 |
|
Damn. I hoped that'd overwrite a bit more. Ah well... :| |
|
@Mahmoud-zino I've implemented a hard filter for those three export function props as requested. See how I implemented this in my commit in case you need to modify this in the future. It's not a perfect solution, but should work for now. I'm able to replicate the error @ak4zh reported above, beyond that everything else looks good to me. |
|
I've encountered another issue. |
|
@ak4zh can you please provide your setup, the tree-view is a very tricky component so I really appreciate you digging in it and finding these juicy bugs 😉 |
|
@ak4zh on other thoughts this could be a performance issue, I have opted to the change event, this should still work the same for the component, just calling the function fewer times and only as needed. |
|
Additionally I notice you are using the spread operator to add the |
|
Verified the functionality works fine after 012464c. |
This is used to trigger reactivity in svelte, so if we want to use .push instead we will still have to do array.push(value);
array = array;which I think will have the same effect on speed + the spread method is the recommended way of doing this from the svelte docs https://svelte.dev/tutorial/updating-arrays-and-objects |
|
Got it. Thanks for the explanation. Before this I was generating the tree view myself and it was messy code. |
|
@Mahmoud-zino On another thought I realised since the recent changes, we've moved away from using reactivity. As a result, I proceeded to test with Just adding a note. |
|
FYI my goal will be to review this again tomorrow. If we're confident all is well I'll aim to merge then. This will make it part of the latest v2 RC release. |
|
I recently noticed that the selectAll and deselectAll functions are being removed in this pull request. I've been brainstorming ways to streamline this, and I came up with a somewhat unconventional solution. What if we try this approach? let refreshKey = String(Math.random());
export const actions = {
updateAll(subNodes: TreeViewNode[], updateField: 'checked'|'open', status: boolean) {
subNodes.forEach(n => {
n[updateField] = status;
if (updateField === 'checked') n.indeterminate = false;
if (n.children && n.children.length) actions.updateAll(n.children, updateField, status)
})
refreshKey = String(Math.random());
},
selectAll() {
actions.updateAll(nodes, 'checked', true)
},
deselectAll() {
actions.updateAll(nodes, 'checked', false)
},
expandAll() {
actions.updateAll(nodes, 'open', true)
},
collapseAll() {
actions.updateAll(nodes, 'open', false)
}
} {#key refreshKey}
{#if nodes && nodes.length > 0}
<TreeViewDataDrivenItem bind:nodes on:change on:click on:toggle on:keydown on:keyup />
{:else}
<slot />
{/if}
{/key}// +page.svelte
<svelte:fragment slot="preview">
<TreeView bind:actions={multiDDAction} bind:nodes={multipleDD} selection multiple />
</svelte:fragment>
<svelte:fragment slot="footer">
<button class="btn variant-filled" on:click={() => multiDDAction.selectAll()}>Select All</button>
<button class="btn variant-filled" on:click={() => multiDDAction.deselectAll()}>Unselect All</button>
<button class="btn variant-filled" on:click={() => multiDDAction.expandAll()}>Expand All</button>
<button class="btn variant-filled" on:click={() => multiDDAction.collapseAll()}>Collapse All</button>
</svelte:fragment> |
|
Here's my repo with above suggested changes for quick test, everything seems to work correctly, not sure if this hacky approach is good enough for Chris: |
just tested both variants there is no difference whatsoever (also on performance). |
|
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've made a couple of changes that get rid of some of the type assertions that weren't really necessary, as well as replacing the group = [...group, node.value] in favor of mutating the array. Svelte's tutorial may mention it as a convenient way to trigger reactivity, but I have strong opinions against it 😄.
Besides that, everything seems to be working perfectly. Awesome work!
I would be interested in hearing your opinions 😄, we have a lot of places where we are using the spread operator to trigger interactivity, so if there is a problem other than the style it might be worth it to change them. |
|
@Mahmoud-zino I like to reference this example when talking about the consequences of this approach: As library authors, we should be, generally, cautious when it comes to performance, striving to be as performant as reasonably possible. Using This method of reassignment is one of those React idioms that has weaseled it's way into Svelte. It's popular among the React folks because of how their reactivity system works. Over there, state is based on referential equality. Meaning, they have create a whole new array in order for the VDOM to recognized that their state has updated. Over here in Svelte land, we have the luxury of simply mutating the state and being done with it. No excess memory allocation required. We might as well take advantage of it! /end-of-rant |
|
oof, I though the different was trivial... |



Linked Issue
Closes #1885
Closes #1884
Needs to be done
we are now using export functions to handle part of the relations, but it is displayed in the props table. we need a way to hide it.

Description
fixed relational updates for both recursive and non-recursive modes.
This is a basic diagram of how the tree-view relations behave:

Extra changes
selectAll,deselectAllwill need extreme effort for such a tiny feature -_-)Changsets
bugfix: Tree-view relational updates are now working as expected.
Checklist
Please read and apply all contribution requirements.
devbranch (NEVERmaster)docs/,feat/,chore/,bugfix/pnpm checkpnpm formatpnpm test