<commit_before>import {Module, Service} from '../../decorators';
import _ from 'lodash';
import angular from 'angular';
import NgStorage from 'ngstorage';

@Module({
    name : 'ps.common.service.playlist',
    modules : [ NgStorage ]
})
@Service('playlistService')
export default class PlaylistService {

    constructor($localStorage) {
        "ngInject";
        this.$localStorage = $localStorage;
        this.$localStorage.playlist = this.$localStorage.playlist || [];
    }

    playlist() {
        return this.$localStorage.playlist;
    }
    add(item) {
        this.$localStorage.playlist.push(item);
    }
    remove (item) {
        this.$localStorage.playlist = _.remove(this.$localStorage.playlist, function(elem) { return elem.id !== item.id; });
    }
    contains(item) {
        return angular.isObject(_.find(this.$localStorage.playlist, {id : item.id}));
    }
    addOrRemove (item) {
        (this.contains(item)) ? this.remove(item) : this.add(item);
    }
    removeAll () {
        this.$localStorage.playlist = [];
    }
}<commit_msg>refactor(service.playlist): simplify code and remove dependency to lodash<commit_after>import {Module, Service} from '../../decorators';
import NgStorage from 'ngstorage';

@Module({
    name : 'ps.common.service.playlist',
    modules : [ NgStorage ]
})
@Service('playlistService')
export default class PlaylistService {

    constructor($localStorage) {
        "ngInject";
        this.$localStorage = $localStorage;
        this.$localStorage.playlist = this.$localStorage.playlist || [];
    }

    playlist() {
        return this.$localStorage.playlist;
    }
    add(item) {
        this.playlist().push(item);
    }
    remove (item) {
        this.$localStorage.playlist = this.playlist().filter(elem => elem.id !== item.id);
    }
    contains(item) {
        return !!this.playlist().find(elem => elem.id === item.id);
    }
    addOrRemove(item) {
        this.contains(item) ? this.remove(item) : this.add(item);
    }
    removeAll () {
        this.$localStorage.playlist = [];
    }
}
{'fraction_non_alphanumeric': 0.1555232558139535, 'fraction_numerical': 0.0, 'mean_word_length': 2.90359168241966, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2261076', 'n_tokens_mistral': 626, 'n_tokens_neox': 622, 'n_words': 111}