Skip to content
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

Constructors rather than factories #2

Closed
Rich-Harris opened this issue Nov 21, 2016 · 0 comments
Closed

Constructors rather than factories #2

Rich-Harris opened this issue Nov 21, 2016 · 0 comments

Comments

@Rich-Harris
Copy link
Member

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.)

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

No branches or pull requests

1 participant