Syntax Video
Will This New JS Framework Replace React? | RippleJS First Look
- 0:00 Intro to Ripple
- 1:53 Who made this?
- 2:21 Feature List
- 3:05 The Docs
- 3:24 Reactive Arrays
- 3:47 Effects
- 4:09 Props
- 4:37 My Overall Impressions
- 8:49 Tasks App Code Walkthrough
- 9:05 Entry / index / vite Setup
- 9:30 App Component
- 10:06 Derived / Computed Values
- 10:30 Complex Derived Values
- 11:15 Nested reactive values
- 12:13 Form inputs / events
- 12:44 Conditional Rendering
- 13:23 Nested if / for statements
- 14:15 Reactive class bindings
- 14:38 Reactive props
- 15:24 Reactive style bindings
- 17:20 Impressions after building with Ripple
- 17:42 Thanks!
Intro to Ripple
What's up? CJ here. A brand new front-end web framework just dropped and today we're going to talk about it. So, I'm going to show you what it is, how it works, and tell you what I think about it. So, it's called Ripple. It is the elegant TypeScript UI framework. And at first glance, it might look a little bit like React because it does use JSX of sorts, but if you're keen, you'll notice that there's this component keyword, which isn't valid JavaScript. So, it introduces that new to the language. And the idea is you'll be able to define your components like this, but you'll be able to have inline logic. So you'll notice that there are for loops and if statements embedded inside of the template. And then anytime we need to define strings or just raw text, we use curly braces for that. So you'll notice there are curly braces here. And so that this is a signal to their compiler that hey, this isn't an element. This isn't other types of syntax. It's an actual string. And then the other cool thing is you get scoped styles by default. So this style tag inside of this component,
these styles defined inside of here are only going to apply to this component. So you might be thinking after seeing this, this looks a little bit like spelt and it absolutely was inspired by the design of spelt. And if you take a look at this counter example here, you can see there are dollar signs thrown everywhere. And so one of the fundamental ideas in this framework is if you define a variable or a prop that starts with a dollar sign, that will automatically signal to their compiler that this thing needs to be reactive. So this count variable is reactive. Meaning if we change it, the UI should update.
This doubled variable is a derived value or a computed value because it's dependent on some other dollar sign value here. So the syntax gets a little bit wonky if you're using it here cuz we're using template strings which have dollar signs in them and then we have the dollar sign variables inside of them. But this one line of code here will automatically update the UI if count ever changes. And then in order to change count, we can actually just directly mutate it. So this is ripple.js JS and uh first of all, why should you care? Well, it was actually created by Dominic Ganoway. And so they're not just some random JavaScript developer. They created Inferno.js uh which is a very fast front-end framework uh that took inspiration from React. They were a former React core team member and they're a current maintainer of spelt.tjs. So the mind behind these ideas has a lot of experience in modern front-end development. So if we take a look at their list of features, it has reactive state management. We talked about that with the dollar sign
Who made this?
Feature List
component-based. One of the nice things is you can define multiple components in a single file. That's one of the things that's trickier to do in things like spelt or view, but you can do that here in ripple. JSX like syntax. If you've been developing in React, looking at this code probably looks pretty familiar to do. And it's highly performant. So I didn't talk about that, but this uses fine grain rendering. There is no virtual DOM. It's basically using the same ideas behind spelt and solid but without signals in order to uh optimize your code ahead of time whenever you run that build script. It also has native control flow. We're seeing that with if and for scope styling and out of the box they do have VS Code, TypeScript and prettier support. So this is Ripple. You can take a look at their GitHub repo that kind of goes through all this stuff. These are the docs and I also these are early days. So Ripple is still alpha software. there are plenty of issues. Um, and the creator is is open to feedback. Um, but you can go through their docs and see all of these different types of ways to define components. And one of the things to
The Docs
Reactive Arrays
note is if you want to have arrays or sets, they did introduce this type called the ripple array. Because if you want to be able to do mutation of variables with a standard array, ripple wouldn't know how to track those changes. So if you want to be able to automatically update the UI whenever something is pushed into an array or removed from an array, you can use a ripple array instead. Now they also have effects. So essentially you can have a callback that whenever the variables it's dependent on have changed, this function will rerun. One of the nice things is you don't have to define your dependency array. So this is very similar to spelt to solid.js.
Effects
Essentially if any of these reactive variables are being accessed inside of that effect, this is automatically going to rerun it. autotracks dependencies, which is great. Your components can also have props. So, if you've ever written a React component that takes in props, very similar idea. The one caveat here is if those props need to be reactive, they start with a dollar sign as well.
Props
And if regular DOM elements like class or ID need to be reactive, you put a dollar sign in front of them. So this is another piece of interesting syntax where if you need that class to automatically change when its dependencies change or if it's dependent on reactive variables, you use dollar sign class instead of just regular plain old class. So some interesting ideas here. I'm going to give you my first impressions and then I'll show you how I built this tasks app. So this is just a a standard hello world and it lets you do things like mark things as done.
My Overall Impressions
We've got some style bindings here. We can filter the list to only show the ones that are to-do or the ones that are done. we can remove from the list. So I used ripple to create this. I'll show you how I did that. But let's talk about some of my first impressions. So when I came across this on some Twitter posts, I went to the git repo and I saw this component keyword. And my initial gut reaction was like I don't think we need new syntax, right? I think one of the reasons why solidjs is so interesting and enticing for a lot of React developers is it just looks like React, right? There's no custom syntax here except for JSX. But at this point, most developers have gotten used to JSX. But with something like SolidJS, they didn't introduce any new syntax. It's all happening at compile time and under the hood. But with Ripple, they introduce this component keyword. So my initial gut reaction was like, uh, not great, but I I came around to it. It's it's nothing crazy. But what does get weird is having control flow inside of your your JSX. But I actually do like this because I do not like having to have
like inline turnaries um or just like conditional expressions. To me, that's where JSX really breaks down and that's where you start to get some really ugly components. Being able to just have an if statement right here is really cool. I will say this takes some getting used to because you almost have to think of it as like it's rendering top down, right? So it's it starts rendering and then when it gets here, it needs to render all of those out. And so basically any flat expression is what actually gets rendered versus being able to put it inside of variables and and reuse it like you would with JSX. Like you cannot store JSX in variables inside of Ripple. Basically once some some JSX is seen by the compiler that is actually getting rendered out in the component.
So I think of think of it almost as like a top down kind of thing. But at first glance I actually do really like the idea of like not having to do map, not having to do turnaries. So this part is is very cool as well. I also really like that they stole scoped styles from spelt. Like why haven't we been able to do this in React? Literally just put a style element inside of a component and make those styles scoped by default. The since we do not have this inside of React, the ecosystem has come up with 10 different solutions. You've got styled components, you've got CSS modules, you've got CSS andJS. There's like a million ways to do this when literally probably the easiest thing to do is just put a style tag in a component and make sure those styles don't leak out. So this is beautiful. I I love that they stole this from spelt and also Vue and uh I really like that piece as well. Now in terms of reactive variables I I will say that this takes some getting used to. So I built quite a few apps with spelt in the previous version and also in the current version. And in the current version they introduced runes with like dollar sign state and dollar sign derived. But before that all variables used to be reactive by
default. So I think it was a good change to basically make it opt in for reactive variables. So you're explicitly saying that hey this thing must be reactive. But in an example like this, everything has a dollar sign on it. So this this uh basically makes your templates like pretty pretty confusing and messy because there's so many dollar signs everywhere. I almost wish there was a way to say that this component all variables were reactive. So if you do something like dollar sign counter, I don't know, they'd have to come up with the syntax, but basically saying any variables defined in here will be reactive. That way you could have reactive by default. At the same time, if another developer comes across that code, like are they going to know to look at the name of the component to know that these are reactive? So, in a sense, this is like very explicit. So, yeah, I don't know how I feel about that. But overall, I think this is a good direction. I think that on the current timeline that we're on, in the current reality that we are experiencing, React one in a big way and it's it's everywhere, right? Everything is built with React, but that doesn't
mean it's the best solution, right? I think React one because it's so customizable and because every person that comes across it can kind of do what they want with it which results in a very fractured ecosystem and that's kind of the current state of things in in the world of React in the world of building front-end applications. So I think React absolutely should be shook up. I I think there should be something new and different and uh I I like where this framework is headed. So let's take a look at how I built this tasks app here.
Tasks App Code Walkthrough
So it's pretty simple. You can add tasks. They show up in the list down here. You can remove them. You can mark them as done and then you can filter the list to show them. And here you can see how many tasks are completed. Now looking at the codes, we have our entry point which is index.ts that just mounts our ripple app right on the element with ID root. And this is just a Vit application. So they created the ripple plugin for Vit. And now we can write ripple code inside of our Vit applications. And if you take a look at our index.html, HTML we are bringing in pico CSS to get some default styles and then right here is where our entire application will live. Now app.ripple is our top level component. You can see that we have export component app and then we can define all of our things. So at the top level is where I defined all of my variables all of my functions that are going to be used in the template itself. So one issue right now is you cannot use generics inside of a ripple file like this. So I tried doing ripple
Entry / index / vite Setup
App Component
array with new task like this but we run into this syntax error. So to get around it I basically had to use their from create an array first and then now this has the correct type. So that's a little clunky but I'm sure they'll fix that at some point. From there you can see that we have our computed value total done. So this is the value that is showing up right here. How many of them are marked as completed? And you'll notice this isn't an effect or anything like that.
Derived / Computed Values
It's literally just a reduce on task. So because tasks is a reactive variable, this total done variable is going to recalculate any time that list changes. And so anytime one of them gets marked as done, this variable is going to recalculate automatically. No effect required. For filtered tasks, this is the list that changes depending on what I click on here. This was a little bit tricky to figure out. For some reason, having this inside of if statements didn't work. So I just had it as a single expression here that's just a nested turnary. So this isn't ideal. I also tried defining this inside of an effect, but basically this is dependent on the current filter. Whatever the current filter is, that is what filtered task should be. So in React, this might be a use memo or you could set a state variable whenever state updates. But ultimately, I had to just define this as nested turnaries. So whenever the current filter changes, change what we're filtering on or display all of the tasks. For adding a new task, we can just push it into the array because we are using that ripple array. When we toggle something as done, we're just marking that property as done. You will
Complex Derived Values
Nested reactive values
notice that I specified done as dollar sign done. So for the UI to react whenever I change done, so to update the done property to be able to update the filtered tasks, this property also has to have a dollar sign on it. So I could see that as one tricky area, especially if you're like pulling data down from an API and then you want that data to now be reactive, you might actually have to iterate over it and then rename any variables that need to be reactive with a dollar sign. This thing is not connected to an API, but when I put it into that array, I do have to use that dollar sign done. So, similar idea. If I was sending this data to an API, I'd have to do some serializing to remove the dollar sign properties whenever I'm sending it to the API. So, that's that's something that maybe they haven't thought about as much, but would be a little bit cumbersome. Maybe there will be some solutions for it going forward.
Uh, for removing a task, we can just splice it out of the array because it is a reactive array. And then setting the filter just sets what is currently selected. Now I have several different components. We've got our form and then our list. If we take a look at the form, it's taking in one prop which is add the task. So the form itself is just an input and then when the value changes, it's updating its state variable here, new task. And then whenever the form is submitted, it is calling that add task function that got passed down as a prop and then resetting the form by resetting the value here. Now the one thing to note is we're not using onchange. In React, we use onchange. But if we actually want it to be on key press, we do have to use on input. I have these scoped styles here. That is our task form. Now, for conditionally rendering out this section, you'll see that by default, it says add a task to get started. So, it's just an if else statement. So, if there are no tasks, it says add a task to get started. If there are tasks, then we're showing the total done versus overall amount. So, if I add a task now, it says 0 out of one. If I check it, it's now done. Now, it's one
Form inputs / events
Conditional Rendering
out of one. So, we just have this inline if statement. It actually took me a second to remember the syntax here because we're referencing a variable. We then want a string. We then have a variable reference and then another string. So this I was getting these weird regular expression errors. And I was like, what's happening? I was like, oh yeah, if I want a plain old string, I need to wrap it in curly braces and quotes. So that took some getting used to. Now for the filter buttons, these three buttons here, I defined a separate component. So let's look at filter buttons. And this takes in the function set filter. So that can set if it's all done or to-do. and then it knows what the current filter is so it can correctly highlight which one is selected. Now, I will say I tried doing this in line because it's not too complex, right? I potentially could have just had this right in line inside the component, but I was running into some compile errors. So, I think mixing if statements with for loops isn't quite there just yet. I'll have to file a bug to figure out what was going wrong. But the moment I extracted it to its own component, things were good to go. So, basically, we're going to iterate over
Nested if / for statements
all to-do and done. And then for each of those, we're going to create a filter button. And the filter button is in charge of displaying the correct text and then setting that specific filter uh when it's clicked. So if we look at filter button, nothing too crazy. Takes in those three props, renders it out. And then here we can see this dollar sign class binding. So basically, in order to display that button differently, we're adding the contrast class which is provided by Pico CSS. But whenever the filter changes, the contrast class needs to be applied to the one that is actually selected. So in order to get this to be reactive, we have to say dollar sign class. And this is a signal to the ripple compiler that hey, if this thing ever changes, we do need to update that attribute there.
Reactive class bindings
Reactive props
From there, we have our list of tasks. So I'm passing down that full reactive array. You'll notice that I had to put dollar sign tasks in the prop name as well. So before, even though I'm passing down a variable that is reactive, if the prop itself was not called dollar sign tasks, then uh it wouldn't be reactive inside that component. So the prop itself needs to have a dollar sign on it as well. And then I just passed down those two methods for toggling as done and removing. If we take a look at the task list, nothing crazy. Just got a for loop with some weird formatting. So we are using prettier, but it's not perfect just yet. Sometimes I have to manually format this to get it to display in the way that you probably would want it. So this is probably how we want to look at it. So iterate over the tasks array that's coming from our props for each one. We'll render it out. And one thing that I did have to do here is a custom style binding. So basically whenever we mark something as done like so I want to show that line through it. And one of the first things I tried is to have a reactive class binding. So I had a class
Reactive style bindings
called and this had text decoration of line through. And so whenever dollar sign done was true I wanted to apply that class. But because that class was not applied by default the ripple compiler actually stripped away this class because it was like oh you're not using that. and then it was only applied when done was true and then it didn't show up at all. The other thing is even if I tried making sure that the class didn't get removed. So if I had like a span down here that was just class done, I basically just did this so that Ripple would know that it should compile this class called done. But even with that, my class binding didn't work because this is technically like a compiled scoped style with like a custom attribute on the end of it. So if you were to just add the done class to some other element, it doesn't apply to it.
And so right now there, as far as I could see, there's no way to really access the compiled name of that class if you want to conditionally add it. So all of that to say, I had to do a direct style binding instead of a class binding. And as far as I can tell, style bindings do not support object syntax like you can do inside of React. So instead of object syntax, I had to do just your standard old style string. And if task is done, set text decoration to line through, otherwise set text decoration to none. So, they still need to do some work in terms of figuring out how to work with scope styles and reactive bindings. And then it would be nice if we were able to define styles with object syntax, which I'm sure they're probably working on as well. So, that's the app that I built. I hit a few corners that they really hadn't thought about just yet, and I had to do some things to kind of get things working, but I'm going to file issues for all of the type errors that I ran into and that class issue that I ran into as well. And um they'll potentially work on it in the future. So overall my experience working
Impressions after building with Ripple
with it, it was fine. It was like learning a new framework. You figure out what are the the exact ways to do things. It took a second to figure out like the conditional syntax and remembering that I need to wrap things in quotes. But overall, as a developer that's worked in all the frameworks, React felt view solid Angular, this this felt just fine to work inside of. I'm excited to see where they go with this.
Thanks!
All right, that's all I got for you, but let me know down in the comments. Are you going to try Ripple? And what do you like about it? What do you not like about it? let me know down in the comments. Um, like I said, I'm excited about new frameworks. I'm excited about better ways to do things than React because React is currently the default and especially in the age of LLMs, they're just pooping out React code. We need something better and it looks like Ripple is uh on their way to being something potentially better than that.
Quote it with credit and a link. Quoting Syntax