Comments (12)
What about oncreate
and ondestroy
? Unambiguous (you can only create or destroy something once), and they have a nice symmetry
from svelte.
I would go with mount
.
init
- all is good, ready to mount.
mount
- added to the DOM and initial render done.
from svelte.
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.
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.
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.
@Rich-Harris yeah mate - love it!!!
from svelte.
+1 for oncreate
/ondestroy
!
from svelte.
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.
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.
In Python's unittest you use setUp
and tearDown
functions as well.
from svelte.
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.
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)
- Svelte 5: Element Attributes get out of sync with internal state HOT 5
- `#snippet` rest args and `@render` spread? HOT 1
- Svelte 5: Spreading attributes to element breaks `hidden` HOT 5
- Svelte5: .focus() within $effect() does not work on initial load with ssr = false HOT 1
- Svelte 5: "in" transition not firing in dev/hmr mode but works fine when the app is built HOT 6
- A .svelte.ts file does not create reactivity across numerous $derived updates HOT 28
- vscode plugin: in 5.0.0-next105, compiler.cjs not included in package HOT 3
- Svelte 5: Discrepancy in `$effect` log between `array[0]` and `array.at(0)`? HOT 1
- Svelte 5: Svelte transition cause nested snippets not to work. HOT 1
- Svelte 5: TypeError: null is not an object (evaluating 'metadata.parent') when assigning value to $bindable HOT 6
- `event.currentTarget` wrongly changes reference to the <body> after an `await`, inside an onclick event HOT 11
- Svelte 5: try...catch `exceptionVar` has already been declared (duplicate-declaration)
- Svelte 5: `$derived` state mutation in function expressions does not error at compile time HOT 1
- Svelte 5: Transition Bug HOT 6
- svelte 5 bug: class getters rerun when non-dependent state updates HOT 13
- Svelte 5: Hydration fails when SvelteKit app is run as a dependency
- Svelte 5: compile-time variable HOT 4
- Svelte5: reactive Set constructor not working correctly HOT 14
- Svelte 5: Specify (and enforce) special `<svelte:*>` tag void-ness HOT 2
- svelte 5 accessors broken after [email protected]
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from svelte.