{"size": 794, "ext": "js", "max_stars_repo_path": "public/src/js/sagas/channelCaches.js", "max_stars_repo_name": "WhatAboutGaming/pyramid-waggle", "max_stars_repo_stars_event_min_datetime": "2016-03-16T12:03:54.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-14T03:42:56.000Z", "max_issues_repo_path": "public/src/js/sagas/channelCaches.js", "max_issues_repo_name": "WhatAboutGaming/pyramid-waggle", "max_issues_repo_issues_event_min_datetime": "2017-01-08T22:58:34.000Z", "max_issues_repo_issues_event_max_datetime": "2017-04-19T09:19:08.000Z", "max_forks_repo_path": "public/src/js/sagas/channelCaches.js", "max_forks_repo_name": "WhatAboutGaming/pyramid-waggle", "max_forks_repo_forks_event_min_datetime": "2017-05-22T15:49:46.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-10T22:15:07.000Z"}
{"max_stars_count": 13, "max_issues_count": 3, "max_forks_count": 2, "avg_line_length": 20.8947368421, "max_line_length": 69, "alphanum_fraction": 0.5957178841}
import { take } from "redux-saga/effects";

import * as actionTypes from "../actionTypes";
import actions from "../actions";
import store from "../store";

export default function* () {
	while (true) {
		let action = yield take([
			actionTypes.channelCaches.APPEND,
			actionTypes.channelCaches.UPDATE
		]);

		let channel = action.channel || action.data && action.data.channel;

		// Handle clears
		if (channel) {
			let items = action.cache || [action.data];

			if (items && items.length) {
				items.forEach((item) => {
					if (
						item &&
						item.type === "clearchat" &&
						item.time &&
						item.username
					) {
						let { time, username } = item;
						store.dispatch(actions.channelCaches.clearUser(
							channel, username, time
						));
					}
				});
			}
		}
	}
}
