<commit_before>import { take, put, cancel, fork, call } from 'redux-saga/effects';
import { SagaCancellationException } from 'redux-saga';

import { MARKER_MOVED, changeMapCenter, changeNode, CHANGE_NODE_ADDRESS } from '../actions';
import { geocode } from '../../common/helpers/photon';
import delay from '../../common/helpers/delayPromise';

// Update map
export function *updateMap(node) {
  try {
    // Delay photon request (debounce).
    yield call(delay, 300);

    const address = yield call([ node, node.address ]);
    const feature = yield call(geocode, address);

    // Restart daemon if no feature was found.
    if (feature === undefined) {
      return;
    }

    const [ lon, lat ] = feature.geometry.coordinates;
    const center = { lat, lon };

    yield put(changeMapCenter(center));

    node = yield call([ node, node.merge ], center);

    yield put(changeNode(node));
  } catch (error) {
    if (error instanceof SagaCancellationException) {
      return;
    }

    throw error;
  }
}

// This saga itself is not really debouncing the map update, but in combination with the delay in the updateMap saga,
// we get the desired effect. This two functions need to be devided to don't block the execution between
// CHANGE_NODE_ADDRESS actions via fork.
export function *debounceUpdateMap() {
  try {
    let updateMapTask = null;

    while (true) {
      const { payload: node } = yield take(CHANGE_NODE_ADDRESS);

      // Cancel old update map task (debounce).
      if (updateMapTask != null) {
        yield cancel(updateMapTask);
      }

      updateMapTask = yield fork(updateMap, node);
    }
  } catch (error) {
    if (error instanceof SagaCancellationException) {
      return;
    }

    throw error;
  }
}

// Cancel markerUpdate, when the user moves the marker.
export default function *cancelUpdateMap() {
  // Run updateMap saga until ...
  const updateMapTask = yield fork(debounceUpdateMap);

  // ... marker was moved.
  yield take(MARKER_MOVED);
  yield cancel(updateMapTask);
}
<commit_msg>Use explicit check against null.<commit_after>import { take, put, cancel, fork, call } from 'redux-saga/effects';
import { SagaCancellationException } from 'redux-saga';

import { MARKER_MOVED, changeMapCenter, changeNode, CHANGE_NODE_ADDRESS } from '../actions';
import { geocode } from '../../common/helpers/photon';
import delay from '../../common/helpers/delayPromise';

// Update map
export function *updateMap(node) {
  try {
    // Delay photon request (debounce).
    yield call(delay, 300);

    const address = yield call([ node, node.address ]);
    const feature = yield call(geocode, address);

    // Restart daemon if no feature was found.
    if (feature === undefined) {
      return;
    }

    const [ lon, lat ] = feature.geometry.coordinates;
    const center = { lat, lon };

    yield put(changeMapCenter(center));

    node = yield call([ node, node.merge ], center);

    yield put(changeNode(node));
  } catch (error) {
    if (error instanceof SagaCancellationException) {
      return;
    }

    throw error;
  }
}

// This saga itself is not really debouncing the map update, but in combination with the delay in the updateMap saga,
// we get the desired effect. This two functions need to be devided to don't block the execution between
// CHANGE_NODE_ADDRESS actions via fork.
export function *debounceUpdateMap() {
  try {
    let updateMapTask = null;

    while (true) {
      const { payload: node } = yield take(CHANGE_NODE_ADDRESS);

      // Cancel old update map task (debounce).
      if (updateMapTask !== null) {
        yield cancel(updateMapTask);
      }

      updateMapTask = yield fork(updateMap, node);
    }
  } catch (error) {
    if (error instanceof SagaCancellationException) {
      return;
    }

    throw error;
  }
}

// Cancel markerUpdate, when the user moves the marker.
export default function *cancelUpdateMap() {
  // Run updateMap saga until ...
  const updateMapTask = yield fork(debounceUpdateMap);

  // ... marker was moved.
  yield take(MARKER_MOVED);
  yield cancel(updateMapTask);
}

{'fraction_non_alphanumeric': 0.11187103077674646, 'fraction_numerical': 0.0014655593551538837, 'mean_word_length': 3.103206412825651, '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': '7245729', 'n_tokens_mistral': 1231, 'n_tokens_neox': 1180, 'n_words': 396}