Code Monkey home page Code Monkey logo

Comments (12)

Rich-Harris avatar Rich-Harris commented on May 22, 2024 12

What about oncreate and ondestroy? Unambiguous (you can only create or destroy something once), and they have a nice symmetry

from svelte.

vampaz avatar vampaz commented on May 22, 2024 3

I would go with mount.
init - all is good, ready to mount.
mount - added to the DOM and initial render done.

from svelte.

aickin avatar aickin commented on May 22, 2024 2

I would go with mount.

I'd be fine with that as well, with the caveat that onteardown should then be changed to onunmount.

from svelte.

mrkishi avatar mrkishi commented on May 22, 2024

In regards to 1, it'd also be nice to know if components can be rerendered/reconstructed/remounted manually, either in place or in a new target.

On 2, perhaps consider reusing names from other frameworks, whichever's aligned with svelte's implementation: Custom Elements v1's connect, Vue and React's mount, Angular's init, and so on.

from svelte.

maraisr avatar maraisr commented on May 22, 2024

Agreeing with you @aickin - its VERY important to have a clear and concise api, that can be consumed and understood at first glace. onteardown -> onsetup - or - onmount -> onunmount would be ammaazinggg!

Much like React's will / did ComponentUpdate lifecycles.

from svelte.

maraisr avatar maraisr commented on May 22, 2024

@Rich-Harris yeah mate - love it!!!

from svelte.

aickin avatar aickin commented on May 22, 2024

+1 for oncreate/ondestroy!

from svelte.

wessberg avatar wessberg commented on May 22, 2024

Might I suggest following the Custom Elements v1 spec for the names of lifecycle hooks? I think that's most forward looking, even though not as concise.

onrender would become connectedCallback.
onteardown would become disconnectedCallback

from svelte.

rrag avatar rrag commented on May 22, 2024

my $0.02 when I first saw onteardown I was looking for onsetup, you know like JUnit, in java which has setUp() and tearDown(). it did not occur to me that onrender is actually oncreate, so in the absence of a compelling reason, I suggest using the familiar (at least to those coming from Java) onsetup, onteardown

from svelte.

Ryuno-Ki avatar Ryuno-Ki commented on May 22, 2024

In Python's unittest you use setUp and tearDown functions as well.

from svelte.

Swatinem avatar Swatinem commented on May 22, 2024

I actually think react did a good job finding names for these lifecycle events:

  • componentDidMount
  • componentWillUnmount
  • (plus maybe all the update related lifecycle events)

Well those names are a bit verbose, I would maybe call them afterMount and beforeUnmount, which also make it clear that we have a valid dom elements that are also attached (mounted) to the real dom.

I think there is an edge case involving yield fragments with the current onrender hook that does not guarantee a mounted dom element currently. I will have to come up with a testcase for that.

from svelte.

Rich-Harris avatar Rich-Harris commented on May 22, 2024

I've opened #316 which implements oncreate and ondestroy in a non-breaking way (so that people have time to update their components before it becomes a breaking change in V2).

Re alternative name suggestions, I'm wary of using the same names that web components and React use, partly because they're kinda ugly and tedious to type (and don't gel with all the other single-word-all-lowercase properties), but mostly because when you do that, you need to get the semantics exactly the same otherwise you just end up confusing people. For example, my understanding is that disconnectedCallback is called when a web component is temporarily removed from the document, whereas a Svelte component is either alive or dead, it doesn't exist in a kind of off-document limbo. In fact, the reason we're here is that React users reasonably expected 'render' to mean roughly the same thing in Svelte as in React. So I'm still in favour of oncreate and ondestroy.

from svelte.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.