[ 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
"Mr Branding" is a blog based on RSS for everything related to website branding and website design, it collects its posts from many sites in order to facilitate the updating to the latest technology.
To suggest any source, please contact me: Taha.baba@consultant.com
Colm Tuite dives deep into what he thinks is fundamentally broken with the current design tool model, as well as hint at the direction he think we should be headed. (medium.freecodecamp.org)
Working with a team of 6 Front end developers, you will be pivotal in the company’s shift to an API-driven single page application, on an industry leading product. Putting your own stamp on a greenfields system using cool tech and Agile processes, you’ll have a guiding influence on the platform, its codebase and be a mentor to others on the team. (jumbointeractive.com)
Here’s how the little-known skill of “active reading” can teach you how great products get built – and ultimately how to be a better designer. (blog.intercom.com)
A great slide deck and list of resources from Manuel Matuzovic to help make your web projects more inclusive and improve the usability/user experience at the same time. (speakerdeck.com)
Sam Thorogood shares some thoughts on SVGs, high-DPI and when you should inline images. (medium.com)
If you use GitHub on a daily basis or sporadically you are sure to find one thing in this post that helps with your workflow. (hackernoon.com)
And it’s visual! Start your free trial now. (dapulse.com)
This article doesn’t explain how to use Webpack. Rather, explains the reasoning behind it and what makes it more special than just a bundler. (jackhiston.com)
Sophia Shoemaker builds a music player whilst introducing some of the new goodies in React 16. (sitepoint.com)
A command line tool to statically analyse your page in order to generate the most optimal web font subsets, then inject them into your page. (github.com)
We’re looking for an experienced design leader to grow our design team in Boston, while also continuing to be an individual contributor. Together we’ll build both great products and a great team. (thoughtbot.com)
Are you passionate about digital applications? Do you have curiosity and empathy for humans? Do you believe that design starts with problem definition? Are you a compulsive problem solver? If so, you’ve got our attention. (typeform.com)
The post Web Design Weekly #291 appeared first on Web Design Weekly.
For a lot of JavaScript developers, the biggest complaint with Redux is the amount of boilerplate code needed to implement features. A better alternative is MobX which provides similar functionality but with lesser code to write.
For MobX newbies, take a quick look at this introduction written by MobX's creator. You can also work through this tutorial to gain some practical experience.
The goal of this article is to help JavaScript developers decide which of these two state management solutions are best for their projects. I've migrated this CRUD Redux project to MobX to use as an example in this article. I'll first discuss the pros and cons of using MobX, and then I'll demonstrate actual code samples from both versions to show the difference.
The code for the projects mentioned in this article can be found on GitHub:
If you enjoy this post, you might also like to sign up for SitePoint Premium and watch our course on working with forms using React and Redux.
First, let's look at what they both have in common. They:
Let's now look at the main differences between Redux and MobX.
For a beginner, you can learn how to use MobX in just 30 minutes. Once you learn the basics, that's it. You don't need to learn anything new. With Redux, the basics are easy too. However, once you start building more complex applications, you'll have to deal with:
With MobX, all these situations are "magically" taken care of. You don't need additional libraries to handle such situations.
To implement a feature in Redux, you need to update at least four artifacts. This includes writing code for reducers, actions, containers and components. This is particularly annoying if you're working on a small project. MobX only requires you to update at least two artifacts (i.e. the store and the view component).
If you prefer writing object-oriented code, you'll be pleased to know you can use OOP to implement state management logic with MobX. Through the use of decorators such as @observable and @observer, you can easily make your plain JavaScript components and stores reactive. If you prefer functional programming, no problem --- that's supported as well. Redux, on the other hand, is heavily geared towards functional programming principles. However, you can use the redux-connect-decorator library if you want a class-based approach.
In most JavaScript applications, you'll find yourself working with relational or nested data. To be able to use it in a Redux store, you'll have to normalize it first. Next, you have to write some more code to manage tracking of references in normalized data.
In MobX, it's recommended to store your data in a denormalized form. MobX can keep track of the relations for you, and will automatically re-render changes. By using domain objects to store your data, you can refer directly to other domain objects defined in other stores. In addition, you can use (@)computed decorators and modifiers for observables to easily solve complex data challenges.
Redux is a framework that provides strict guidelines on how you write state code. This means you can easily write tests and develop maintainable code. MobX is a library and has no rules on how to implement it. The danger with this is that it's very easy to take shortcuts and apply quick fixes that can lead to unmaintainable code.
MobX's internal code "magically" handles a lot of logic to make your application reactive. There's an invisible area where your data passes between the store and your component, which makes it difficult to debug when you have a problem. If you change state directly in components, without using @actions, you'll have a hard time pinpointing the source of a bug.
In software development, new emerging trends appear all the time. Within a few short years, current software techniques can quickly loose momentum. At the moment, there are several solutions competing with both Redux and Mobx. A few examples are Relay/Apollo & GraphQL, Alt.js and Jumpsuit. Any of these technologies has the potential to become the most popular. If you really want to know which one is best for you, you'll have to try them all.
Continue reading %Redux vs MobX: Which Is Best for Your Project?%
Colorful One Pager with lovely illustrations calling for submissions for the annual Future of Design survey by NEA. We featured their 2016 Survey Results – presented in a smart long-scrolling One Page website of course
This article is by guest author Jack Franklin. SitePoint guest posts aim to bring you engaging content from prominent writers and speakers of the JavaScript community.
In this article, we'll take a look at using Jest --- a testing framework maintained by Facebook --- to test our ReactJS components. We'll look at how we can use Jest first on plain JavaScript functions, before looking at some of the features it provides out of the box specifically aimed at making testing React apps easier. It's worth noting that Jest isn't aimed specifically at React: you can use it to test any JavaScript applications. However, a couple of the features it provides come in really handy for testing user interfaces, which is why it's a great fit with React.
Before we can test anything, we need an application to test! Staying true to web development tradition, I've built a small todo application that we'll use as the starting point. You can find it, along with all the tests that we're about to write, on GitHub. If you'd like to play with the application to get a feel for it, you can also find a live demo online.
The application is written in ES2015, compiled using Webpack with the Babel ES2015 and React presets. I won't go into the details of the build set up, but it's all in the GitHub repo if you'd like to check it out. You'll find full instructions in the README on how to get the app running locally. If you'd like to read more, the application is built using Webpack, and I recommend "A Beginner's guide to Webpack" as a good introduction to the tool.
The entry point of the application is app/index.js, which just renders the Todos component into the HTML:
render(
<Todos />,
document.getElementById('app')
);
The Todos component is the main hub of the application. It contains all the state (hard-coded data for this application, which in reality would likely come from an API or similar), and has code to render the two child components: Todo, which is rendered once for each todo in the state, and AddTodo, which is rendered once and provides the form for a user to add a new todo.
Because the Todos component contains all the state, it needs the Todo and AddTodo components to notify it whenever anything changes. Therefore, it passes functions down into these components that they can call when some data changes, and Todos can update the state accordingly.
Finally, for now, you'll notice that all the business logic is contained in app/state-functions.js:
export function toggleDone(state, id) {…}
export function addTodo(state, todo) {…}
export function deleteTodo(state, id) {…}
These are all pure functions that take the state and some data, and return the new state. If you're unfamiliar with pure functions, they are functions that only reference data they are given and have no side effects. For more, you can read my article on A List Apart on pure functions and my article on SitePoint about pure functions and React.
If you're familiar with Redux, they're fairly similar to what Redux would call a reducer. In fact, if this application got much bigger I would consider moving into Redux for a more explicit, structured approach to data. But for this size application you'll often find that local component state and some well abstracted functions to be more than enough.
There have been many articles written on the pros and cons of test-driven development, where developers are expected to write the tests first, before writing the code to fix the test. The idea behind this is that, by writing the test first, you have to think about the API that you're writing, and it can lead to a better design. For me, I find that this very much comes down to personal preference and also to the sort of thing I'm testing. I've found that, for React components, I like to write the components first and then add tests to the most important bits of functionality. However, if you find that writing tests first for your components fits your workflow, then you should do that. There's no hard rule here; do whatever feels best for you and your team.
Note that this article will focus on testing front-end code. If you're looking for something focused on the back end, be sure to check out SitePoint's course Test-Driven Development in Node.js.
Jest was first released in 2014, and although it initially garnered a lot of interest, the project was dormant for a while and not so actively worked on. However, Facebook has invested the last year into improving Jest, and recently published a few releases with impressive changes that make it worth reconsidering. The only resemblance of Jest compared to the initial open-source release is the name and the logo. Everything else has been changed and rewritten. If you'd like to find out more about this, you can read Christoph Pojer's comment, where he discusses the current state of the project.
If you've been frustrated by setting up Babel, React and JSX tests using another framework, then I definitely recommend giving Jest a try. If you've found your existing test setup to be slow, I also highly recommend Jest. It automatically runs tests in parallel, and its watch mode is able to run only tests relevant to the changed file, which is invaluable when you have a large suite of tests. It comes with JSDom configured, meaning you can write browser tests but run them through Node, can deal with asynchronous tests and has advanced features such as mocking, spies and stubs built in.
To start with, we need to get Jest installed. Because we're also using Babel, we'll install another couple of modules that make Jest and Babel play nicely out of the box:
npm install --save-dev babel-jest babel-polyfill babel-preset-es2015 babel-preset-react jest
You also need to have a .babelrc file with Babel configured to use any presets and plugins you need. The sample project already has this file, which looks like so:
{
"presets": ["es2015", "react"]
}
We won't install any React testing tools yet, because we're not going to start with testing our components, but our state functions.
Jest expects to find our tests in a __tests__ folder, which has become a popular convention in the JavaScript community, and it's one we're going to stick to here. If you're not a fan of the __tests__ setup, out of the box Jest also supports finding any .test.js and .spec.js files too.
As we'll be testing our state functions, go ahead and create __tests__/state-functions.test.js.
We'll write a proper test shortly, but for now, put in this dummy test, which will let us check everything's working correctly and we have Jest configured.
describe('Addition', () => {
it('knows that 2 and 2 make 4', () => {
expect(2 + 2).toBe(4);
});
});
Now, head into your package.json. We need to set up npm test so that it runs Jest, and we can do that simply by setting the test script to run jest.
"scripts": {
"test": "jest"
}
If you now run npm test locally, you should see your tests run, and pass!
PASS __tests__/state-functions.test.js
Addition
✓ knows that 2 and 2 make 4 (5ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 passed, 0 total
Time: 3.11s
If you've ever used Jasmine, or most testing frameworks, the above test code itself should be pretty familiar. Jest lets us use describe and it to nest tests as we need to. How much nesting you use is up to you; I like to nest mine so all the descriptive strings passed to describe and it read almost as a sentence.
When it comes to making actual assertions, you wrap the thing you want to test within an expect() call, before then calling an assertion on it. In this case, we've used toBe. You can find a list of all the available assertions in the Jest documentation. toBe checks that the given value matches the value under test, using === to do so. We'll meet a few of Jest's assertions through this tutorial.
Now we've seen Jest work on a dummy test, let's get it running on a real one! We're going to test the first of our state functions, toggleDone. toggleDone takes the current state and the ID of a todo that we'd like to toggle. Each todo has a done property, and toggleDone should swap it from true to false, or vice-versa.
If you're following along with this, make sure you've cloned the repo and have copied the app folder to the same directory that contains your ___tests__ folder. You'll also need to install the shortid package (npm install shortid --save), which is a dependency of the Todo app.
I'll start by importing the function from app/state-functions.js, and setting up the test's structure. Whilst Jest allows you to use describe and it to nest as deeply as you'd like to, you can also use test, which will often read better. test is just an alias to Jest's it function, but can sometimes make tests much easier to read and less nested.
For example, here's how I would write that test with nested describe and it calls:
import { toggleDone } from '../app/state-functions';
describe('toggleDone', () => {
describe('when given an incomplete todo', () => {
it('marks the todo as completed', () => {
});
});
});
And here's how I would do it with test:
import { toggleDone } from '../app/state-functions';
test('toggleDone completes an incomplete todo', () => {
});
The test still reads nicely, but there's less indentation getting in the way now. This one is mainly down to personal preference; choose whichever style you're more comfortable with.
Now we can write the assertion. First we'll create our starting state, before passing it into toggleDone, along with the ID of the todo that we want to toggle. toggleDone will return our finish state, which we can then assert on:
const startState = {
todos: [{ id: 1, done: false, name: 'Buy Milk' }]
};
const finState = toggleDone(startState, 1);
expect(finState.todos).toEqual([
{ id: 1, done: true, name: 'Buy Milk' }
]);
Notice now that I use toEqual to make my assertion. You should use toBe on primitive values, such as strings and numbers, but toEqual on objects and arrays. toEqual is built to deal with arrays and objects, and will recursively check each field or item within the object given to ensure that it matches.
With that we can now run npm test and see our state function test pass:
PASS __tests__/state-functions.test.js
✓ tooggleDone completes an incomplete todo (9ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 passed, 0 total
Time: 3.166s
It's a bit frustrating to make changes to a test file and then have to manually run npm test again. One of Jest's best features is its watch mode, which watches for file changes and runs tests accordingly. It can even figure out which subset of tests to run based on the file that changed. It's incredibly powerful and reliable, and you're able to run Jest in watch mode and leave it all day whilst you craft your code.
To run it in watch mode, you can run npm test -- --watch. Anything you pass to npm test after the first -- will be passed straight through to the underlying command. This means that these two commands are effectively equivalent:
npm test -- --watchjest --watchI would recommend that you leave Jest running in another tab, or terminal window, for the rest of this tutorial.
Before moving onto testing the React components, we'll write one more test on another one of our state functions. In a real application I would write many more tests, but for the sake of the tutorial, I'll skip some of them. For now, let's write a test that ensures that our deleteTodo function is working. Before seeing how I've written it below, try writing it yourself and seeing how your test compares.
Remember that you will have to update the import statement at the top to import deleteTodo along with toggleTodo:
import { toggleTodo, deleteTodo } from '../app/state-functions';
And here's how I've written the test:
test('deleteTodo deletes the todo it is given', () => {
const startState = {
todos: [{ id: 1, done: false, name: 'Buy Milk' }]
};
const finState = deleteTodo(startState, 1);
expect(finState.todos).toEqual([]);
});
The test doesn't vary too much from the first: we set up our initial state, run our function and then assert on the finished state. If you left Jest running in watch mode, notice how it picks up your new test and runs it, and how quick it is to do so! It's a great way to get instant feedback on your tests as you write them.
The tests above also demonstrate the perfect layout for a test, which is:
By keeping the tests laid out in this way, you'll find them easier to follow and work with.
Now we're happy testing our state functions, let's move on to React components.
Continue reading %How to Test React Components Using Jest%
In less than 4 minutes, we’ll demonstrate how HelloSign’s dashboard can help you manage and provide overviews into your API calls, callbacks, requests and more! Watch as we create API requests and demonstrate HelloSign’s working dashboard. You’ll see how to find status reports for API requests, usage analytics, and how to manage and debug live and test API calls.
Continue reading %Using the HelloSign API Dashboard and Test Mode%