Wednesday, November 20, 2019

Pricing Table Style 135

The post Pricing Table Style 135 appeared first on Best jQuery.


by Admin via Best jQuery

Counter Style 96

The post Counter Style 96 appeared first on Best jQuery.


by Admin via Best jQuery

Compile-time Immutability in TypeScript

Compile-time Immutability in TypeScript

TypeScript allows us to decorate specification-compliant ECMAScript with type information that we can analyze and output as plain JavaScript using a dedicated compiler. In large-scale projects, this sort of static analysis can catch potential bugs ahead of resorting to lengthy debugging sessions, let alone deploying to production. However, reference types in TypeScript are still mutable, which can lead to unintended side effects in our software.

In this article, we'll look at possible constructs where prohibiting references from being mutated can be beneficial.

Primitives vs Reference Types

JavaScript defines two overarching groups of data types:

  • Primitives: low-level values that are immutable (e.g. strings, numbers, booleans etc.)
  • References: collections of properties, representing identifiable heap memory, that are mutable (e.g. objects, arrays, Map etc.)

Say we declare a constant, to which we assign a string:

const message = 'hello';

Given that strings are primitives and are thus immutable, we’re unable to directly modify this value. It can only be used to produce new values:

console.log(message.replace('h', 'sm')); // 'smello'
console.log(message); // 'hello'

Despite invoking replace() upon message, we aren't modifying its memory. We're merely creating a new string, leaving the original contents of message intact.

Mutating the indices of message is a no-op by default, but will throw a TypeError in strict mode:

'use strict';

const message = 'hello';
message[0] = 'j'; // TypeError: 0 is read-only

Note that if the declaration of message were to use the let keyword, we would be able to replace the value to which it resolves:

let message = 'hello';
message = 'goodbye';

It's important to highlight that this is not mutation. Instead, we're replacing one immutable value with another.

Mutable References

Let's contrast the behavior of primitives with references. Let's declare an object with a couple of properties:

const me = {
  name: 'James',
  age: 29,
};

Given that JavaScript objects are mutable, we can change its existing properties and add new ones:

me.name = 'Rob';
me.isTall = true;

console.log(me); // Object { name: "Rob", age: 29, isTall: true };

Unlike primitives, objects can be directly mutated without being replaced by a new reference. We can prove this by sharing a single object across two declarations:

const me = {
  name: 'James',
  age: 29,
};

const rob = me;

rob.name = 'Rob';

console.log(me); // { name: 'Rob', age: 29 }

JavaScript arrays, which inherit from Object.prototype, are also mutable:

const names = ['James', 'Sarah', 'Rob'];

names[2] = 'Layla';

console.log(names); // Array(3) [ 'James', 'Sarah', 'Layla' ]

What's the Issue with Mutable References?

Consider we have a mutable array of the first five Fibonacci numbers:

const fibonacci = [1, 2, 3, 5, 8];

log2(fibonacci); // replaces each item, n, with Math.log2(n);
appendFibonacci(fibonacci, 5, 5); // appends the next five Fibonacci numbers to the input array

This code may seem innocuous on the surface, but since log2 mutates the array it receives, our fibonacci array will no longer exclusively represent Fibonacci numbers as the name would otherwise suggest. Instead, fibonacci would become [0, 1, 1.584962500721156, 2.321928094887362, 3, 13, 21, 34, 55, 89]. One could therefore argue that the names of these declarations are semantically inaccurate, making the flow of the program harder to follow.

Pseudo-immutable Objects in JavaScript

Although JavaScript objects are mutable, we can take advantage of particular constructs to deep clone references, namely spread syntax:

const me = {
  name: 'James',
  age: 29,
  address: {
    house: '123',
    street: 'Fake Street',
    town: 'Fakesville',
    country: 'United States',
    zip: 12345,
  },
};

const rob = {
  ...me,
  name: 'Rob',
  address: {
    ...me.address,
    house: '125',
  },
};

console.log(me.name); // 'James'
console.log(rob.name); // 'Rob'
console.log(me === rob); // false

The spread syntax is also compatible with arrays:

const names = ['James', 'Sarah', 'Rob'];
const newNames = [...names.slice(0, 2), 'Layla'];

console.log(names); // Array(3) [ 'James', 'Sarah', 'Rob' ]
console.log(newNames); // Array(3) [ 'James', 'Sarah', 'Layla' ]
console.log(names === newNames); // false

Thinking immutably when dealing with reference types can make the behavior of our code clearer. Revisiting the prior mutable Fibonacci example, we could avoid such mutation by copying fibonacci into a new array:

const fibonacci = [1, 2, 3, 5, 8];
const log2Fibonacci = [...fibonacci];

log2(log2Fibonacci);
appendFibonacci(fibonacci, 5, 5);

Rather than placing the burden of creating copies on the consumer, it would be preferable for log2 and appendFibonacci to treat their inputs as read-only, creating new outputs based upon them:

const PHI = 1.618033988749895;

const log2 = (arr: number[]) => arr.map(n => Math.log2(2));
const fib = (n: number) => (PHI ** n - (-PHI) ** -n) / Math.sqrt(5);

const createFibSequence = (start = 0, length = 5) =>
  new Array(length).fill(0).map((_, i) => fib(start + i + 2));

const fibonacci = [1, 2, 3, 5, 8];
const log2Fibonacci = log2(fibonacci);
const extendedFibSequence = [...fibonacci, ...createFibSequence(5, 5)];

By writing our functions to return new references in favor of mutating their inputs, the array identified by the fibonacci declaration remains unchanged, and its name remains a valid source of context. Ultimately, this code is more deterministic.

The post Compile-time Immutability in TypeScript appeared first on SitePoint.


by James Wright via SitePoint

Google Analytics Basics: A Guide For Beginners (infographic)

Google Analytics (GA) was launched in 2005 and is a free web analytics tool that helps you analyze your web traffic. Although the idea of web traffic can seem like a small part of your business, it actually plays a significant role in your marketing strategy’s success. Whether you’re running...

[ This is a content summary only. Visit our website https://ift.tt/1b4YgHQ for full links, other content, and more! ]

by Web Desk via Digital Information World

How You Should Behave on Social Media (infographic)

Social media is in many ways a lot like the wild west. One thing that makes it similar to that fabled era has to do with how new it is. Even though social media has basically ended up becoming a more or less indispensable part of our lives, there are still new things that people learn. Even if you...

[ This is a content summary only. Visit our website https://ift.tt/1b4YgHQ for full links, other content, and more! ]

by Zia Muhammad via Digital Information World

Which Companies Turned A Profit the Quickest - And Which Have Yet To?

Turning a profit seems to be an easy task for the world’s biggest brands. After all, it’s pretty much guaranteed once your name is big enough to be recognised around the globe, right? According to new research from Forward2Me, it seems that profit isn’t always guaranteed, even if you’re considered...

[ This is a content summary only. Visit our website https://ift.tt/1b4YgHQ for full links, other content, and more! ]

by Web Desk via Digital Information World

How new features get added to Chrome and Blink

#418 — November 20, 2019

Read on the Web

Frontend Focus

What Newspapers Can Teach Us About Web Design — From the Gutenberg Principle to grid systems to above the fold, newspapers teach us much about the foundations of web design. Frederick O’Brien digs into what can be learned from the printed press.

Smashing Magazine

Intent to Explain: Demystifying the Blink Shipping Process — How do features get added to Chrome? What process goes on behind the scenes to bring the latest Web features to Chromium, Blink, et al.? Here’s an overview of the process, and if you prefer a talk/video version, there’s one of those too.

Google

Node.js Learning Path: Build Web APIs and Apps — Join both Scott Moss and Jem Young on this learning path to discover how to deploy Node-powered apps and design and build APIs in Node from the ground up.

Frontend Masters sponsor

GSAP 'GreenSock' 3 Available Now — This popular ‘swiss army knife’ of a JavaScript animation library just saw its version 3.0 release. It’s a significant upgrade with over fifty new features and changes, including a simplified API, a new motion paths plugin, ES6 module support, and more. You can see the the full release notes here, or if you’d rather here’s a video of the highlights.

GreenSock

▶  Interactive Web Animation with SVG — A whistle-stop tour of delightful SVG animations and how this graphics format “provides a link from the world of design to the world of development”.

Cassie Evans

Firefox’s Fight for The Future of The Web“Ultimately, Firefox’s future is as much down to the decisions of a few regulators as it is about anything Mozilla can do”.

Alex Hern (The Guardian)

Chrome, Edge, Safari Hacked At Chinese Hacking Contest — White-hat hackers gathered in Chengdu to test zero-days against today’s top browsers.

Catalin Cimpanu

💻 Jobs

Senior Software Engineer at Getty (Los Angeles, CA) — Build fantastic tools and interfaces at one of the world's most prestigious cultural heritage orgs using Linked-Open-Data, Python, Structured-CMS, Vue.js.

J. Paul Getty Trust

Find a Job Through Vettery — Make a profile, name your salary, and connect with hiring managers from top employers. Vettery is completely free for job seekers.

Vettery

📙 News, Tutorials & Opinion

Cropping Images to a Specific Aspect Ratio with JavaScript — How to use the HTML canvas API and some basic math to build a tiny crop helper function, making it easy to quickly crop images in various aspect ratios.

Rik Schennink

▶  Become An HTML Email Geek With These Videos From Rémi Parmentier — Genuinely useful guides to designing HTML emails and working with the quirks of targeting email clients (truly a minefield compared to normal browsers).

Rachel Andrew

Tried & True Tips from 25 React Experts to Make You More Productive — Check out the top productivity tips of 25 React experts, from smart ways to get started with React to advanced hacks.

Progress KendoReact sponsor

▶  HTTP Headers for the Responsible Developer — Explores how HTTP headers have a direct impact on user experience. Related slides here.

Stefan Judis

How Do You Remove Unused CSS From a Site — Chris Coyier shares some skepticism at those unused CSS tools that promise to take care of everything, highlighting their issues and suggesting an alternative practice.

CSS Tricks

▶  You Are Doing :focus Wrong (And I Was Too) — A good primer on focus states and how using them can make lives easier for those navigating your pages via the keyboard. P.S: Never turn :focus off.

Kevin Powell

A List of All the Tools Used to Create a Hit HTML5 Game on Steam — They sold over 200k units so they clearly got something right.

Maschinen-Mensch

▶  Learn More About Accessibility in Web Standards. Listen Now

Heroku sponsorpodcast

Real Web Development on iPad — Outlines how to get setup for full-stack development on the iPad, including a look at how iOS automation can help.

Lachlan Campbell

Pac-Man...in CSS — A fun little tutorial recreating a “happy, eating Pac-Man” using the clip-path property. Waka waka!

Maks Akymenko

Comparing the Different Types of Native JavaScript Popups

Elliot Goldman

🔧 Code, Tools & Resources

siriwave: The Apple Siri Wave-Form Replicated in A JS Library — This isn’t a particularly new project, but was recently updated and as such landed on our radar. It’s a neat recreation of the Siri ‘look’ made with JavaScript. There’s a detailed blog post outlining how the effect was achieved, and a demo where you can see it in action.

Flavio Maria De Stefano

ScrollTrigger: Let Your Page React to Scroll Changes — Triggers classes based on the current scroll position. So, for example, when an element enters the viewport you can fade it in.

Erik Terwan

bootlint: HTML Linter for Bootstrap Projects — Despite only just reaching version 1.0, this is a popular and mature linting tool that checks for several common HTML mistakes in webpages that are using Bootstrap in a fairly “vanilla” way.

Bootstrap

Flynt: A Component Based WordPress Starter Theme for Developers — It’s open source but with a commercial variant.

Bleech

   ðŸ—“ Upcoming Events

Frontend Con, November 26-27 — Warsaw, Poland — Brings together 30+ experts with over 500 experienced frontend pros from all over the world.

dotCSS, December 4 — Paris, France — The largest CSS conference in Europe.

Flashback Conference, February 10-11 — Orlando, Florida — Looks at cutting-edge web dev, browser APIs and tooling, but adds the understanding of how they’ve evolved from the past to the web of today.

Frontend Developer Love, February 19-21 — Amsterdam, Netherlands — Three full days of talks from 35+ global JavaScript leaders from around the world.


by via Frontend Focus