b

'My search for the boy in a child abuse video'

Lucy Proctor was horrified when she was WhatsApped a sex abuse video. And she wanted to find out if the boy was safe.




b

The actor who was really stabbed on stage

Conor Madden was playing Hamlet when a sword fight went badly wrong. Would he ever act again?




b

The volunteer army helping self-isolating neighbours

The coronavirus outbreak has left many feeling trapped indoors, but for some help may not be far away.




b

Coronavirus: Here's how you can stop bad information from going viral

Experts are calling on the public to practise ‘information hygiene’ to help stop the spread of falsehoods online.




b

Birth in a pandemic: 'You are stronger than you think'

Coronavirus is throwing many birth plans up in the air and leading some health trusts to increase home births.




b

Coronavirus: The grandad who became a TikTok star without realising it

Joe Allington was persuaded to dance on TikTok for the first time in January. Now he's got 1.5 million followers.




b

Why being gay in Russia is about "love and passion"

The secret moment between two gay Russian lovers that defied haters.




b

Electrosensitivity: 'I didn't believe people had it, then it happened to me'

Velma, Emma and Dean believe mobile phone signals, wi-fi and other modern technology makes them ill.




b

Rob Lawrie, the ex-squaddie, and the girl taken

Rob thought he was helping a refugee girl and her father as they struggled to get to the UK. But he found out it was all a lie.




b

Coronavirus: DIY hair shaving and beauty treatments

As hair dye and clippers become the next thing on the stockpile list - we look at how people are managing their hair and beauty.




b

Dirty streaming: The internet's big secret

Figures suggest that IT now generates as much CO2 as flying, with some arguing it's nearly double.




b

Sex, Disability, and Sex and Disability

Disability and sex is a topic around which there are a lot of misconceptions, but what do disabled people think when people get awkward talking about sex with them?




b

Ramadan and Coronavirus: Breaking my fast on Zoom

How fasting in lockdown and isolation has changed Ramadan for young Muslims this year.




b

Coronavirus: 'I'm being bombarded by gambling ads'

Gambling companies have halted TV and radio ads during lockdown - but not online ads.




b

Coronavirus: Flower grower donates blooms to key workers

Horticulturalist Ben Cross is working with supermarkets to donate flowers to NHS workers.




b

The shop where you can still buy huge bags of pasta

Wholesalers are opening their doors to members of the public keen to buy supplies in bulk.




b

Coronavirus tests and masks sold by fraudsters online

A BBC investigation has found online scams selling fake protective equipment and coronavirus tests.




b

Coronavirus: 'My parents' campervan has become my office'

A marketing manager explains why she turned a campervan into her office during coronavirus.




b

Bill Gates: Few countries will get 'A-grade' for coronavirus response

The Microsoft billionaire says we find ourselves in uncharted territory with the coronavirus pandemic.




b

Coronavirus: ‘Buying a round’ to thank NHS workers

Social enterprise Brewgooder is helping people buy beers for those on the coronavirus front line.




b

Coronavirus: UK chancellor on new microloan scheme for small businesses

Firms will be able to borrow up to £50,000, which will be interest free for the first year.




b

Coronavirus: Pint delivery service to challenge Belfast ban

A pub delivering Guinness to people's homes during lockdown says it was operating within the law.




b

Coronavirus: Should maternity and paternity leave be extended?

A petition calling for maternity leave to be extended due to coronavirus has attracted many signatures.




b

Coronavirus: 'My cafe's going bust before it's even opened'

A car factory worker turned cafe owner explains how coronavirus is affecting his business dream.




b

Coronavirus: Bread and cake tips from a self-isolating baker

Ray normally runs his family bakery, Rinkoffs, but is currently staying at home with his wife.




b

Staging a 'socially distanced' boxing match

Inside the Nicaraguan boxing event that caught the world's attention during the pandemic.




b

Coronavirus: Disease meets deforestation at heart of Brazil's Amazon

Coronavirus has overwhelmed Manaus, the Amazon's biggest city, and the worst is yet to come.




b

Millie Small: My Boy Lollipop singer dies aged 72

The singer, who had Jamaica's first million-selling single, dies after suffering a stroke.




b

Life for asylum seekers in lockdown on the US-Mexico border

Magaly Contreras has spent nine months in a Tijuana shelter and is worried about her future.




b

Coronavirus: São Paulo governor at odds with Bolsonaro

São Paulo Governor João Doria has imposed tough virus curbs, a move slammed by President Bolsonaro.




b

Brazil's Amazon: Surge in deforestation as military prepares to deploy

The military is preparing to deploy to the region to try to stop illegal logging and mining.




b

Coronavirus: Brazil's outbreak 'threatens Paraguay's success'

Paraguay's president says he has reinforced the border with the worst-hit country in South America.




b

Venezuela: Trump denies role in bungled incursion

Venezuela has accused the US of being behind a botched raid to oust President Maduro.




b

React Router & Webpack in Production

I’ve been working on a pretty large react-router codebase at work. Currently it has around 50~ code splits, which as you can imagine, is a lot of routes. This is going to be a post on the things I’ve learned throughout building out my development / production config and how we are using webpack in production.

###Initial Setup

Before I really dive into how my webpack config is setup and the problems I’ve found, I’ll quickly go over how this app is setup. Currently, there’s one entry point and it looks like this:

import React from 'react'
import { render } from 'react-dom'
import { match, Router, browserHistory } from 'react-router'
import AsyncProps from 'async-props'
import routes from '../routes/index'
/* globals document, window */

const { pathname, search, hash } = window.location
const location = `${pathname}${search}${hash}`

match({ routes, location }, () => {
  render(
    <Router
      render={props => <AsyncProps {...props}/>}
      routes={routes}
      history={browserHistory}
    />,
    document.getElementById('app')
  )
})

It looks like a standard react-router setup, except a couple things are different. For one, there’s way too many routes to have them all in this file, so we are importing the main route object into this file. Second, we are using match on the client side. Without matching first, the client side would try to render before the splits were downloaded causing an error. You can read a little more about match on the client here.

Next, we are using Ryan Florence’s awesome async-props library for loading data into components. It allows me to load data from an api before the server renders components. It will pass the data down to the client for the client-side render, and then data will load as you navigate to new pages automatically.

###Routes

Our main routes file looks like this:


export default {
  component: 'div',
  path: '/',
  indexRoute: require('./index'),
  childRoutes: [
    require('./login'),
    require('./account'),
    ...
  ]
}

There’s a lot more require’s in our app of course. And these are nested pretty deep. The files referenced in the root file have more child routes, and those use require.ensure which you can read about in the webpack docs on code splitting. It tells webpack to make a new bundle, and then load that bundle when require.ensure is called on the client. Here’s an example:

if(typeof require.ensure !== "function") require.ensure = function(d, c) { c(require) }

module.exports = {
  path: 'account',
  getComponent(location, cb) {
    require.ensure([], (require) => {
      cb(null, require('../../views/master/index.jsx'))
    })
  },
  childRoutes: [
    require('./settings'),
  ]
}

There’s a few things going on here. First, we have a function at the top that will polyfill require.ensure. Why? Well, on this project we are server rendering our whole site as well, which I would rather not do, but due to the type of site we are building: we have to. The next thing is the relative require path. I’m using this awesome babel resolver plugin along with webpack’s resolve paths so that I can import files like this:

import Header from '../../master/header'
//becomes
import Header from 'master/header'

Why do I have to use a babel plugin AND webpack’s resolve feature? Once again, doing a server rendered app, the code is ran on the server and also through webpack. In this particular app, I haven’t had time to experiment with webpacking the server. Anyways, if I didn’t use the babel plugin, errors would be thrown on the server, but webpack would work fine. This is one of the common things I have ran into while building this app.

Realizing some things need to be done slightly different on the server or client. You may still be wondering why I am referencing the component as a relative path in the above route example, and that’s because the babel plugin I’m using only works with import and not require. My route objects are the one place that I have these “nasty” looking paths.

##Webpack

I was prompted to make this article after tweeting this out:

A couple people wanted a better explanation as to what’s happening here. When I was first building my production webpack config, even after using all of these plugins:

new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.js'),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin({
  compress: { warnings: false },
  comments: false,
  sourceMap: false,
  mangle: true,
  minimize: true
}),

My bundle looked like this:

That’s pretty huge if you think about it. And I’m not talking about the amount of bundles. I’m talking about the file size. After searching everywhere for a solution to get the bundle size down further, I found webpack’s AggressiveMergingPlugin. This thing is a life saver. As you may have seen from the tweet, the output turns into this:

Just having the main, vendor, and one other bundle brings the whole site under 1MB. I’m using the plugin to only merge files if the size reduction is more than 50%, which is the default.

People talk about code splitting in webpack and think it’s really amazing to load the JS for the page you’re on and nothing more. It sounds great. The problem is that the file size is immensely bigger. If someone more familiar with webpack has a better idea as to why this is, I’d like a better explanation. It isn’t feasable to keep the splits instead of merging them. This site is pretty large, with a lot of routes as you can tell from the screenshots. Codesplitting without merging would cause way more waiting on the client side every time you navigate to a new page. Even if the JS was heavily cached, the first time you hit these pages it will have to load a 300kb bundle for some of them.

##Caching

That takes us to caching. We are about a month away from publicly launching this site, so we haven’t setup the workflow for pushing updates through a cdn, but that will be the end result. For now, in my webpack config, my output object looks like this:

output: {
  path: __dirname + '/public/assets/js/[hash]/',
  filename: '[name].js',
  chunkFilename: '[id].js',
  publicPath: '/assets/js/[hash]/'
},

This is in the production config of course. This way I can cache the files and when I update the code, the hash will change and the browser won’t be caching the old code. I pass in the hash as an env variable at runtime to that the server has the correct path to the assets folder.

##Problems

There were a few big problems I came across while building out a server rendered app with dynamic routes. The first was page titles. How am I supposed to have the right title on the client and on the initial server render? Thankfully, Ryan has yet another solution. react-title-component solves this perfectly.

The next was, how do I hit an api, wait for the response on server render, load new data on route changes, and of course, do this at the component level. As I mentioned before, async-props solves this problem too. It will give you route info so that you can make requests based on things in the url.

The next problem is one that I haven’t fully solved. Webpack is getting really slow. It takes around 20 seconds on a maxed out macbook 15” to build code in production. On the server, it takes more like a minute! If I’m in development mode, it takes around 10 seconds to make the initial build, and sometimes it lags on building the splits on code change. If anyone has insight into this I would love to hear it.

This one goes along with the webpack one, and it is reloading the server. I haven’t tried to webpack the server but I hear doing so works great for this. I don’t think it would fix the problem with webpack being slow though, and in fact it would probably make it even slower.

##Folder structure

I almost forgot to throw this one in here! I’m really happy with the structure of this project. I have a views folder that has all of the same folders and file names as the routes folder. It makes it really easy to find things. These also correspond with the URL to the page. /account/settings will be in views/account/settings.jsx and routes/account/settings.js. The same is true for my tests folder.

##Conclusion

I hope this gave you a good glimpse at how webpack and react router work at a larger scale than you see most blog posts cover. If you have any questions or things that you would like me to talk about that I haven’t already, please leave a comment below and I will update this post! I’m sure that I forgot a few problems and tips writing this. I was thinking this would be a short post but it blew up on me!




b

Building Redux Middleware

After writing my post a few months ago on building your own redux app, I have been asked a couple times to write a guide on creating redux middleware and how it works. This will be a quick post on how you can acheive anything with your own middleware!

##Basic middleware


const customMiddleware = store => next => action => {
  if(action.type !== 'custom') return next(action)
  //do stuff!
}

Applying it:

import { createStore, applyMiddleware, } from 'redux'
import reducer from './reducer'
import customMiddleware from './customMiddleware'

const store = createStore(
  reducer,
  applyMiddleware(customMiddleware)
)

Whaaa? store => next => action => I know that looks confusing. Essentially you are building a chain of functions, it will look like this when it gets called:

//next looks something like this:
let dispatched = null
let next = actionAttempt => dispatched = actionAttempt 

const dispatch = customMiddleware(store)(next)

dispatch({
  type: 'custom',
  value: 'test'
})

All you are doing is chaining function calls and passing in the neccesary data. When I first saw this I was confused a little due to the long chain, but it made perfect sense after reading the article on writing redux tests.

So now that we understand how those chained functions work, let’s explain the first line of our middleware.

if(action.type !== 'custom') return next(action)

There should be some way to tell what actions should go through your middleware. In this example, we are saying if the action’s type is not custom call next, which will pass it to any other middleware and then to the reducer.

##Doing Cool stuff

The official guide on redux middleware covers a few examples on this, I’m going to try to explain it in a more simple way.

Say we want an action like this:

dispatch({
  type: 'ajax',
  url: 'http://api.com',
  method: 'POST',
  body: state => ({
    title: state.title
    description: state.description
  }),
  cb: response => console.log('finished!', response)
})

We want this to do a post request, and then call the cb function. It would look something like this:

import fetch from 'isomorphic-fetch'

const ajaxMiddleware = store => next => action => {
  if(action.type !== 'ajax') return next(action)
  
  fetch(action.url, {
    method: action.method,
    body: JSON.stringify(action.body(store.getState()))
  })
  .then(response => response.json())
  .then(json => action.cb(json))
}

It’s pretty simple really. You have access to every method redux offers in middleware. What if we wanted the cb function to have access to dispatching more actions? We could change that last line of the fetch function to this:

.then(json => action.cb(json, store.dispatch))

Now in the callback, we can do:

  cb: (response, dispatch) => dispatch(newAction(response))

As you can see, middleware is very easy to write in redux. You can pass store state back to actions, and so much more. If you need any help or if I didn’t go into detail enough, feel free to leave a comment below!




b

2000 FIFA Club World Championship: Corinthians 0-0 Vasco da Gama (4-3 PSO)

Corinthians-Vasco da Gama, FIFA Club World Cup Brazil 2000 Final: The all-Brazilian final had a plethora of familiar names - including legend Romario, Edmundo, Gilberto Melo, Ricardinho and Dida - and ended in a dramatic penalty shootout.




b

2005 Club World Cup Final: Sao Paulo 1-0 Liverpool  

Sao Paulo-Liverpool, FIFA Club World Cup Japan 2005 Final: The English side saw Steven Gerrard go close twice, but they could not deny a spirited performance by the Brazilians.




b

2006 Club World Cup Final: Internacional 1-0 Barcelona

Internacional-Barcelona, FIFA Club World Cup Japan 2006 Final: The powerful side of Ronaldinho, Deco and Andres Iniesta lost out to the Brazilians despite creating a number of chances.




b

2007 Club World Cup Final: Boca Juniors 2-4 AC Milan

In the final of the FIFA Club World Cup Japan 2007, Italian giants AC Milan got two goals from 'Pippo' Inzaghi and one each from Kaka and Alessandro Nesta to become the world's top team.




b

2008 Club World Cup Final: LDU Quito 0-1 Manchester United

Liga de Quito-Manchester United, FIFA Club World Cup Japan 2008 Final: Both teams showed impressive attacking flair, but it was Wayne Rooney's angled shot that made the difference.




b

2009 Club World Cup: Estudiantes 1-2 Barcelona (AET)

A:Estudiantes-Barcelona, FIFA Club World Cup UAE 2009 final: Barcelona won their sixth trophy of the year following a last-gasp equaliser and a headed winner in extra time against a dogged Argentine opponent.




b

2010 Club World Cup Final: TP Mazembe 0-3 Inter

TP Mazembe-Inter Milan, FIFA Club World Cup UAE 2010: Internazionale was in rampant form as they crushed the dreams of the first African finalists.




b

2011 Club World Cup Final: Santos 0-4 Barcelona

Hopes were high in the final of the FIFA Club World Cup Japan 2011 that Brazilian team Santos could match Barcelona's firepower, but Lionel Messi, Cesc Fabregas, Xavi and crew had other ideas.




b

2012 Club World Cup Final: Corinthians 1-0 Chelsea

Corinthians and Chelsea met in the FIFA Club World Cup Cup Japan 2012 final. Watch highlights from the match when the South American champions defeated their European counterparts. 




b

2013 Club World Cup Final: Bayern Munich 2-0 Raja Casablanca

Bayern Munich - Raja Casablanca, FIFA Club World Cup Morocco 2013: The European champions got goals from Dante and Thiago as the host Moroccan club came close but fell in the end in this well-played final.





b

Claudio Gomes of France and Abel Ruiz of Spain pose for photos

GUWAHATI, INDIA - OCTOBER 17: Claudio Gomes of France and Abel Ruiz of Spain pose for photos with referees prior to the FIFA U-17 World Cup India 2017 Round of 16 match between France and Spain at Indira Gandhi Athletic Stadium on October 17, 2017 in Guwahati, India. (Photo by Tom Dulat - FIFA/FIFA via Getty Images)




b

Abel Ruiz of Spain celebrates a scored goal

MUMBAI, INDIA - OCTOBER 25: Abel Ruiz of Spain celebrates a scored goal during the FIFA U-17 World Cup India 2017 Semi Final match between Mali and Spain at Dr DY Patil Cricket Stadium on October 25, 2017 in Mumbai, India. (Photo by Buda Mendes - FIFA/FIFA via Getty Images)




b

Abel Ruiz of Spain waits in the tunnel

KOCHI, INDIA - OCTOBER 22: Abel Ruiz of Spain waits in the tunnel ahead of the FIFA U-17 World Cup India 2017 Quarter Final match between Spain and Iran at the Jawaharlal Nehru International Stadium on October 22, 2017 in Kochi, India. (Photo by Mike Hewitt - FIFA/FIFA via Getty Images)




b

The dressing room of Brazil team

KOLKATA, INDIA - OCTOBER 28: The dressing room of Brazil team is pictured prior to the FIFA U-17 World Cup India 2017 3rd Place match between Brazil and Mali at Vivekananda Yuba Bharati Krirangan on October 28, 2017 in Kolkata, India. (Photo by Buda Mendes - FIFA/FIFA via Getty Images)