Comments (7)
Here's a suggestion: warn (not error) on variable/import with name of rune, and disable the rune for the entire file. So you can do import $state from "somewhere"
and it gives you a warning:
The import/variable name clashes with a Svelte rune. The $state rune cannot be used in this file unless the import/variable is renamed.
The warning should maybe be able to be suppressed.
This way new runes are not breaking changes. And the existing error for all $-prefixed variables should be removed, or at least changed to warnings (which should definitely be able to be suppressed).
from svelte.
You can always import the package imports as a namespace. This is something we've been advocating for folks who have this exact problem, for example with Lexical:
import * as Lexical from 'lexical';
// ..
lexical.$insertNodes(…)
from svelte.
@trueadm I don't think you understood my point, we have internal conventions and rules and all of our projects use $
and in case we WANT to use Svelte 5, we are FORCED to break those rules.
In my opinion, a framework should absolutely not break a company or even a developer code writing rules.
I saw the other issues related to the $ sign, they suggest the removal of the $ sign from the runes, but here I am asking to relax the restriction.
from svelte.
@roonie007 I know, I was the author of Lexical that also had the convention of using $
prefixes on the APIs. However, like I said above, you're not removing the convention, you're just working around it. In the case of .svelte
modules, we enforce that $
prefix isn't allowed as it enables us to use those for runes in the future. It would suck if we couldn't add a $db()
or a $session()
rune in the future to SvelteKit – for example.
from svelte.
@trueadm That’s precisely my point. While svelte could introduce $db
or $session
in the future, in our codebase, we have the flexibility to rename variables as needed (e.g., $database
, $mongo
, $prisma
, $userSession
, etc...).
Having the choice is always preferable to being restricted. Allowing us to continue using $-prefixes
for our internal functions without enforcing a blanket restriction would provide more flexibility and avoid unnecessary workarounds.
from svelte.
@trueadm That’s precisely my point. While svelte could introduce
$db
or$session
in the future, in our codebase, we have the flexibility to rename variables as needed (e.g.,$database
,$mongo
,$prisma
,$userSession
, etc...).Having the choice is always preferable to being restricted. Allowing us to continue using
$-prefixes
for our internal functions without enforcing a blanket restriction would provide more flexibility and avoid unnecessary workarounds.
The problem is semver: if you don't restrict $ variables whenever you want to add a new rune that's a breaking change. So while you absolutely can rename your variables svelte can't publish a new rune without bumping to svelte 6 (which would be kinda restrictive)
from svelte.
@rChaoz suggestion is also an acceptable solution to relax the restriction.
from svelte.
Related Issues (20)
- Svelte 5: Mutating data in load fn stops page reactivity HOT 4
- Svelte 5: this type of directive is not valid on components HOT 4
- Svelte 5: Inaccurate Error Message HOT 1
- `batch` function to update multiple sources at once HOT 4
- Svelte 5 reporting invalid type error on Svelte 4 component using slot
- Make aria- dependencies optional HOT 9
- Svelte 5: problems unmounting elements from the dom inside an each block HOT 5
- next.168 development mode and component snippets inside loop HOT 5
- next.168 broke unmounting content in my app HOT 5
- Breakpoints cannot be set on certain locations in Svelte generated code in V8 HOT 1
- Bad compilation of valid Svelte 4 components under Svelte 5 HOT 3
- components still not unmounted HOT 9
- `$effect` throws `Uncaught Error: effect_orphan` in a custom store HOT 3
- Make `bind:{value}` a shorthand to `bind:value={value}` HOT 2
- Investigate dropping the CJS build HOT 1
- Error on create multiple toasts with svelte-sonner HOT 2
- Validator type not exported in svelte/store
- Svelte 5: Incorrect Handling of Rest Props in Compiled Code. Error: $$props is not defined
- Svelte 5: Regression since next.167 and new regression with next.171 HOT 4
- Svelte 5: Allow returning (object) $state directly? HOT 2
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.