Skip to content

Conversation

jknohr
Copy link
Owner

@jknohr jknohr commented Jan 25, 2025

Upgrade src/lib/components/Anchor/Anchor.svelte, src/lib/components/ContrastTheme/ContrastTheme.svelte, and src/lib/components/Controls/Controls.svelte to Svelte 5.0 syntax.

  • Reactivity Syntax: Replace let with $state for reactive variables. Replace $: with $derived or $effect for reactive statements.
  • Props: Use $props to declare props with destructuring.
  • Event Handling: Replace on:click with onclick for event handlers. Replace createEventDispatcher with callback props.
  • Other Changes: Refactor various functions and variables to align with the new syntax and structure of Svelte 5.0.

Summary by Sourcery

Update components to use Svelte 5 syntax, including reactivity changes, props updates, and event handling modifications.

New Features:

  • Added support for Svelte 5 callback props for event handling.

Enhancements:

  • Migrated from Svelte reactivity syntax to Svelte 5 syntax, using $state for reactive variables, $derived or $effect for reactive statements, and $props for props declaration.

Upgrade `src/lib/components/Anchor/Anchor.svelte`, `src/lib/components/ContrastTheme/ContrastTheme.svelte`, and `src/lib/components/Controls/Controls.svelte` to Svelte 5.0 syntax.

* **Reactivity Syntax**: Replace `let` with `$state` for reactive variables. Replace `$:` with `$derived` or `$effect` for reactive statements.
* **Props**: Use `$props` to declare props with destructuring.
* **Event Handling**: Replace `on:click` with `onclick` for event handlers. Replace `createEventDispatcher` with callback props.
* **Other Changes**: Refactor various functions and variables to align with the new syntax and structure of Svelte 5.0.
Copy link

sourcery-ai bot commented Jan 25, 2025

Reviewer's Guide by Sourcery

This pull request upgrades the codebase to Svelte 5.0, focusing on syntax changes related to reactivity, props, and event handling. It also includes refactoring of various functions and variables to align with the new Svelte 5.0 structure.

Class diagram showing updated component structure with Svelte 5.0 changes

classDiagram
    class Component {
        $props
        $state
        $derived
        $effect()
    }

    class Edge {
        +$props: EdgeProps
        +$state: EdgeState
        +$derived dynamic
        +$derived edgeColor
        +$effect()
    }

    class Graph {
        +$props: GraphProps
        +$state: GraphState
        +$derived dimensions
        +$effect()
    }

    class Node {
        +$props: NodeProps
        +$state: NodeState
        +$derived nodePosition
        +$effect()
    }

    Component <|-- Edge
    Component <|-- Graph
    Component <|-- Node

    note for Component "Base structure for
Svelte 5.0 components"
    note for Edge "Updated with new
reactivity syntax"
    note for Graph "Refactored state
management"
    note for Node "Modified props and
state handling"
Loading

File-Level Changes

Change Details Files
Replaced let with $state for reactive variables.
  • All reactive variables are now declared using $state.
src/lib/components/Edge/Edge.svelte
Replaced $: with $derived or $effect for reactive statements.
  • Reactive statements are now declared using $derived for values and $effect for side effects.
src/lib/components/Edge/Edge.svelte
Used $props to declare props with destructuring.
  • Component props are now declared using $props with destructuring.
src/lib/components/Edge/Edge.svelte
src/lib/containers/Graph/Graph.svelte
src/lib/components/Node/Node.svelte
Replaced on:click with onclick for event handlers.
  • Event handlers are now declared using onclick instead of on:click.
src/lib/components/Edge/Edge.svelte
Replaced createEventDispatcher with callback props.
  • Event dispatchers are now implemented using callback props.
src/lib/containers/Graph/Graph.svelte
src/lib/components/Anchor/Anchor.svelte
Refactored various functions and variables to align with Svelte 5.0 syntax.
  • Adjusted code to use the new Svelte 5.0 syntax and structure.
  • Refactored code to use the new Svelte 5.0 syntax and structure.
src/lib/components/Edge/Edge.svelte
src/lib/containers/Graph/Graph.svelte
src/lib/components/Node/Node.svelte
src/lib/containers/Svelvet/Svelvet.svelte
src/lib/components/Anchor/Anchor.svelte
src/lib/components/Resizer/Resizer.svelte
src/lib/components/data/Knob/Knob.svelte
src/lib/components/Minimap/Minimap.svelte
src/lib/components/Drawer/Drawer.svelte
src/lib/components/data/ColorPicker/ColorWheel.svelte
src/lib/components/ContrastTheme/ContrastTheme.svelte
src/lib/components/Node/InternalNode.svelte
src/lib/components/ThemeToggle/ThemeToggle.svelte
src/lib/components/Editor/Editor.svelte
src/lib/components/Controls/Controls.svelte
src/lib/components/data/RadioGroup/RadioGroup.svelte
src/routes/+page.svelte
src/lib/components/FlowChart/FlowChart.svelte
src/lib/components/Group/Group.svelte
src/lib/components/data/Toggle/Toggle.svelte

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @jknohr - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider keeping on:event syntax instead of changing to onevent attributes, as this may break event modifier functionality and is not a required change for Svelte 5
  • Establish consistent patterns for state initialization - some components mix old-style declarations with new $state syntax which could lead to confusion
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

const graphDOMElement = getContext<Writable<HTMLElement>>('graphDOMElement');
const dispatch = createEventDispatcher();
const dispatch = (eventName, detail) => {
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Custom event dispatch implementation may not handle bubbling correctly

Consider using Svelte's built-in createEventDispatcher instead of a custom implementation to ensure proper event bubbling and typing.

@jknohr jknohr merged commit cf31a78 into main Jan 25, 2025
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.

1 participant