Skip to content

Commit

Permalink
dont use constructor props
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianGonz97 committed Oct 27, 2024
1 parent abc1aca commit 9e78c0f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ import type { Component, ComponentProps, Snippet } from "svelte";
* ```
*/
export class RenderComponentConfig<TComponent extends Component> {
component: TComponent;
props: ComponentProps<TComponent> | Record<string, never>;
constructor(
public component: TComponent,
public props: ComponentProps<TComponent> | Record<string, never> = {}
) {}
component: TComponent,
props: ComponentProps<TComponent> | Record<string, never> = {}
) {
this.component = component;
this.props = props;
}
}

/**
Expand All @@ -39,10 +44,12 @@ export class RenderComponentConfig<TComponent extends Component> {
* ```
*/
export class RenderSnippetConfig<TProps> {
constructor(
public snippet: Snippet<[TProps]>,
public params: TProps
) {}
snippet: Snippet<[TProps]>;
params: TProps;
constructor(snippet: Snippet<[TProps]>, params: TProps) {
this.snippet = snippet;
this.params = params;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ export type SidebarStateProps = {
};

class SidebarState {
readonly props: SidebarStateProps;
open = $derived.by(() => this.props.open());
openMobile = $state(false);
setOpen: SidebarStateProps["setOpen"];
#isMobile: IsMobile;
state = $derived.by(() => (this.open ? "expanded" : "collapsed"));

constructor(readonly props: SidebarStateProps) {
constructor(props: SidebarStateProps) {
this.setOpen = props.setOpen;
this.#isMobile = new IsMobile();
this.props = props;
}

// Convenience getter for checking if the sidebar is mobile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ import type { Component, ComponentProps, Snippet } from "svelte";
* ```
*/
export class RenderComponentConfig<TComponent extends Component> {
component: TComponent;
props: ComponentProps<TComponent> | Record<string, never>;
constructor(
public component: TComponent,
public props: ComponentProps<TComponent> | Record<string, never>
) {}
component: TComponent,
props: ComponentProps<TComponent> | Record<string, never> = {}
) {
this.component = component;
this.props = props;
}
}

/**
Expand All @@ -39,10 +44,12 @@ export class RenderComponentConfig<TComponent extends Component> {
* ```
*/
export class RenderSnippetConfig<TProps> {
constructor(
public snippet: Snippet<[TProps]>,
public params: TProps
) {}
snippet: Snippet<[TProps]>;
params: TProps;
constructor(snippet: Snippet<[TProps]>, params: TProps) {
this.snippet = snippet;
this.params = params;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ export type SidebarStateProps = {
};

class SidebarState {
readonly props: SidebarStateProps;
open = $derived.by(() => this.props.open());
openMobile = $state(false);
setOpen: SidebarStateProps["setOpen"];
#isMobile: IsMobile;
state = $derived.by(() => (this.open ? "expanded" : "collapsed"));

constructor(readonly props: SidebarStateProps) {
constructor(props: SidebarStateProps) {
this.setOpen = props.setOpen;
this.#isMobile = new IsMobile();
this.props = props;
}

// Convenience getter for checking if the sidebar is mobile
Expand Down

0 comments on commit 9e78c0f

Please sign in to comment.