Wednesday, November 30, 2016

Managing State in Aurelia: How to Use Aurelia with Redux

Nowadays, when developing a web app, a lot of focus is placed on state containers — particularly on all sorts of Flux patterns. One of the most prominent implementations of Flux is Redux . For those of you who haven't caught the hype train yet, Redux is a library that helps you to keep state mutations predictable. It stores the entire state of your application in a single object tree.

In this article, we're going to cover the basics of how to use Redux with Aurelia — a next generation open-source JavaScript client framework. But rather than build yet another counter example, we're going to do something more interesting. We're going to build a simple markdown editor with undo and redo functionality. The code for this tutorial is available on GitHub and there is a demo of the finished project here.

Note: When learning something new, I prefer to go back to the source and in the case of Redux, there is this awesome Egghead Video series by the Redux creator (Dan Abramov). Since we won't go into detail on the way Redux works, if you're in need of a refresher, and have a couple of hours to spare, I can highly recommend giving the series a shot.

How this Tutorial is Structured

In this article, I'm going to build three versions of the same component.

The first version will use a pure Aurelia approach. Here you will learn how to setup an Aurelia app, configure the dependencies and create the necessary View and ViewModel. We will look into building the example the classic Aurelia way using two-way data binding.

The second version will introduce Redux to handle the application state. We will use a vanilla approach, which means no additional plugin to handle the interop. That way you will learn how to use Aurelia's out of the box features to accommodate a Redux development process.

The final version will implement the undo/redo feature. Anyone who has built this kind of functionality from scratch knows that it is quite easy to get started, but things can quickly get out of hand. That's why we'll use the the redux-undo plugin to handle this for us.

Throughout the article you will see several references to the official Aurelia docs, to help you find additional information. All of the code listings also link back to their original source files.

So without any further ado, let's get started.

Scaffolding a New Aurelia App

Since we're focusing on the interaction with Aurelia, the example is based on Aurelia's new preferred way to scaffold an application, the Aurelia CLI.

Following the steps explained in CLI Docs, we install the CLI globally with the following command:

npm install aurelia-cli -g

Next, we'll create the new app using:

au new aurelia-redux

This will start a dialogue asking whether you would like to use the default setup or customize your choices. Select the default (ESNext) and opt to create the project and install the dependencies. Then change directory into your new project's folder (using cd aurelia-redux) and start the development server with:

au run --watch

If everything has gone according to plan, this will fire up a BrowserSync development server instance, listening by default on port 9000. Additionally, it will track changes made to your application and refresh when needed.

Adding Dependencies to the Bundler

The next step is to install the necessary dependencies for our upcoming project. Since the Aurelia CLI builds on top of npm modules we can do this with the following command:

npm install --save marked redux redux-undo

Ok, so let's go through each of those. Marked is a full-featured, easy to use markdown parser and compiler, which we're going to use for ... well for exactly what it says on the tin. Redux is the package for the library itself and redux-undo is a simple plugin to add undo/redo features for our application's state container.

Under the hood, the Aurelia CLI uses RequireJS and as such all dependencies are referenced via the Asynchronous Module Definition (AMD) format. Now what's left is to tell the Aurelia application how and where it can find those dependencies.

In order to do so open the aurelia.json file found in your app's aurelia-project subfolder. If you scroll down to the bundles section you will see two objects. One for the app-bundle, containing your own app code, followed by the vendor-bundle used to bundle all of your app's dependencies in a separate bundle file. That object contains a property named dependencies and you guessed it, this is the place where we're going to add our additional ones.

Manipulating the file aurelia.json manually, is currently a necessary step, but one which is going to be automated in future versions.

There are multiple ways to register custom dependencies, best understood by following the respective official Aurelia Docs. What we're going to add is the following code:

// file: aurelia_project/aurelia.json

...
{
  "name": "text",
  "path": "../scripts/text"
},
// START OF NEW DEPENDENCIES, DON'T COPY THIS LINE
{
  "name": "marked",
  "path": "../node_modules/marked",
  "main": "marked.min"
},
{
  "name": "redux",
  "path": "../node_modules/redux/dist",
  "main": "redux.min"
},
{
  "name": "redux-undo",
  "path": "../node_modules/redux-undo/lib",
  "main": "index"
},
// END OF NEW DEPENDENCIES, DON'T COPY THIS LINE
{
  "name": "aurelia-templating-resources",
  "path": "../node_modules/aurelia-templating-resources/dist/amd",
  "main": "aurelia-templating-resources"
},
...

Wiring the App Dependencies

Now that everything is set up you should go ahead and restart the CLI watcher to get your newly installed vendor dependencies properly bundled. Remember we do this with the following command:

au run --watch

That's it, now we're ready to get our hands dirty with some code.

Adding Some Styling

No markdown editor would be complete without some decent styling. We'll start off by including a stylish-looking font in index.html in the root folder.

<head>
  <title>Aurelia MarkDown Editor</title>
  <link href="http://ift.tt/2gWdtd0"
        rel="stylesheet" type="text/css">
</head>

After that we'll add a bunch of styles to /src/styles.css. Rather than list all of the CSS here, I'd encourage you to have a look at the CSS file on GitHub and to use these styles in your own project.

Doing it the Aurelia Way

We will start off by creating a new custom element named <markdown-aurelia> to act as our logical container. We do so by following Aurelia's default conventions of creating a ViewModel markdown-aurelia.js and a View markdown-aurelia.html, inside the src folder.

Continue reading %Managing State in Aurelia: How to Use Aurelia with Redux%


by Vildan Softic via SitePoint

Wishing you a very merry UXmas!

UXmas is back in 2016 with your daily UX Christmas treat.

We’re more excited than Rudolph the Red-Nosed Reindeer on Christmas Eve now that UXmas 2016 has officially begun. Along with Thirst Studios, we’ll bring you a daily UX treat in the lead-up to Christmas. 

Beginning December 1, a new window will open each day on the uxmas.com website to reveal a surprise gift. Since 2012, we’ve brought together some of the biggest names in UX with fun and insightful content, just for you—and this year is no different! It’s our way of giving back to you, the UX community. Plus, who could resist that pun? 

What can you expect? Anything! It could be an article, a video, a sketch, or something else—just like a real advent calendar, you never know what you’re going to get.

Hundreds of thousands of people have enjoyed the articles and emails over the past few years. From the streets of New York to the jungles of the Congo, from tiny 1-inch screens to huge video billboards, unwrapping a daily UXmas gift is an experience appreciated around the globe.

Join us this year on Twitter @merryuxmas, and sign up to the mailing list at uxmas.com for a daily #uxmas gift.

And most importantly, have a merry UXmas!

blog-img

The post Wishing you a very merry UXmas! appeared first on UX Mastery.


by Natassja Hoogstad Hay via UX Mastery

6 of the Best Donation Plugins for WordPress

Although common knowledge, it’s always worth a mention: one of the most powerful features of WordPress lies in its diverse and exhaustive list of plugins. Navigating your way through the dense forest of options, however, can be quite time-consuming.

In this article I'm here to help. We'll cover an overview of some popular and powerful plugins that provide your site with the ability to collect donations.

The use of donation plugins is on the rise, and by my estimation, I think it is heavily impacted by the growing number of independent content creators out there. For creative, online entrepreneurs, donations are a relatively modern addition to the list of ways to monetize content, providing an interesting alternative to advertisements and eCommerce. There is also of course charities and not-for-profits that can now easily accept donations online.

But what are the best donations plugins available?

Continue reading %6 of the Best Donation Plugins for WordPress%


by Sally Wood via SitePoint

What’s New in HTML 5.1

A HTML 5.1 knight in shining armor!

A glimpse of HTML 5.1

The release of the HTML5 standard about two years ago was a big deal in the web development community. Not only because it came packing an impressive list of new features, but also because it was the first major update to HTML since HTML 4.01 was released in 1999. You can still see some websites bragging about the use of the "modern" HTML5 standard today.

Fortunately, we didn't have to wait quite that long for the next iteration of HTML. In October 2015, the W3C started working on the draft of HTML 5.1 with the goal of fixing some of the issues that were left open in HTML5. After many iterations, it reached the state of "Candidate Recommendation" in June 2016, "Proposed Recommendation" in September 2016 and finally a W3C Recommendation in November 2016. Those who followed this development probably noticed that it was a bumpy ride. A lot of initial HTML 5.1 features were dropped due to poor design or a lack of browser vendor support.

While HTML 5.1 was still in development, the W3C has already started working on a draft of HTML 5.2 which is expected to be released in late 2017. In the meantime, here's an overview of some of the interesting new features and improvements introduced in 5.1. Browser support is still lacking for these features but we'll refer you to at least some browsers which can be used to test each example.

Context Menus Using the menu and menuitems Elements

The draft version of 5.1 introduced two different kinds of menu elements: context and toolbar. The former is used to extend the native context menus, usually displayed by right-clicking on the page, and the latter was intended to define plain menu components. In the process of development, toolbar was dropped, but the context menu still remains.

You can use the <menu> tag to define a menu consisting of one or several <menuitem> elements and then bind it to any element using the contextmenu attribute.

Each <menuitem> can have one of the three types:

  • checkbox - allows you to select or deselect an option;
  • command - allows you to execute an action on click;
  • radio - allows you to select one option from a group.

Here's a basic usage example which works in Firefox 49, but doesn't seem to work in Chrome 54.

See the Pen HTML 5.1 menu example by SitePoint (@SitePoint) on CodePen.

In a supported browser, that context menu should look like so:

[caption id="attachment_144279" align="aligncenter" width="400"]A HTML 5.1 context menu Context menu with custom items[/caption]

Details and Summary Elements

The new <details> and <summary> elements implement the ability to show and hide a block of additional information by clicking on an element. This is something that's often done using JavaScript which can now be done using the <details> element with a <summary> element inside it. Clicking on the summary toggles the visibility of the rest of the content from the <details> element.

The following example has been tested in Firefox and Chrome.

See the Pen HTML 5.1 details and summary demo by SitePoint (@SitePoint) on CodePen.

That demo in a supported browser should look like so:

Details and summary elements

More input types — month, week and datetime-local

The arsenal of input types has been extended with three more input types: month, week and datetime-local.

The first two of these will allow you to select a week or a month. In Chrome, both of them are rendered as a dropdown calendar which either allows you to select a particular month of the year or a week. When you access the values from JavaScript you will receive a string looking approximately like these: "2016-W43" for the week input and "2016-10" for the month input.

Initially, the drafts of 5.1 introduced two date-time inputs — datetime and datetime-local. The difference was that datetime-local always selected the time in the user's timezone, while the datetime input would also allow you to select a different timezone. During development, datetime type was dropped and now only datetime-local remains. The datetime-local input consists of two parts — the date, which can be selected in a similar way to the week or month input, and the time part, which can be typed in separately.

Continue reading %What’s New in HTML 5.1%


by Pavels Jelisejevs via SitePoint

mgGlitch – Tiny jQuery Plugin for Glitch

mgGlitch is a little jQuery plugin to glitch everything.

This plugin will clone the selected element (html or image) 3 times :

  • first element become a static background
  • next element with glitch property and lower interval
  • next element with glitch property, higher interval and scale options
  • next element with glitch property, higher interval, scale options and blend mode apply

by via jQuery-Plugins.net RSS Feed

Forrest Brownlie

Forrest Brownlie

Minimal One Page portfolio for Forrest Brownlie - a front-end dev from Auckland, New Zealand. The intro section features a neat 3D spiraling block background achieved with the Three.js library. Nice personal touch with the "Kia Ora" top-left - a Māori language greeting which has entered New Zealand English.

by Rob Hope via One Page Love

Christoph Kulmer – Magic Entertainment

Christoph Kulmer Magic Entertainment

Long scrolling One Pager with a hover-sensitive parallax background effect for magician, Christoph Kulmer. Thanks for the build notes Stefan, good to know it's built on WordPress too!

by Rob Hope via One Page Love