Posts tagged with javascript

Clean up your Vue modules with ES6 Arrow Functions

On the .dev blog Jacob Bennett shared some nice refactorings using arrow functions.

Recently when refactoring a Vue 1.0 application, I utilized ES6 arrow functions to clean up the code and make things a bit more consistent before updating to Vue 2.0. Along the way I made a few mistakes and wanted to share the lessons I learned as well as offer a few conventions that I will be using in my Vue applications moving forward.

https://dotdev.co/clean-up-your-vue-modules-with-es6-arrow-functions-2ef65e348d41

Read more

Join 9,500+ smart developers

Every month I share what I learn from running Spatie, building Oh Dear, and maintaining 300+ open source packages. Practical takes on Laravel, PHP, and AI that you can actually use.

No spam. Unsubscribe anytime. You can also follow me on X.

Beyond Console Debugging Tricks

Daniel Reis shows some alternatives for the best known form of debugging JavaScript console.log.

I don’t consider myself a nitpicker. That’s only true, and it’s all fine and dandy… until I find a console.log() that someone forgot to remove from the JavaScript code. And if we’re talking about debugger statements… all hell breaks loose! ... I collected some of the most common examples I can present as proper alternatives for that process.

https://medium.com/outsystems-experts/beyond-console-debugging-tricks-f7d0d7f5df4

Read more

Is your JavaScript function actually pure

What does “pure function” mean in the context of JavaScript? In programming in general, purity is also known as “referential transparency”, a fancy way of saying “replacing an expression or function call with its result will never change the behavior of the program” or a way of saying “every time you pass the same inputs, you always get the same outputs”.

That sounds intuitive, and a function like x => x * 10 looks pure because every single time you pass it the number 3 as argument you will get 30 as output. So how can we tell that one function is pure and the other isn’t? Is it enough that we just read the code?

Spoiler: reading the code isn't enough.

http://staltz.com/is-your-javascript-function-actually-pure.html

Read more

Our dashboard has been updated to make use of Laravel Echo original

by Freek Van der Herten – 1 minute read

A couple of months ago we released a dashboard powered by Laravel, Pusher and Vue.js. In tandem with Laravel 5.3 a new JavaScript library was released called Laravel Echo. This library makes it very easy to work with a service like Pusher. This weekend I took the time to update the dashboard to make…

Read more

Best of Frontend United Conference 2016

A few weeks ago the Frontend United Conference was held in Ghent, Belgium. The entire development team at Spatie attended the conference. Though it certainly was fun to go to a conference with the entire team we were left a bit underwhelmed. Some of the talks were very short and some speakers seemed a bit unprepared.

The organisers have begun posting video's of all sessions to YouTube. In my opinion the following three talks rose above the rest.

1: Harry Roberts gave a talk were he demonstrated that programming best practices apply to writing CSS as well.

2: Christian Heillman talked about web obesity and gave a few tips on how to optimize the size of images.

3: Mathias Bynens showed how unicode support in JavaScript is broken and what common pitfalls are when working with special characters. Rather than just complaining about it, he offered some kick ass self-made solutions.

(the video for this session hasn't been posted yet, this is a video of the same talk at another conference)

Read more

A Blade directive to export PHP variables to JavaScript original

by Freek Van der Herten – 1 minute read

Today we released our new package called laravel-blade-javascript. It provides you with a javascript Blade directive to export PHP variables to JavaScript. So it basically does the same as Jeffrey Way's popular PHP-Vars-To-Js-Transformer package but instead of exporting variables in the controller…

Read more

Acceptance Testing a Laravel and Vue.js Application

Mohammed Said did some research on how run acceptance test for a javascript driven interface.

If you’re testing non-javascript driven interfaces then you may use Laravel’s built-in PHP Browser based testing library, it’s very powerful and the API is very readable as well. However if you need to test javascript driven interfaces then selenium is what you should be using.
https://dotdev.co/acceptance-testing-a-laravel-and-vue-js-application-4160b8e96156#.j1ltb34zv

Read more

Building a GIF search engine with React

Over at the Tighten blog Samantha Geitz posted an amazing introduction to React. She starts off by clearly explaining how to setup the environment (webpack and a few dependencies). After making sure that it all works, she continues by building a GIF search engine. Along the way the core concepts of React are explained. If you're in any way interesting in learning React, I warmly recommend reading the entire piece.

React itself is reasonably well-documented and easy to pick up, once you can shift your thinking to align with its conventions. The problem is, if you want to build robust apps, the V in MVC probably isn't going to cut it, and you have to dive into the often-confusing ecosystem surrounding React.

In this series, we're going to walk through the stages of building a React application — an app that lets you search the Giphy API and displays results, similar to what Giphy has on its own website.

In this first article, we are going to build the application using only React (with Webpack for asset compilation).

http://blog.tighten.co/react-101-building-a-gif-search-engine

I'm looking forward to read the next articles of this series.

Read more

What do you name the callback function?

Derick Bailey on his blog:

JavaScript practically requires callback functions to do anything asynchronous. Unless you’re talking about generators, you really can’t get away from them. Callbacks are everywhere.

...

I do use different names for the callback parameter, depending on the circumstance. I believe naming is important as it provides a set of expectations. If your code breaks the expectations of the name, people will be confused and it will cause problems.

http://derickbailey.com/2016/02/15/what-do-you-name-the-callback-function/

Read more

Learn React.js in just a couple of afternoons

Wes Bos released a series of videos on React.js.

Together, we will build “Catch of the Day” — a real-time app for a trendy seafood market where price and quantity available are variable and can change at a moments notice. We will build a menu, an order form, and an inventory management area where authorized users can immediately update product details.
Wes has released some really learning resources on, amongst others the terminal, sublime. A while ago he also appeared on Full Stack Radio. I'm pretty sure his new batch of videos will be top notch!

Read more

How to run your own npm repository server original

by Freek Van der Herten – 1 minute read

At Spatie we're constantly improving our application template called Blender. We love using packages to pull in functionality. Creating and using packages has many benefits. Though we try to create public packages that benefit the community, there are some packages that are very specific to Blender.…

Read more

Add a JavaScript breakpoint programmatically

When working on JavaScript code you'll probably find yourself riddling the code with console.log-statements when something is not working the way that you're expecting.

But did you know that there is a debugger statement available? It has invokes any available debugging functionality. To put it otherwise: you can programmatically set a breakpoint for your debugger. It should work in any browser.

function potentiallyBuggyCode() {
    debugger; //the debugger wil stop here
}

Here's the documentation on the debugger-statement on MDN.

Read more

Using the dataset property in JavaScript

In plain old JavaScript you can get the data attributes of

[code language="html"]

lorum ipsum
```

like this

[code language="javascript"] document.getElementById('test').getAttribute('data-news-item-id');



But did you know there's a alternative way of doing this by reading an element's dataset property?

[code language="javascript"]
document.getElementById('test').dataset.newsItemId;

Notice that the values can be accessed by camelcasing the name of the data attribute. You can also write to datasets to change values of data attributes. Read the informative helpful article on MDN to know more.

Read more