<commit_before>var React = require('react');
var debounce = require('lodash/function/debounce');

var matchers = {};
var matchedQueries = {};

var mediaChangeCallback;

var onMediaChange = function () {
  mediaChangeCallback();
};

var MatchMediaBase = {
  childContextTypes: {
    mediaQueries: React.PropTypes.object
  },

  getChildContext: function () {
    return {
      mediaQueries: this.getMatchedMedia()
    };
  },

  init: function (mediaQueryOpts) {
    if (!mediaQueryOpts || typeof window === 'undefined') {
      return;
    }

    Object.keys(mediaQueryOpts).forEach(function (key) {
      matchers[key] = window.matchMedia(mediaQueryOpts[key]);
      matchers[key].addListener(onMediaChange);
    });
  },

  componentWillMount: function () {
    mediaChangeCallback = this.handleMediaChange;
  },

  componentWillUnmount: function () {
    mediaChangeCallback = null;

    if (!matchers) {
      return;
    }

    Object.keys(matchers).forEach(function (key) {
      matchers[key].removeListener(onMediaChange);
    });
  },
<commit_msg>Make sure that handleMediaChange is called when component will be mounted. Fixes #96<commit_after>var React = require('react');
var debounce = require('lodash/function/debounce');

var matchers = {};
var matchedQueries = {};

var mediaChangeCallback;

var onMediaChange = function () {
  mediaChangeCallback();
};

var MatchMediaBase = {
  childContextTypes: {
    mediaQueries: React.PropTypes.object
  },

  getChildContext: function () {
    return {
      mediaQueries: this.getMatchedMedia()
    };
  },

  init: function (mediaQueryOpts) {
    if (!mediaQueryOpts || typeof window === 'undefined') {
      return;
    }

    Object.keys(mediaQueryOpts).forEach(function (key) {
      matchers[key] = window.matchMedia(mediaQueryOpts[key]);
      matchers[key].addListener(onMediaChange);
    });
  },

  componentWillMount: function () {
    mediaChangeCallback = this.handleMediaChange;
    mediaChangeCallback();
  },

  componentWillUnmount: function () {
    mediaChangeCallback = null;

    if (!matchers) {
      return;
    }

    Object.keys(matchers).forEach(function (key) {
      matchers[key].removeListener(onMediaChange);
    });
  },

{'fraction_non_alphanumeric': 0.1306509945750452, 'fraction_numerical': 0.0009041591320072332, 'mean_word_length': 3.6589473684210527, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2117868', 'n_tokens_mistral': 671, 'n_tokens_neox': 659, 'n_words': 121}