Friday, September 29, 2017

Using Preact as a React Alternative

Preact is an implementation of the virtual DOM component paradigm just like React and many other similar libraries. Unlike React, it's only 3KB in size, and it also outperforms it in terms of speed. It's created by Jason Miller and available under the well-known permissive and open-source MIT license.

Why Use Preact?

Preact logoPreact is a lightweight version of React. You may prefer to use Preact as a lightweight alternative if you like building views with React but performance, speed and size are a priority for you --- for example, in case of mobile web apps or progressive web apps.

Whether you're starting a new project or developing an existing one, Preact can save you a lot of time. You don't need to reinvent the wheel trying to learn a new library, since it's similar to, and compatible with, React --- to the point that you can use existing React packages with it with only some aliasing, thanks to the compatibility layer preact-compat.

Pros and Cons

There are many differences between React and Preact that we can summarize in three points:

  • Features and API: Preact includes only a subset of the React API, and not all available features in React.
  • Size: Preact is much smaller than React.
  • Performance: Preact is faster than React.

Every library out there has its own set of pros and cons, and only your priorities can help you decide which library is a good fit for your next project. In this section, I'll try to list the pros and cons of the two libraries.

Preact Pros

  • Preact is lightweight, smaller (only 3KB in size when gzipped) and faster than React (see these tests). You can also run performance tests in your browser via this link.
  • Preact is largely compatible with React, and has the same ES6 API as React, which makes it dead easy either to adopt Preact as a new library for building user interfaces in your project or to swap React with Preact for an existing project for performance reasons.
  • It has good documentation and examples available from the official website.
  • It has a powerful and official CLI for quickly creating new Preact projects, without the hassle of Webpack and Babel configuration.
  • Many features are inspired by all the work already done on React.
  • It has also its own set of advanced features independent from React, like Linked State.

React Pros

  • React supports one-way data binding.
  • It's backed by a large company, Facebook.
  • Good documentation, examples, and tutorials on the official website and the web.
  • Large community.
  • Used on Facebook's website, which has millions of visitors worldwide.
  • Has its own official developer debugging tools extension for Chrome.
  • It has the Create React App project boilerplate for quickly creating projects with zero configuration.
  • It has a well-architectured and complex codebase.

React Cons

  • React has a relatively large size in comparison with Preact or other existing similar libraries. (React minified source file is around 136KB in size, or about 42KB when minified and gzipped.)
  • It's slower than Preact.
  • As a result of its complex codebase, it's harder for novice developers to contribute.

Note: Another con I listed while writing this article was that React had a grant patent clause paired with the BSD license, making it legally unsuitable for some use cases. However, in September 2017, the React license switched MIT, which resolved these license concerns.

Preact Cons

  • Preact supports only stateless functional components and ES6 class-based component definition, so there's no createClass.
  • No support for context.
  • No support for React propTypes.
  • Smaller community than React.

Getting Started with Preact CLI

Preact CLI is a command line tool created by Preact's author, Jason Miller. It makes it very easy to create a new Preact project without getting bogged down with configuration complexities, so let's start by installing it.

Open your terminal (Linux or macOS) or command prompt (Windows), then run the following commands:

npm i -g preact-cli@latest

This will install the latest version of Preact CLI, assuming you have Node and NPM installed on your local development machine.

You can now create your project with this:

preact create my-app

Or with this, ff you want to create your app interactively:

preact init

Next, navigate inside your app's root folder and run this:

npm start

This will start a live-reload development server.

Finally, when you finish developing your app, you can build a production release using this:

npm run build

Continue reading %Using Preact as a React Alternative%


by Ahmed Bouchefra via SitePoint

Second Cousins

Unique One Page redesign for Second Cousins with a hover-sensitive text changer and a dynamic/moving sun icon that matches the arc of the sun at their location ☀️

Full Review | Direct Link


by Rob Hope @robhope via One Page Love

Don’t Understand SEO? A Beginners Guide to SEO Terminology #[Infographic]

Are you reading online resources to try and learn about SEO? Do you struggle to understand some of the terminology used? Rocket55 share the ABC’s of SEO in this infographic.

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

by Web Desk via Digital Information World

Extracting Website Data and Creating APIs with WrapAPI

Today, almost all services we use have some sort of API. Some web applications are even built from API points alone, being passed to some kind of front-end view. If you're a consumer of a service that provides an API, you'll sometimes need more features or find limits to what the API can offer. In this article, we'll cover a service that's useful both for API consumers and creators.

I always go with the saying that, if there's a web interface, you can build your own API over it. WrapAPI tries to make this process easier. If you're familiar with the process of web scraping/crawling (or extracting data from websites), you'll see the magic of WrapAPI.

WrapAPI offers a service that allows you to easily extract information from websites and create APIs from the data. It provides an easy, interactive way of selecting what information you want to get. With just a few clicks, you can have your API online.

To follow along with this tutorial, I recommend you head over to wrapapi.com and create an account.

How To Get Around WrapAPI

On the WrapAPI site, you'll see that you can start to build your project right away --- although, unless you create an account, your work won't be saved.

Once you've signed up, click the Try building an API button.

WrapAPI Web Builder

You'll be presented by a browser-like interface. On top of the site we're presented with a URL bar. As an example, WrapAPI uses Hacker News (http://ift.tt/YV9WJO). If you click the URL to change it to something else, you'll see more options related to the request you want to make. We'll use the default options, and only change the URL to http://ift.tt/2brOFq8. We're covering only the GET method, as we only want to get data in this example.

Below the URL bar there are four buttons that give you different information regarding the site you're viewing. Browser view displays the site as you would visit it from your browser. Code view displays the source code of the site. Headers shows the response you get from the server. This is useful if you want to see what response you get from the server: it gives you information like the HTTP status codes (200, 404, 400 etc.), content types, web servers and so on. You can also view the request's Cookies directly from the builder.

Getting the Data

By now you should be able to see SitePoint inside the Browser View frame.

Preview of SitePoint inside WrapAPI Builder

Let's create a very simple API that shows us the latest post titles of the JavaScript channel. If you hover over the titles, images or any other element in the site, you'll notice a selection color covering it. Let's scroll down a bit, to the LATEST articles part. Hover over the title from one of the articles and click on that title. You'll notice that it doesn't switch to that particular link we clicked. We see that every title in this section is highlighted. WrapAPI guessed that these are all the titles we want. Sometimes it can also select parts of the sites we don't want. That's usually the case when the CSS class selectors are not well-defined or used by other elements in the site.

Besides CSS selectors, WrapAPI supports regular expressions, JSON selectors, headers, cookies, form outputs, and a bunch more options. You can use them all together and extract exactly what you're aiming for. In this example, we'll only use CSS selectors.

Selecting titles in the builder

In the right part of the interface, you'll see three tabs. Let's take a look at the current Build tab. Outputs will show us the selectors (in our case CSS selectors), and you'll get more details on what you would like to select. We're interested only in extracting the title, which is text. There are more options on cleaning the result output, but we won't get into these details. If you'd like to create another selector, to select description, author, date, etc., just click the Create a new collection/output. Naming your selectors is also important, as this will make it easier if you use multiple selectors in the site. By clicking the pencil icon, you can edit your selectors.

Extract/Ouput options

The Preview tab will show a representation of our data in JSON, and you probably get the idea of what the API will look like. If you're happy with the results, you can click the Save button to save a version of the API.

Saving API endpoints

You'll need to enter the repository and the endpoint name of the API. It helps you manage and organize your APIs. That will also be part of your API's name in the end. After entering the information, you'll return to the builder. Our API is saved, but now we need to test and publish it.

Tips:

  • If the site has pagination (previous/next pages), you can use the query string options. (More on that here.)
  • Name your selectors correctly, as they'll be part of the JSON output.

Continue reading %Extracting Website Data and Creating APIs with WrapAPI%


by Ardian Haxha via SitePoint

#354: React 16 Released

This week's JavaScript newsRead this e-mail on the Web
JavaScript Weekly
Issue 354 — September 29, 2017
The final release of React 16 is here, with rewritten ‘Fiber’ internals. There’s a lot more React 16 stuff in today’s React Status newsletter.
Facebook Code

Recently, there have been some issues involving patent-related features, but Facebook is now moving some of its projects to a standard MIT license.
Facebook Code

JavaScript telemetry gives a timeline of browser events leading to an error, including interaction events, like clicks, inputs, navigation and console messages + more. Debug better w/ telemetry and know why your app crashed.
ROLLBAR   Sponsor

Draggable abstracts native browser events into a modular API for you to build custom, and potentially complex, drag and drop experiences.
Shopify

Learning by building in action in this step-by-step tutorial to help you understand how Promises work.
Trey Huffine

Wissam Abirached explains context and the this keyword in JavaScript, the difference between explicit and hard bindings and what the new keyword represents.
Telerik Developer Network

It’s pitched at being an ideal step up for developers comfortable with jQuery who want to move on to something else.
Mateusz Łuczak

Speakers Holly Schinsky & Jen Looper will be covering Vue & Preact next Thursday (Oct 5).
Certified Fresh Events

Jobs Supported by Hired.com

Can't find the right job? Want companies to apply to you? Try Hired.com.

In Brief

BigInt: A Proposal for Arbitrary Precision Integers in JS news
Ecma TC39

Write Less Code, Use More Tools 
Our outrageous decision to orchestrate Nomad with Kubernetes.
CircleCI  Sponsor

A Brief History of Modularity in JavaScript tutorial
Nicolás Bevacqua

ES6 Promises: Patterns and Anti-Patterns tutorial
Bobby Brennan

Exploring set(), get() and Object.defineProperty() in TypeScript tutorial
Todd Motto

Why Node 8's util.promisify Is So Awesome tutorial node
James Jeffery

Love fraud? You’re going to hate Blockchain 
SitePen  Sponsor

Web Truths: JavaScript Can’t Be Trusted opinion
Christian Heilmann

The Past, Present, and Future of the Angular CLI story
Stephen Fluin

ECMAScript, TC39, and the History of JavaScript video
Tyler McGinnis

Rapid prototyping playground for JavaScript in your editor 
Run any code and see the results immediately right in your editor. Supports VS Code, Atom and JetBrains IDEs.
Wallaby.js  Sponsor

CheerpJ, a Java to JavaScript Compiler, Now in Beta tools
Compile unmodified Java apps to JS for running in the browser.
Leaning Tech

Cerebral: Declarative State and Side Effects Management for JS Frameworks code
An intriguing idea, at least.
Christian Alfoni

Cherow: A Fast, TypeScript-Based JavaScript Parser code
KFlash

Slack JS 9.0.0: A JS Client for Slack's Web API code
Brian Leroux

vue-a11y-calendar: An Accessible, Internationalized Vue Calendar code
IBM

ppipe: Pipes Values Through Functions code
An alternative to using the proposed ‘pipe’ operator for ES.
Yavuz Ege Özcan

Sheet: A Simple Spreadsheet in 220 Bytes of HTML and JS code

Curated by Peter Cooper and published by Cooperpress.

Like this? You may also enjoy: FrontEnd Focus : Node Weekly : React Status

Stop getting JavaScript Weekly : Change email address : Read this issue on the Web

© Cooperpress Ltd. Fairfield Enterprise Centre, Lincoln Way, Louth, LN11 0LS, UK


by via JavaScript Weekly

HustleCase

Lovely clean pre-order Landing Page built on the Shopify framework for a whiteboard laptop cover called HustleCase.

Full Review | Direct Link


by Rob Hope @robhope via One Page Love

Best Video Background Plugins for WordPress