<commit_before>import * as types from '../mutation-types'
import _ from 'underscore'

const state = {
    feeds:     {},
    userfeeds: []
}

const mutations = {
    // 获取全部订阅源
    [types.RECEIVE_FEEDS](state, { data }) {
        state.feeds = data
    },
    // 获取用户订阅源
    [types.RECEIVE_USER_FEEDS](state, { data }) {
        state.userfeeds = data
    },
    // 标记已读
    [types.READ_POST](state, { feed_id }) {
        state.userfeeds = _.map(state.userfeeds, feed => {
            if (feed._id === feed_id) {
                feed.unread --
            }
            return feed
        })
    },
    // 全部标记已读
    [types.READ_ALL](state, feed_id) {
        state.userfeeds = _.map(state.userfeeds, feed => {
            if (feed._id === feed_id) {
                feed.unread = 0
            }
            return feed
        })
    },
    // 增加订阅
    [types.SUBSCRIBE](state, feed) {
        state.userfeeds = [...state.userfeeds, feed]
        state.feeds = _.map(state.feeds, item => {
            if (item._id === feed._id) {
                item.feedNum++
            }
            return item
        })
    },
    // 取消订阅
    [types.UNSUBSCRIBE](state, { _id }) {
        state.userfeeds = _.filter(state.userfeeds, feed => feed._id !== _id)
        state.feeds = _.map(state.feeds, item => {
            if (item._id === _id) {
                item.feedNum--
            }
            return item
        })
    }
}

export default {
    state,
    mutations
}<commit_msg>update feeds after searching a new feed<commit_after>import * as types from '../mutation-types'
import _ from 'underscore'

const state = {
    feeds:     {},
    userfeeds: []
}

const mutations = {
    // 获取全部订阅源
    [types.RECEIVE_FEEDS](state, { data }) {
        state.feeds = data
    },
    // 获取用户订阅源
    [types.RECEIVE_USER_FEEDS](state, { data }) {
        state.userfeeds = data
    },
    // 标记已读
    [types.READ_POST](state, { feed_id }) {
        state.userfeeds = _.map(state.userfeeds, feed => {
            if (feed._id === feed_id) {
                feed.unread --
            }
            return feed
        })
    },
    // 全部标记已读
    [types.READ_ALL](state, feed_id) {
        state.userfeeds = _.map(state.userfeeds, feed => {
            if (feed._id === feed_id) {
                feed.unread = 0
            }
            return feed
        })
    },
    // 增加订阅
    [types.SUBSCRIBE](state, feed) {
        let exist = true
        state.userfeeds = [...state.userfeeds, feed]
        state.feeds = state.feeds.map(item => {
            if (item._id === feed._id) {
                item.feedNum++
                exist = false
            }
            return item
        })
        if (exist) {
            state.feeds = [...state.feeds, feed]
        }
    },
    // 取消订阅
    [types.UNSUBSCRIBE](state, { _id }) {
        state.userfeeds = state.userfeeds.filter(feed => feed._id !== _id)
        state.feeds = state.feeds.map(state.feeds, item => {
            if (item._id === _id) {
                item.feedNum--
            }
            return item
        })
    },
}

export default {
    state,
    mutations
}
{'fraction_non_alphanumeric': 0.14190051020408162, 'fraction_numerical': 0.0006377551020408163, 'mean_word_length': 1.3983180428134556, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '211701', 'n_tokens_mistral': 1077, 'n_tokens_neox': 1102, 'n_words': 184}