Questions tagged [javascript]

JavaScript (not to be confused with Java) is a high-level, dynamic, multi-paradigm, weakly-typed language used for both client-side and server-side scripting. Use this tag for questions regarding common implementations of ECMAScript, JavaScript, JScript, etc. JS does not typically refer to its ECMA-cousin, ActionScript.

Filter by
Sorted by
Tagged with
0
votes
0answers
24 views

Memory management in node.js

I'm writing a web server as a test project in node.js Whats really bothering me so far is the lack of control or even awareness of memory usage. Naturally I want to cache some stuff in RAM for faster ...
1
vote
1answer
35 views

Tips for module naming and criteria for grouping files in a directory

It appeared, that I have in my pet project two abstractions: asset loaders and drawing tasks. For each abstraction I have some classes representing them (currently a single class for drawing task ...
0
votes
0answers
38 views

How could I reuse common JS modules between several projects?

At my company, we are developing pretty simple React Native and sometimes mobile-only React apps. Most of them have some similar logic, such as 'sign-in by phone' flow, some payments stuff, etc., and ...
-2
votes
1answer
42 views

React class or function for stateful components?

Which is better to use? react class based stateful component or react hooks functional stateful component? I've searched a bit but couldn't find what is preferred to use.
2
votes
1answer
83 views

Many small files vs fewer larger files: impact on bundle size and build time

I've been a relentless proponent of small files. I prefer one function export per file, functions with everything-in-one-view, and breaking up UI components as much as sensible (which is why I love ...
0
votes
2answers
90 views

What is the best practice for incorporating asynchronous code in this case?

Context: I'm building a popup widget. The html and css files are stored in S3. I need to get those files asynchronously and then continue with the rest of the logic. In the code below, I'm getting ...
1
vote
0answers
116 views

How & Should we use Clean Architecture in Front-end?

Just a little explanation: "I'm used to be a solo front-end developer in my company and using default folder-structure and way of coding which vue-cli provided, it is good for a solo developer and ...
3
votes
3answers
92 views

Read large JSON file and return a subset for map

To some extent, this is a wide question, because I do not know in which direction I should move. I am using Polymaps to show markers on a map. The markers are static but the visualization depends on ...
0
votes
0answers
38 views

Should I create Thumbnail of video in Web App (client-side) or Lambda/Server-side?

I am trying to create a thumbnail from a video that I'll be uploading to my Web App(React). And then I'll upload that video to AWS S3, and thumbnail(image) to S3 as well. I wanted to know where ...
-2
votes
0answers
47 views

Change of frontend technology from JSF to Angular

Here is the situation. There is a new project approaching, It will be a sequel of present project. The development of JSF takes too long. The plan is to change frontend technology from JSF to Angular ...
-4
votes
0answers
79 views

Return result at the same line, without defining intermediate variable, pattern or anti-pattern? [duplicate]

I haven't found discussion on this topic. If there's an old discussion here where this issue has been discussed please link it, and I'll close my question. Two examples: function random(number) { ...
3
votes
3answers
277 views

How to manage chaotic code explosion in React application

So we decided to redo UI of our web application in React. Six months down the lane and we have a complete mess of components and reducers and thunks and actions and god knows what not. We have ...
2
votes
0answers
27 views

React Hooks: using state in useEffect without depending on it

I have run into a situation in React where I want to run a function F in a useEffect hook whenever a value V1 from the store changes. F uses another value from the store V2. I only want to run F when ...
0
votes
2answers
120 views

Should we check if the primary key exists if rendering a collection fetched from database?

I have got an argument with my colleagues about this. IMO It's common practice that you don't need to check if an id exists or not before rendering it. So here's an example. This is what my ...
1
vote
2answers
115 views

How to refactor duplicated functions with only one difference in parameter list

I've got 2 near-identical functions (NodeJS). One of them queries DB for shop information by its phone number, while the other one queries by its id. I'd like to know if there's a clean way to merge ...
-1
votes
2answers
107 views

Why don't people usually use asserts throughout their application?

I usually do Javascript and I like putting console.assert liberally in my application. It throws an error if the first argument is falsey. E.g.: console.assert(price > 0, 'Price isn\'t above 0') ...
2
votes
4answers
580 views

When a function can take a single item or multiple, is it better to have more than one function or just one function that takes arrays?

Consider something like.... (Pseudocode Javascript like) var capitalizeWord: function(word){ word.toAllCaps(); } What if now I need to do multiple words, but still sometimes only do one still. ...
0
votes
1answer
63 views

Should Javascript events always emit to window?

I'm going to start with the opposite of my question: why should events emit only to a specific context when your code is supposed to be easy to interact with? In the JS world, you can emit events ...
0
votes
0answers
12 views

Dynamically retrieve associated data in View

I'm afraid on StackOverflow this question might be rejected as "opinion based". I'm using CakePHP 3.7.9 and in one View I have a form with a select and a number input: echo $this->Form->...
0
votes
1answer
46 views

When should javascript files be loaded

I am using a great deal of jquery. I have several "sub-pages" that are loaded into a main div by a menu click. Each of those sub pages has an associated javascript file. I have been loading the ...
-2
votes
2answers
44 views

Alternative to RLE for short, infrequent runs

I have 3 number arrays that I need to encode into a URL through query parameters. Example: http://localhost:3000/?r=133223333302302040&y=10000000000000000000&b=13333332002100122331 This is a ...
3
votes
1answer
153 views

VueJs - composing components for large scale projects

I started getting into VueJs and Vuex development and I'm looking for a "mainstream" architecture for large scale projects. I think the question doesn't depend on whether you take a ready to use UI ...
9
votes
2answers
380 views

Jumpy Code with Descriptive Function Names

I'm currently building out some functionality on a page. When writing JS I've been making a set of smaller functions like FindCarouselLocations(elem), GetImagesFromLibrary(url), and BuildCarousels(...
-2
votes
3answers
151 views

Good practice for JavaScript (ES6) data objects

I see very often to pass around unnamed data objects in JavaScript, e.g. { a: 1, b: 2}. Is it a good practice or is better to make a simple data class for that like in other languages: class ...
153
votes
4answers
29k views

Why is JavaScript not compiled to bytecode before sending over the network?

You'd often see that JavaScript is actually being transported over the web with all the useless stuff that doesn't need to be there -- Comments, particularly those containing licenses, indentations ('\...
1
vote
1answer
54 views

maintain server business logic for multiple version of offline client

I have an offline application and the data is 2-way synchronised between server and the app using pouchdb-couchdb. One requirement is both the server and the app must able to mutate the application ...
1
vote
1answer
109 views

How do JavaScript engines convert async/await to promises under the hood?

I'm curious how the async/await syntax is converted to Promises. Maybe I'm just not thinking about it properly, but I don't know how this code would be converted to a Promise: async function myFunc(...
1
vote
1answer
52 views

Does it make sense to use reflection or to hard-code controller parameter names in JavaScript?

So I have made a pull request to change this code: //Controller: ... [HttpPost] public ActionResult Unauthorize(int userID, int permissionID) { ...
-1
votes
1answer
41 views

Can Ionic apps be easily ported as a Web Application?

I am newbie to angular and Ionic world and trying to figure out the right stack to get started with my requirement to develop a hybrid mobile app. I understand that Ionic is a wrapper around other ...
-4
votes
2answers
97 views

How can I calculate the radius of an arc given by a series of points

Given a series of points, I need to assert that the plotted points form an arc (with a certain level of confidence), and I need to approximate the radius of the arc. For example, the following points ...
2
votes
1answer
164 views

Form validation code shared in the frontend and backend API?

I have a legacy Java monolithic web application. My goal is to use React on the frontend, keep Java on the backend and add an API for the frontend to use. My question is how can I write the data ...
-3
votes
1answer
140 views

How to make code runnable on open source code editors like Ace Editor?

For my computer science uni project I'm required to build a web application with an integrated code editor. I believe I can just integrate open source editors like Ace Editor. However, I feel ...
0
votes
1answer
42 views

Documenting JavaScript types received from API in VueJS

I'm using VueJS and have data coming as json via web API. The API is strongly typed, but in my Vue component, I don't have a good way of knowing what the types being passed are. Given the following: ...
0
votes
2answers
81 views

Code style to keep track of nested objects and data types?

In untyped languages (Python, Javascript specifically) find myself making a lot of bugs / wasting a lot of time because I forget what's in the objects I'm passing around. For example, I forget things ...
0
votes
0answers
36 views

Managing adjacent components

(originally asked here, but aparently not the right place) I managed to create a minimalistic example to reproduce the confusion I'm facing, here's a working SandBox. I have a page ( see the Profile ...
2
votes
1answer
49 views

ReactJS - lift state to main container or export a helper?

I'm using ReactJS (React Hooks, specifically) to build an application. Part of that application involves account creation, sign-in, and authentication. I only recently finished the sign-in feature, ...
1
vote
2answers
94 views

Node.js error handling through each layer

I am looking for a way to handle errors in a Node.js application without getting lots of log entries for the same error event, one from each each affected layer. This might actually apply to any ...
1
vote
1answer
50 views

Transpiling in npm modules

While recently creating a module for shared functionality between our projects I stumbled upon this question. Should the module be occupied with transpilation of code to older browsers that our ...
2
votes
1answer
332 views

Domain classes in DDD structure in React apps?

I'm building an Electron app using React. I'm coming from the C# and WPF world and I'm wondering, where should my domain classes go? I understand the concept of components, but what about a class with ...
0
votes
0answers
52 views

React CRUD patterns

My strategy with react forms has always been (psuedocode): CreateFoo - simply hooks up redux actions to save new record - onOk = (draft) => dispatch(addFoo(draft)); - return <FooForm onOk={...
0
votes
0answers
50 views

Ist good practice adding Converter Between api and client

I just want to curious about adding a converter is a good practice or not. I have multiple API and I always convert API return fields to my client fields. Like=> function ConvertFromAPI(apidata){ ...
3
votes
3answers
190 views

What is an example, in Javascript, of the difference between Abstraction and Indirection?

I thought I understood what abstraction meant - refactoring code so that it applies to more general use cases. However I have recently learned that some types of abstraction may actually be ...
0
votes
2answers
157 views

How can I emulate Signals and Slots found in Qt, to Javascript / Typescript Classes?

Ive brought this up with other developers, and they say while there is no obvious way forward, it seems that they all have an idea of how to go about it. Is there any way I can implement signals and ...
2
votes
1answer
46 views

Best practice in synchronized form data validations (Web apps - Client-Server)

Here we go again with topic what was asked many times all over internet, but I not found any good enough answer: What are best practices in making client and server side validations synced? I was ...
3
votes
0answers
93 views

data transfer objects between abstraction layers

I want to create an Express REST API and want to try following the clean architecture ideas. I was reading about it but didn't get the idea of the communication between the abstraction layers. Let's ...
0
votes
1answer
154 views

Passing javascript function vs use imports in Svelte or React component

I wanted to use some function from javascript module in one of my component. Should I pass it in props when making the component or should I just use Imports in component itself to get the javascript ...
0
votes
0answers
25 views

Methods for storing data pre-registration in a web app

I have a web app - it's more complicated than a todo list but for simplicity sake let us assume it is a todo list. The user has the choice to sign up and create an account thus allowing them to store ...
0
votes
1answer
25 views

Contemplating about API design of a typescript/nodejs library for querying a remote storage service

I am working on a Typescript library (to be used by many users within my org, possibly open-sourced) which provides access to some remote storage. I am contemplating between several variants for the ...
2
votes
1answer
101 views

Is this the right way to handle errors using the fetch api?

I am using the fetch api in my handleSubmit function in a React component to post data like this: handleSubmit(event) { event.preventDefault(); var error = false; var { username, password } = this....
0
votes
0answers
24 views

Confidentiality concerns in including all state+actions crash report

I am working on creating a method to send crash report details for an Office Add-In created with Redux. Because of the way Redux works, it is possible to get the entire application's state as well as ...

1 2 3 4 5 39