Creating a side-effect free `new Component`
See original GitHub issueIs your feature request related to a problem? Please describe. When using a component in a JavaScript file, you do it like this:
import Component from `MyComponent.svelte`;
const myComponent = new Component({
target: document.getElementById('main')
});
In our project we have the eslint rules no-new
and no-unused-vars
which get triggered by this code: The code triggers no-unused-vars
, but if I remove const myComponent =
, the code triggers the no-new
rule.
Describe the solution you’d like
I’d like the component to be able to do a “delayed mount”, to have a side-effect-free constructor if it does not receive a target
property (for ease of use you can leave the default behavior like it is). Taking a peek at Vue, I’d like a syntax like this:
const myComponent = new Component();
myComponent.mount(document.getElementById('main'));
Describe alternatives you’ve considered For now, I’ll add a
// eslint-disable-next-line no-new
new Component({
target: document.getElementById('main')
});
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:6 (4 by maintainers)
Top Results From Across the Web
65 Handling side effect in class component - YouTube
In this lecture you will learn, how to handle side effects in a class based component and what are lifecycle methods of a...
Read more >How to make a class-based custom element side-effect-free ...
From webpack guide - Mark the file as side-effect-free: All the code noted above does not contain side effects, so we can simply...
Read more >Side-effects in Compose - Android Developers
A side-effect is a change to the state of the app that happens outside the scope of a composable function. Due to composables'...
Read more >Effectful (But Side-Effect Free) Programming - pfun
Effectful (But Side-Effect Free) Programming. In functional programming, programs are built by composing functions that have no side-effects.
Read more >4 Working with side effects - React Hooks in Action
Recognizing types of side effects in components; Wrapping side effects with the useEffect hook; Controlling when an effect runs by specifying a dependency ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Assuming this issue is motivated by a desire to appease the linter without disabling the line, and you don’t actually need a separate
mount
function, an alterntive for you could be like this, for example:not sure i understand. your motivations seem entirely because of
no-new
. yet your proposed syntax still includesnew
. why do you really want a delayed mount? your solution doesnt fit your stated problem.