Sign Up Now!

Sign up and get personalized intelligence briefing delivered daily.


Sign Up

Articles related to "javascript"


From Promises to Observables

  • I was so impressed with RxJS that I went home and actually used Observables to improve performance for one of the pages on my site andrewevans.dev.
  • Specifically I'm going to show how I was able to use RxJS to manage multiple HTTP calls at once, and how this significantly improved my user experience.
  • Instead of having to specifically build code around handling different events, RxJS enables you to use observables and operators to do the work for you.
  • RxJS is a safe way to handle events in your code through the predefined behaviors and contracts that come with the observables.
  • The resulting experience from this code was that (in the Angular client) I had to provide a traditional spinner on the page to show until all of the promises completed.
  • Now for the RxJS implementation, I wrapped each of the HTTP calls to this endpoint in a separate observable.

save | comments | report | share on


React vs Angular: A Comparison

  • One of the main difference between Angular and React is that AngularJS is a full-fledged javascript framework which is based on MVC architecture.
  • Another important difference between Angular and React is the behavior of the DOM.
  • As it is a full-fledged MVC framework, Angular supports two-way data binding.
  • The way of rendering data may differ in angular and react, but the components are common in both.
  • React uses javascript for writing logics of the app.
  • Clearly, in the popularity, ReactJS is the winner, but as I said earlier, this does not mean React is better.
  • Both Angular and React are heavily used in modern web development.
  • Angular and React are the most popular and widely used web framework and library, respectively.
  • Either way, whether it’s React or Angular, it is highly recommended to use tools like Bit to share your components and collaborate with your team.

save | comments | report | share on


I WebRTC you - building a video chat in JavaScript

  • In a nutshell, WebRTC allows you to build apps, that exchange data in real-time using a peer-to-peer connection.
  • For instance, Signal calls are done over pure WebRTC, and due to the peer-to-peer nature, work mostly without sending your call data through a third party, e.g. like Skype does now.
  • Once the called party receives an offer, it peer.createAnswer() specifying its own capabilities, e.g. if it'll also send audio and video.
  • Both parties need to exchange an offer and answer, and they need to know the other side's ICE candidates, or they won't know where to send their audio and video streams after all.
  • Our handleMessage function closely follows the sequence diagram above: When Bob receives a start_call message, he sends a WebRTC offer to the signalling server.

save | comments | report | share on


Docker for front-end developers

  • To fully understand the aforementioned terminologies, let’s set up Docker and run an example.
  • Let’s run a Docker container using Node.js.
  • Since this post is focused on front-end developers, let’s run a React application in Docker!
  • For that, I recommend using the create-react-app CLI, but you can use whatever project you have at hand; the process will be the same.
  • In this file, you’d normally specify the image you want to use, which files will be inside, and whether you need to execute some commands before building.
  • When working in yarn projects, the recommendation is to remove the node_modules from the /app and move it to root.
  • In case you want to keep the changes to the container in your file system, you can use the -v flag and mount the current directory into /app.

save | comments | report | share on


Docker for front-end developers

  • To fully understand the aforementioned terminologies, let’s set up Docker and run an example.
  • Let’s run a Docker container using Node.js.
  • Since this post is focused on front-end developers, let’s run a React application in Docker!
  • For that, I recommend using the create-react-app CLI, but you can use whatever project you have at hand; the process will be the same.
  • In this file, you’d normally specify the image you want to use, which files will be inside, and whether you need to execute some commands before building.
  • When working in yarn projects, the recommendation is to remove the node_modules from the /app and move it to root.
  • In case you want to keep the changes to the container in your file system, you can use the -v flag and mount the current directory into /app.

save | comments | report | share on


Understanding Rest Parameter Syntax

  • But hopefully, this post will help you understand how spread and rest are different yet similar.
  • Let's say that you want to pass in an unknown number of arguments to a function.
  • That's when you want to use the rest parameter!
  • In this example arg1 and arg2 are passed through as expected, then all of the additional arguments are added to the otherArgs array.
  • Additionally, not including any additional arguments will result in an empty array.
  • As it turns out, you can use destructuring and the rest parameter together.
  • Keep in mind that destructuring expects the arguments to be there.
  • If you don't include a destructured expected argument, it will result in an undefined reference.
  • As you can see in the examples above the main difference between rest and spread is location.
  • Rest parameter syntax is limited to the function signature itself.

save | comments | report | share on


JavaScript Developer Resume Sample & Template (A/B Tested Word Version)

  • Real JavaScript Developer Resume Sample To Download - The Only Resume Template You Need To Land JavaScript Developer Job. Inspired JavaScript Web Developer with 6+ years of strong experience in Graph Databases, Testing, DDD/TDD areas with willingness to learn and master SEO and Web Components.
  • Microservices & Containerisation specialist.
  • Sore eyes?
  • Go to the "misc" section of your settings and select night theme.

save | comments | report | share on


Reducing Motion to Improve Accessibility

  • In this post, I am going to walk you through a newer media query (to me): prefers-reduced-motion.
  • Andy Bell's dark mode post inspired me to add the user-controlled option.
  • However, if JavaScript doesn't load, we want to fallback on system preferences when the data-user-reduced-motion attribute doesn't exist.
  • Then we add the CSS outside the query for if the data-user-reduced-motion="true".
  • Now what we want to do is create a default localStorage state for the user if the reduceMotionOn is null.
  • The last thing I am going to do upon mounting the component is set the state in the app.
  • If you go to React Dev Tools and go to the <ReduceToggle /> component, you’ll find that the checked state matches the reduceMotionOn localStorage item.
  • Now if I check Reduce motion and leave the site, my user-controlled preferences are preserved!

save | comments | report | share on


Document your Javascript code with JSDoc

  • In this post I'll try to cover everything you need to know to get started with JSDoc. I'll also share with you some other cool stuff I learned about it that you might find useful.
  • Once your code is fully documented you can easily generate a website containing all the API documentation by running a simple command.
  • Now, to be honest, even though I've been using JSDoc comments to document my code for a long time, I didn't install this package until a few weeks ago because I didn't actually needed to generate the website.
  • Simply call jsdoc and add the path to the file or folder.
  • You can create your own template for your API documentation by generating a custom layout.tmpl file and setting the option templates.default.layoutFile to the path of your custom layout in your JSDoc configuration file.

save | comments | report | share on


Why I stopped spreading props on React Components

  • Spreading props on a React Component is a very common pattern that I picked up very easily and loved from day 1.
  • A good scenario to demonstrate how props spreading can really shine is HOCs. Let's look at this example.
  • Being able to spread props like so <Comp {...props} /> is really powerful because we are free to enhance any component we might have.
  • We either become sloppy and allow any, which makes me question why we're even trying to type this thing, or we have to open the 'Actionable' implementation, check how props are handled there and hope that there's not another spread there (which is highly possible) otherwise we'll have open yet another file.
  • While we can't be 100% sure about every single type in this list of props we can do a lot without looking any further.

save | comments | report | share on