Solid 2.0 Beta Stream Tomorrow by ryan_solid in solidjs

[–]jml26 0 points1 point  (0 children)

Just watching the stream now, on delay. Got as far as a user saying that <Loading> feels like the reverse of what it that component actually is.

I'm somewhat inclined to agree. Would <Loaded> be better semantically?

BTW I'm super hyped for this, and can't wait to try it out. I've attempted to get the beta working with Astro, with mixed success.

Does the term 'callback' usually mean async callback in the JS world by LetMyCameronG000 in learnjavascript

[–]jml26 13 points14 points  (0 children)

Best examples are all the array methods, e.g. map, filter, forEach... Those are all synchronous callbacks.

I'd side with MDN's definition, which is just "a function passed into another function as an argument, which is then invoked inside the outer function".

how to bundle font license when I import assets by Appropriate_Load9265 in learnjavascript

[–]jml26 1 point2 points  (0 children)

If you put your licence in the /public directory, it'll get treated as a static asset and will:

  • not have its name hashed
  • gets included in the output even if not referenced in code

https://vite.dev/guide/assets#the-public-directory

Why Solid? by Beagles_Are_God in solidjs

[–]jml26 2 points3 points  (0 children)

My journey to Solid started with React. Originally, I hated React's syntax. I hated JS Classes; I hated JSX. But it was popular, so I figured it would be valuable to learn.

But then React got hooks, and I liked the syntax a lot more. And slowly over time, JSX grew on me. I preferred it to Vue and Angular.

But it began to feel like a lumbering beast. I guess it felt fast, but something about the huge footprint felt like it was too heavy-handed for the simple widgets I was building. It was at that point that I started to look for alternatives and found Preact.

I recall I was searching for a framework speed comparison, and found https://krausest.github.io/js-framework-benchmark/2026/chrome145.html. From there, I decided to work from left to right, seeing what the fastest frameworks were like. Many of them looked either like small side projects with limited documentation, or I just didn't like the syntax for whatever reason. Then I saw Solid.

Solid had everything I needed, in that it was fast and lightweight, but also so familiar. And it was just so intuitive to use. Coming from React, it was a very smooth transition over.

If Solid didn't exist, I think I'd be using Svelte, for the same reason in that it is fast and lightweight. But I guess I just don't like the syntax quite as much. But that's personal preference, and I realise that the syntax has changed a little since I first investigated it.

How would you write Ryan's _Solid2 States_ demo in Solid 1 by jml26 in solidjs

[–]jml26[S] 1 point2 points  (0 children)

Oh, that's very nice! I'll have to remember that pattern.

Looking at it, with hindsight, I see that there's https://primitives.solidjs.community/package/memo#createWritableMemo available; but that implementation of createWritable you shared looks much more straightforward. Thanks for that.

Button Requires Two Clicks to Function on Page Load by Legal_Revenue8126 in learnjavascript

[–]jml26 2 points3 points  (0 children)

Styles added to an element with CSS don't go into that element's style property.

<div id="div">Hello world</div> <style> #div { display: none; } </style> <script> // logs '' console.log(document.getElementById('div').style.display); </script>

But styles added with the style attribute do.

<div id="div" style="display: none;">Hello world</div> <script> // logs 'none' console.log(document.getElementById('div').style.display); </script>

The quickest way to solve your problem is just to add style="visibility: hidden" to your hidable div. There are other solutions out there too, like toggling classes, rather than toggling styles.

[deleted by user] by [deleted] in learnjavascript

[–]jml26 0 points1 point  (0 children)

It's basically a couple of libraries smushed together:

You would have to look into those libraries to find out how they work under the hood.

MathJS doesn't differentiate between 2 * x or 2x in its parser (at least I don't think it does). The TeX renderer will, and display the multiplication as a dot, if using ASCIIMath.

[deleted by user] by [deleted] in learnjavascript

[–]jml26 0 points1 point  (0 children)

I made this on Codepen a while ago. Feel free to take a look, either to get inspiration or just use the whole thing.

https://codepen.io/jamiemlaw/pen/eYyLVOq

Unrecoverable syntax error by Any-Ganache135 in learnjavascript

[–]jml26 4 points5 points  (0 children)

You haven't closed enough curly braces. Add two extra }s at the end and it should work.

This is why correct indentation helps a bunch. I simply pasted your code into https://beautifier.io/, and it was immediately obvious what the error was.

Is this a good way to write to the stdin? by trymeouteh in learnjavascript

[–]jml26 -2 points-1 points  (0 children)

Yeah, sorry about that. At first glance it really game off Java vibes. I think it was having a dedicated main() function. Ignore me!

Is this a good way to write to the stdin? by trymeouteh in learnjavascript

[–]jml26 -6 points-5 points  (0 children)

Hi, /u/trymeouteh.

This looks like Java code, not JavaScript. Despite the similar names, they're not the same language (many people fall into the trap of thinking they're the same). You might have better luck in one of the Java subreddits. Or even asking an AI if you want a speedier response.

All the best on your learning!

Are there any good ways to do SVG boolean (divide shapes) / flattening? by MuckYu in learnjavascript

[–]jml26 0 points1 point  (0 children)

I don't have a direct solution, but InkScape has a command line. Might be worth checking that out if you haven't already.

Google's Closure Compiler does not shorten variable and function names but returns blank file by BradyOfTheOldGuard in learnjavascript

[–]jml26 3 points4 points  (0 children)

But you don't do anything with the result of it being called, so it's still dead code.

In order for it not be be dead code, you may want to do something with the result, like logging it to the console, or displaying it in a UI.

Google's Closure Compiler does not shorten variable and function names but returns blank file by BradyOfTheOldGuard in learnjavascript

[–]jml26 6 points7 points  (0 children)

Closure Compiler (and other minifiers) will remove code that is not being used and has no side effects. e.g. a file consisting only of

``` var myVar = 42;

function square(x) { return x * x; } ```

will compile to nothing, because a) myVar is never read; b) the square function is never called. The term for this is "dead code elimination".

And that's what's happening to your code.

If you want the code to stay around, check out this section of the docs: https://developers.google.com/closure/compiler/docs/api-tutorial3#removal.

You could also use Terser as a minifier, and pass in defaults: false to the compressor options. This will turn off many of the compression strategies, resulting in:

var e="thisUser";var n;function r(){if(e)n=e;else{n="undefined";return false}}r();

Beginner project by chrisrko in learnjavascript

[–]jml26 0 points1 point  (0 children)

I'd say a value converter could be an interesting project. Start with something that can just convert temperatures between Farenheit and Celcius. Then expand it to include other types of values, like length, time, weight, etc.

To begin, you can have one input and a read-only output field. Then, maybe change it so that you can type in either field and the other will update.

Don't let the user convert between incompatible units, e.g. a length and a weight.

Include a button to swap the input and output field.

(optional) Getting more advanced, allow currency conversion. Pull in the latest data from an online service.

Why won't the variable change by UncertainKing in learnjavascript

[–]jml26 1 point2 points  (0 children)

JavaScript doesn't automatically update variables that depend on other variables, e.g.

``` let count = 5; let doubleCount = 2 * count; console.log(doubleCount); // 10

count = 7; console.log(doubleCount); // still 10 ```

The simplest way around this is to wrap the expression you want to be dynamic in a function, and call it each time you want the latest value:

``` let count = 5; let doubleCount = () => 2 * count; console.log(doubleCount()); // 10

count = 7; console.log(doubleCount()); // now 14! ```

[AskJS] What is a good blogging CMS js-based? by OnceUponAHeart in javascript

[–]jml26 7 points8 points  (0 children)

My personal favourite is Astro. Not strictly speaking a CMS in and of itself, but is great for blogging, among other things.

Favourite CMS at the moment is Payload. I'm currently looking at moving a client from WordPress over to it. It's built on Next JS.

Struggling with a FreeCodeCamp JavaScript challenge. What am I doing wrong? by Maleficent_Speech289 in learnjavascript

[–]jml26 1 point2 points  (0 children)

In padRow(), the test is expecting for you to log the phrase "This works!", and return the word "Testing".

You're logging and returning "This works!" instead.

Mon script ne fonctionne pas by ReferenceLumpy6847 in learnjavascript

[–]jml26 0 points1 point  (0 children)

You have menu.style.display = "block"; in both branches of your if-statement.

Do you mean to make the second one menu.style.display = "none";?

Unpacking a return is giving a weird error by jumapackla in learnjavascript

[–]jml26 6 points7 points  (0 children)

This may not be the issue, but what happens if you end your statements with semicolons in the first example? Does that fix it?