JavaScript

2086 readers
14 users here now

founded 2 years ago
MODERATORS
1
 
 

The title says it all. Let's talk about one of JavaScript's most underrated features: Object.freeze(). This powerhouse of immutability isn't just another method - it's your secret weapon for writing safer, more predictable code ✨.

I'll be honest, when I first discovered Object.freeze(), I mostly ignored it. "Just don't mutate your objects," I thought. But as my applications grew more complex, I started to see its true value. Now, it's an essential part of my toolkit.

2
 
 

hello. I recently asked here for help with Lemmy HTTP API and someone said "why don't you use lemmy-js-client?". i tried to add it and...

first i searched the internet about this library and it turns out that it is an npm library... (I have github pages) i searched different variations of the library and found a cdn version of it. i tried to add it. it was a hell of a torture.... i added it the way I add cdn libraries, nothing. i searched all over the internet, but found null. i even asked chatgpt! to no avail. the library (and everything I tried to get out of it) turned into undefined!

what am I supposed to do? this is cdn version what i tried to add
if u want here is source code

3
 
 

hello! im developing lemmy client (on html5). i tried to do login function but... when i try to fetch /v3/user backend with auth-token it give me error:

{
  "error": "no_id_given"
}

but why? what im doing wrong? if you want here is my source file on github ( function: getLoggined() )

4
 
 

hello! im developing lemmy client (on html5). i tried to do login function but... when i try to fetch /v3/user backend with auth-token it give me error:

{
  "error": "no_id_given"
}

but why? what im doing wrong? if you want here is my source file on github ( function: getLoggined() )

5
6
7
4
State of JavaScript 2024 (2024.stateofjs.com)
submitted 1 month ago by [email protected] to c/javascript
8
9
0
submitted 1 month ago* (last edited 1 month ago) by xoron to c/javascript
 
 

i wanted to see if we can create asynchronous bottom-up state management, we have the basics to put together a state management system. State management solutions in apps typically have ways to persist data.

I wanted to explore if there are any benefits to define and manage state in webcomponents with a bottom-up approach. I wanted to see if it could give a greater flexibility in developing a UI and not having to worry about persisted storage management.

https://positive-intentions.com/blog/bottom-up-storage

10
11
12
 
 

On November 22, 2024, Deno formally filed a petition with the USPTO to cancel Oracle’s trademark for “JavaScript.” This marks a pivotal step toward freeing “JavaScript” from legal entanglements and recognizing it as a shared public good.

Oracle has until January 4, 2025, to respond. If they fail to act, the case will go into default, and the trademark will likely be canceled.

13
13
submitted 2 months ago by arendjr to c/javascript
14
5
submitted 2 months ago* (last edited 2 months ago) by xoron to c/javascript
 
 

im working on a javascript UI framework for personal projects and im trying to create something like a React-hook that handles "encrypted at rest".

the react-hook is described in more detail here. id like to extend its functionality to have encrypted persistant data. my approach is the following and it would be great if you could follow along and let me know if im doing something wrong. all advice is apprciated.

im using indexedDB to store the data. i created some basic functionality to automatically persist and rehydrate data. im now investigating password-encrypting the data with javascript using the browser cryptography api.

i have a PR here you can test out on codespaces or clone, but tldr: i encrypt before saving and decrypt when loading. this seems to be working as expected. i will also encrypt/decrypt the event listeners im using and this should keep it safe from anything like browser extensions from listening to events.

the password is something the user will have to put in themselves at part of some init() process. i havent created an input for this yet, so its hardcoded. this is then used to encrypt/decrypt the data.

i would persist the unencrypted salt to indexedDB because this is then used to generate the key.

i think i am almost done with this functionality, but id like advice on anything ive overlooked or things too keep-in-mind. id like to make the storage as secure as possible.

15
 
 

Generally, it is inadvisable to directly expect in if-clauses. Here are some tips to avoid these situations.

16
4
Async Javascript State Management (positive-intentions.com)
submitted 3 months ago by xoron to c/javascript
17
 
 

https://positive-intentions.com/blog/qr-codes-as-a%20data-channel

QR Codes as a Data Channel

the demo in the blog article is a bit cluncky. here is a better link for it: https://chat.positive-intentions.com/#/qr

18
13
submitted 3 months ago by pastelmind to c/javascript
 
 

TL;DR:

  • Many websites are (unintentionally) shipping ES6+ code in production. This indicates that transpiling to ES5 is outdated practice.
  • We need a better baseline for transpilation, which should be a moving target.
  • We should transpile code in node_modules, at least for production.
19
 
 

Should I create functions/methods for packages/libraries that allow optional parameters to accept null?

In this example below, I set the 3rd and 4th parameter as null which will act as the default value.

myLibrary.myFunction(1, 7, null, null, true);

Or is this not a good way to go about creating functions for a package and therefore should not accept null as a parameter value.

myLibrary.myFunction(1, 7, false, 4, true);
20
 
 

In PHP ecosystem there is a tool called Rector. It helps a lot in automated refactoring. It helps a lot in updating from a bad design pattern to another, update code to match a given framework updates, etc.

Maybe we could create a similar tool for client side Javascript to migrate away from jQuery to vanilla Javascript. Websites youmightnotneedjquery.com have a good collections of vanilla JS alternatives to jQuery.

While one could do it manually, on larger code bases, it is extremely tedious.

Maybe such tool exists and I am unaware of it?

At first, I thought about having such transformation as an optimization step in the bundler, but this is unnecessarily redundant and might cause a lot of troubles.

21
22
6
React-Like Functional Web Components (positive-intentions.com)
submitted 3 months ago by xoron to c/javascript
23
24
 
 

https://positive-intentions.com/blog/dim-functional-webcomponents/

im investigating an idea i have about functional webcomponents after some experience with Lit.

Lit is a nice lightweight UI framework, but i didnt like that it was using class-based components.

Vue has a nice approach but i like working with the syntax that React used and i wondered if with webcomponents i could create a functional UI framework that didnt need to be transpiled.

i think the article is already quite long, so i think i will create a separate one as a tutorial for it.

note: im not trying to push "yet another ui framework", this is an investigation to see what is possible. this article is intended as educational.

25
view more: next ›