<commit_before>import _ from 'lodash';
import { push } from 'react-router-redux';
import rootRef from '../libs/firebase';

const	titleCardsRef = rootRef.child('titleCards')
// const moment = require('moment');
const C = require('../constants').default;

function startListeningToTitleCards() {
  return (dispatch) => {
    titleCardsRef.on('value', (snapshot) => {
      dispatch({ type: C.RECEIVE_TITLE_CARDS_DATA, data: snapshot.val(), });
    });
  };
}

function loadTitleCards() {
  return (dispatch) => {
    titleCardsRef.once('value', (snapshot) => {
      dispatch({ type: C.RECEIVE_TITLE_CARDS_DATA, data: snapshot.val(), });
    });
  };
}

function submitNewTitleCard(content) {
  return (dispatch) => {
    const newRef = titleCardsRef.push(content, (error) => {
      if (error) {
        dispatch({ type: C.DISPLAY_ERROR, error: `Submission failed! ${error}`, });
      } else {
        const action = push(`/admin/title-cards/${newRef.key}`);
        dispatch(action);
      }
    });
  };
}

function submitTitleCardEdit(qid, content) {
  return (dispatch, getState) => {
    titleCardsRef.child(qid).update(content, (error) => {
      if (error) {
        dispatch({ type: C.DISPLAY_ERROR, error: `Update failed! ${error}`, });
      } else {
        dispatch({ type: C.DISPLAY_MESSAGE, message: 'Update successfully saved!', });
        const action = push(`/admin/title-cards/${qid}`);
        dispatch(action);
      }
    });
  };
}

export { submitNewTitleCard, loadTitleCards, startListeningToTitleCards, submitTitleCardEdit }
<commit_msg>Deal with potential null from firebase<commit_after>import _ from 'lodash';
import { push } from 'react-router-redux';
import rootRef from '../libs/firebase';

const	titleCardsRef = rootRef.child('titleCards')
const C = require('../constants').default;

function startListeningToTitleCards() {
  return (dispatch) => {
    titleCardsRef.on('value', (snapshot) => {
      if (snapshot) {
        dispatch({ type: C.RECEIVE_TITLE_CARDS_DATA, data: snapshot.val(), });
      }
    });
  };
}

function loadTitleCards() {
  return (dispatch) => {
    titleCardsRef.once('value', (snapshot) => {
      dispatch({ type: C.RECEIVE_TITLE_CARDS_DATA, data: snapshot.val(), });
    });
  };
}

function submitNewTitleCard(content) {
  return (dispatch) => {
    const newRef = titleCardsRef.push(content, (error) => {
      if (error) {
        dispatch({ type: C.DISPLAY_ERROR, error: `Submission failed! ${error}`, });
      } else {
        const action = push(`/admin/title-cards/${newRef.key}`);
        dispatch(action);
      }
    });
  };
}

function submitTitleCardEdit(qid, content) {
  return (dispatch, getState) => {
    titleCardsRef.child(qid).update(content, (error) => {
      if (error) {
        dispatch({ type: C.DISPLAY_ERROR, error: `Update failed! ${error}`, });
      } else {
        dispatch({ type: C.DISPLAY_MESSAGE, message: 'Update successfully saved!', });
        const action = push(`/admin/title-cards/${qid}`);
        dispatch(action);
      }
    });
  };
}

export { submitNewTitleCard, loadTitleCards, startListeningToTitleCards, submitTitleCardEdit }

{'fraction_non_alphanumeric': 0.1659249841068023, 'fraction_numerical': 0.0, 'mean_word_length': 3.4261603375527425, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '4256309', 'n_tokens_mistral': 1015, 'n_tokens_neox': 1017, 'n_words': 200}