Firefox Hello Desktop: Behind the Scenes – Flux and React

This is the first of a few posts that I’m planning regarding discussion about how we implement and work on the desktop and standalone parts of Firefox Hello. We’ve been doing some things in different ways, which we have found to be advantageous. We know other teams are interested in what we do, so its time to share!

Content Processes

First, a little bit of architecture: The panels and conversation window run in content processes (just like regular web pages). The conversation window shares code with the link-clicker pages that are on hello.firefox.com.

Hence those parts run very much in a web-style, and for various reasons, we decided to create them in a web-style manner. As a result, we’ve ended up with using React and Flux to aid our development.

I’ll detail more about the architecture in future posts.

The Flux Pattern

Flux is a recommended pattern for use alongside React, although I think you could use it with other frameworks as well. I’ll detail here about how we use Flux specifically for Hello. As Flux is a pattern, there’s no one set standard and the methods of implementation vary.

Flux Overview

The main parts of a flux system are stores, components and actions. Some of this is a bit like an MVC system, but I find there’s better definition about what does what.
Diagram of Example flow in a Flux patternAn action is effectively a result of an event, that changes the system. For example, in Loop, we use actions for user events, but we also use them for any data incoming from the server.

A store contains the business logic. It listens to actions, when it receives one, it does something based on the action and updates its state appropriately.

A component is a view. The view has a set of properties (passed in values) and/or state (the state is obtained from the store’s state). For a given set of properties and state, you always get the same layout. The components listen for updates to the state in the stores and update appropriately.

We also have a dispatcher. The dispatcher dispatches actions to interested stores. Only one action can be processed at any one time. If a new action comes in, then the dispatcher queues it.

Actions are always synchronous – if changes would happen due to external stimuli then these will be new actions. For example, this prevents actions from blocking other actions whilst waiting for a response from the server.

What advantages do we get?

For Hello, we find the flux pattern fits very nicely. Before, we used a traditional MVC model, however, we kept on getting in a mess with events being all over the place, and application logic being wrapped in amongst the views as well as the models.

Now, we have a much more defined structure:

  • Components/views are a place for displaying, there’s some logic about what to display, but it isn’t business logic.
  • The business logic exists in the stores, and is triggered by actions.
  • You can follow an action through and find out which stores listen for it, and what they do.
  • Actions themselves are well-defined with specified parameters.

React provides the component structure, it has defined ways of tracking state and properties, and the re-rendering on state change gives much automation. Since it encourages the separation of immutable properties, a whole class of inadvertent errors is eliminated.

There’s also many advantages with debugging – we have a flag that lets us watch all the actions going through the system, so its much easier to track what events are taking place and the data passed with them. This combined with the fact that actions have limited scope, helps with debugging the data flows.

Simple Unit Testing

For testing, we’re able to do unit testing in a much simpler fashion:

  • Components/Views are tested by setting up their state and/or properties and ensuring the correct elements are displayed:
it("should render a muted local audio button", function() {
  var comp = TestUtils.renderIntoDocument(
    React.createElement(sharedViews.MediaControlButton, {
      scope: "local",
      type: "audio",
      action: function(){},
      enabled: false
    }));

  expect(comp.getDOMNode().classList.contains("muted")).eql(true);
});
  • Stores are tested by setting an initial state, sending an action, and checking the resultant state:
it("should set the state to READY", function() {
  store.setupRoomInfo(new sharedActions.SetupRoomInfo(fakeRoomInfo));

  expect(store._storeState.roomState).eql(ROOM_STATES.READY);
});

We therefore have many tests written at the unit test level. Many times we’ve found and prevented issues whilst writing these tests, and yet, because these are all content based, we can run the tests in a few seconds. I’ll go more into testing in a future post.

References

Here’s a few references to some of the areas in our code base that are good example of our flux implementation. Note that behind the scenes, everything is known as Loop – the codename for the project.

Conclusion and more coming…

We’ve found using the flux model is much more organised than we were with an MVC, possibly its just a better defined methodology, but it gave us the structure we badly missing. In future posts, I’ll discuss about our development facilities, more about the desktop architecture and whatever else comes up, so please do leave questions in the comments and I’ll try and answer them either direct or with more posts.

Posted in Firefox Hello, Mozilla | Tagged , , , , , | 2 Comments

planet.mozillamessaging.com is moving

As part of tidying up some of our websites we’re moving the existing planet.mozillamessaging.com to planet.mozilla.org/thunderbird.

Both sites are currently functional and show the same blogs, however planet.mozillamessaging.com will become a redirect very soon. When the redirect happens, you’ll hopefully be fine, but you may want to update your links and feed urls now.

Posted in Mozilla | Comments Off

Thunderbird 13 second and third beta releases via new automation

I was going to write this post yesterday, didn’t quite complete it and so it gets an updated with activities of the last 24 hours as well.

Some people had noticed the extra long delay between the first and second betas of Thunderbird 13. Whilst we sometimes don’t publish a beta every week, in this case we were busy finishing off a transition that had started some months previously.

The transition has merged the Thunderbird build automation system onto the same system used by Firefox – we are now running side-by-side, using the same hardware.

The whole transition has been a big benefit to Thunderbird, we’ve brought the Thunderbird build systems up to date, removing a lot of the hacks that were specific to our comm-central based builds. In doing so, we’ve picked up lots of new things: an up to date tinderboxpushlog, self-serve build apis to allow any developer to request new builds and cancel running ones, the hg share extension reducing check out and build times, the latest release automation which includes automatic emails and better parallelism. I’m sure that’s just a small selection.

Ongoing this will help keep Thunderbird much more up to date, we’ll be able to keep in sync with Firefox a lot easier when it comes to the mechanics of building, signing etc. I’ve also got some ideas for where we can add/improve automation for both Firefox and Thunderbird, so I’ll be putting those forward soon.

Back to the events over the last 24 hours. Yesterday we finished shipping the second beta of Thunderbird 13, this was the first release that had been run on the Firefox system, and took about a week or two to complete as many parts had been missing or not quite there. A few hours after that I sent the go for the third beta, and guess what, we’ve just pushed that build out to the beta channel. Apart from a couple of minor hiccups, the automation worked fine. Wow, awesome!

This is a great achievement, and Thunderbird build and release is now in much better shape than it was a few months ago. I’d like to thank John O’Duinn and Chris Cooper for making this happen, and a huge thanks to John Hopkins who I know spent many hours working on the actual transition and the rest of the release engineering team who have been helping out with questions, solutions and fixes.

Posted in Mozilla | Tagged , , , , , | Comments Off

Thunderbird now available in Armenian, Asturian and Croatian (new Beta Languages)

Mozilla Thunderbird is now available in three new beta languages – Armenian, Asturian and Croation. We’ve released these as beta languages – they are relatively new languages and have received some testing, however although the core is based on the same version as the released Thunderbird, there may still be some translation issues on the interface.

If you want to give one of these a try, then you can obtain them from the beta languages section on our download page.

If you find an issue with the translation, please report it under the respective localisation’s component here.

 

Posted in Mozilla | Comments Off

Removed Thunderbird release symlinks for dead branches on FTP

Since the Thunderbird 2.0 days we’ve had “latest-X.Y” symlinks on FTP for all major versions of Thunderbird. With rapid release, this has quickly caused an explosion in the number of them, cluttering things up (as Firefox have already realised and taken action).

In bug 697050 I have just removed all of the ones for the dead branches (2.0, 3.0), and also the ones for all rapid releases (5.0, 6.0, 7.0, 8.0). From now on, there will be no new branch based symlinks, simply a “latest” symlink that points to the latest rapid release.

Posted in Mozilla | Tagged , , , | Comments Off

Lightning Development Channel for Thunderbird Betas

Did you know there’s a Lightning Beta available on the developer channel on AMO for Thunderbird Betas?

No? Well there is.

If you’re running, or wanting to run Thunderbird Beta builds and you want Lightning as well, then head over to the Lightning page on AMO and scroll down to the bottom – you’ll see the Development Channel which is what you want to download and install into your Thunderbird Beta.

Once you’ve done that, updates are automatic. Whenever a new Lightning Beta build is out you’ll get it. No more needing to download special builds.

The Lightning folks are working to ensure that whenever a new beta version of Thunderbird is released, there will be a Lightning Beta compatible with it.

Posted in Mozilla | Tagged , , , | 2 Comments

Welcome to the new blog

If you’ve just found this blog from my old blog, welcome to the new location. Otherwise, just welcome!

I’d decided to move my blog, as I was expecting to loose my old one during some changes to my broadband accounts. As it turns out, I still have the old one set up, but thought I’d move all my work related blogs across here anyway (this one was set up before I found out). I’m not quite sure yet if I’ll use my old blog/site for anything in particular – we’ll see. For now it will stay up as an archive of all my old posts.

After a bit of time with lack of blogging, I’m hoping to get going again in the next few days.

Posted in Mozilla | Tagged , | Comments Off