Replies: 10 comments 1 reply
-
|
I get what you're saying, but having gone down this route with Svelte 5, I can tell you that it's simply not possible. Reactivity must be able to live outside of components, for example in utility functions and places like classes etc, this is a key feature and removing that would be too limiting. At the same time, treating everything as possibly reactive gets cumbersome, especially when it comes to things like destructuring and transporting reactivity on objects – something Ripple supports really well today. |
Beta Was this translation helpful? Give feedback.
-
|
Supporting the $ syntax. It is actually quite good and simple mechanism for newcomers and seasoned devs to distinguish between reactive variables and regular ones. Not all vars need to be reactive, as it would really mean throwing away CPU cycles. As someone who used to program within 64Kb, yes, kilobytes, I am still fond of solutions which are resource efficient. Also, it is especially useful when looking at a piece of code without broad context. Once you see the $ sign, you immediately think "Oh, this will change in time", which is not obvious from just seeing About learning a new syntax: yes, it is different and not immediately obvious, but so is any function of a framework. You read the docs, learn about it and use it. For example it was quite strange to me when I saw this for the first time: var app = new Vue({
el: '#app',
data: {
message: 'Hello Vue!',
counter: 0
}
});Why Or, when someone sees So, if we need to somehow define reactivity, $ (or any other sign, for that matter) prefix is the simplest and cleanest solution in my opinion. Thanks, Dominic, you're doing an excellent job at making our lives easier! |
Beta Was this translation helpful? Give feedback.
-
|
Thank you, Dominic (@trueadm), for clarification. And as I said, you're doing great work. I'm not criticizing, just want to share my opinion, which I hope can help. I got the reasoning behind specifying some variables as reactive and some not. But my question/suggestion is more about the reason for using naming to specify some syntax, rather than using keywords or syntax for it. What I mean is that in JS/TS, different kinds of variables are specified by specific keywords that make them distinguishable during reading. For example: const alice = 1 // I define that it will not change
let bob = 1 // I define that it can change And developers can or cannot use any prefix notation to specify that these variables are different. For example, in the Java/Android world, Google notation has used mAccessibilityDelegade = null // I specify that it will not be used outside of classSome people prefer it, but the majority of developers decided that it is easy enough to read variable definitions, and there is no need to prefix everything. Anyway, this is personal development notation. Some companies can use it, some can avoid it. It can be defined between developers. But JS and TS languages specifically avoid making notation part of the languages, to allow different developers to choose what they prefer. So this goes to my initial question. You also made a superset of TypeScript with JSX-like Syntax. So essentially, it is another language, to which you already defined a new ExampleFor example, like this: import { effect } from 'ripple';
component App() {
$let count = 0; // it variable, but it also reactive
effect(() => {
console.log(count);
});
<button onClick={() => count++}>Increment</button>
}Or like this import { effect } from 'ripple';
component App() {
reactive count = 0;
effect(() => {
console.log(count);
});
<button onClick={() => count++}>Increment</button>
}This will allow developers who like the import { effect } from 'ripple';
component App() {
reactive $count = 0; // still works as valid code
effect(() => {
console.log($count);
});
<button onClick={() => $count++}>Increment</button>
} |
Beta Was this translation helpful? Give feedback.
-
|
The great thing about incorporating When you consume a prop and it's called |
Beta Was this translation helpful? Give feedback.
-
|
Yes, I got what you mean. So essentially, the question is how to define that some properties of an object should be reactive? This sounds like a type definition. Essentially, types in TypeScript are used to signal some specific information about properties or a variable alongside a keyword. For example, it can be done like with arrays: import type { Component } from 'ripple';
component Counter({ startingCount }: {startingCount: Reactive<number>}) {
let count: Reactive<number> = untrack(() => startingCount);
let double: Reactive<number> = count * 2;
}For me, it is much easier to read and understand in comparison with import { untrack } from 'ripple';
component Counter({ $startingCount }: {$startingCount: Reactive<number>}) {
let $count: Reactive<number> = untrack(() => $startingCount);
let $double: Reactive<number> = $count * 2;
} |
Beta Was this translation helpful? Give feedback.
-
|
Yeah we had this topic on the Svelte team, unfortunately TS doesn't work this way. Whilst you can annotate it, they are ambient types and they're lost between boundaries and when you use them in type narrowing scenarios, they also get lost. You can't do that – we all wish we could, but the TS team had a lengthy discussion with us (Svelte team) about how it's not possible. |
Beta Was this translation helpful? Give feedback.
-
|
Oh, okay, thank you for all the answers then! This made the syntax choice much clearer for me. |
Beta Was this translation helpful? Give feedback.
-
|
We all wish we could have something that solves that goal. If we had, we'd all already be using it. The issue for Svelte was they couldn't really adopt the $ prefix because of their previous stores syntax. Ripple doesn't have that constraint. |
Beta Was this translation helpful? Give feedback.
-
|
This approach though would need some sort of mapper when a reactive object is being populated say with result (of same properties names without the $) from a fetch or any backend call . It will be ideal if that mapper is provided by the framework , e.g toState and fromState preferably as Object extension methods so we can do |
Beta Was this translation helpful? Give feedback.
-
|
We removed the $ prefixed last year, closing |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Want to say that I am really impressed by what you are building. You have found a great blend between frameworks! I love that you keep simplicity and the imperative style of React. while making it possible to define markup alongside TS.
On top of that, simplicity in defining reactive variables is also awesome, but the PHP-like
$prefix makes me wonder about other possibilities.I understand that for many developers, the
$countervariables look good, and it's more like personal preference. But also, there's a big community of devs that aren't really fans of it, for example, React devs. I need to mention that I mostly worked on mainstream frameworks: React, Vue 2, and Angular. So my opinion is based on them. And I am still a big fan of the Vue 2 style of reactive variables. That worked without any specific syntax, and by native object property definition. It was easy to read and simple to understand for new devs.As a result, I want to understand, can you consider simplifying the syntax a little bit, by making all variables defined inside the component reactive? This way, there will be no need to use
$, which will make it easier to read for newcomers, but still will make it possible to define non-reactive variables, without any issues.Example
There is an example of how it can look
Beta Was this translation helpful? Give feedback.
All reactions