Skip to content

Constructors rather than factories #2

@Rich-Harris

Description

@Rich-Harris

Having gone back and forth on this, I think it makes more sense for components to be constructors rather than factories – i.e. instead of this...

export default function createComponent ( options ) {
  // ...
}

...this:

export default function Widget ( options ) {
  // ...
}

This makes Svelte components slightly more familiar for people coming from e.g. Ractive or Vue, and has this important benefit:

// awkward naming
import createWidget from './Widget.html';
const widget = createWidget(...);

// better
import Widget from './Widget.html';
const widget = new Widget(...);

(Capitalising filenames makes sense because inline components should also be capitalised, i.e. <Widget foo='bar'/> – this is a good way to visually distinguish elements from components in a way that doesn't make them look like web components.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy