<commit_before>import { Injectable } from '@angular/core';
import { Http } from '@angular/http';

import { Observable } from 'rxjs/Observable';

import { Topic, Comment } from './types';
import { API_URL } from './settings';

@Injectable()
export class ApiService {

  public reddit$: Observable<Array<Topic>>;
  public comments: Comment[];
  public comment$: Comment[] = [];

  constructor(
    private http: Http
  ) {
    this.getTopics();
    this.checkStorage();
    this.setCommentsObservable();
    this._logFeed();
  }

  getTopics(): void {
    this.reddit$ = this.http.get(`${API_URL}breathless.json`)
        .map(response => response.json())

        // for now, slice the first two mod posts
        .map(json => json.data.children.slice(2))
        .map(children =>

            // map only the objects that we want
            children.map(topic => {

                let topicData = topic.data;

                // get the large preview, if it exists, else we'll keep the placeholder
                let large_image = 
                Object.keys(topicData.preview).length > 0 
                ? topicData.preview.images[0].source.url 
                : 'https://placeholdit.imgix.net/~text?txtsize=45&txt=480%C3%97360&w=480&h=360';

                // destructure
                let { id, author, title, thumbnail } = topicData;

                // return a new topic instance
                return new Topic(id, title, thumbnail, large_image, author, false);

            })
        );
    }

    checkStorage(): void {
        // if there are existing comments, set them
        if (localStorage.getItem('comments')) {

            let localComments = localStorage.getItem('comments');

            if (localComments.length > 0) {
                this.comments = JSON.parse(localStorage.getItem('comments'));
            }

        } else {
            // else, create a new localstorage item
            this.setStorage();
        }
    }

    getStorage(): any {
        return JSON.parse(localStorage.getItem('comments'));
    }

    setStorage(): void {
        localStorage.setItem('comments', JSON.stringify(this.comments));
    }

    setCommentsObservable(): void {
        
        Observable.from(this.comments)
        
        .subscribe(comments => {
            this.comment$.push(comments);
        });

    }

    getCommentsForTopic(topic_id): any {
        
        return this.comment$.filter(comment => comment.topic_id === topic_id);
        // return topicComments;
    }

    addComment(comment: Comment): void {
        this.comment$.push(comment);
        this.setStorage();
    }

    private _logFeed() {
        this.reddit$.subscribe(data => console.debug('data', data));
    }
}
<commit_msg>Set comment$ to localstorage<commit_after>import { Injectable } from '@angular/core';
import { Http } from '@angular/http';

import { Observable } from 'rxjs/Observable';

import { Topic, Comment } from './types';
import { API_URL } from './settings';

@Injectable()
export class ApiService {

  public reddit$: Observable<Array<Topic>>;
  public comments: Comment[];
  public comment$: Comment[] = [];

  constructor(
    private http: Http
  ) {
    this.getTopics();
    this.checkStorage();
    this.setCommentsObservable();
    this._logFeed();
  }

  getTopics(): void {
    this.reddit$ = this.http.get(`${API_URL}breathless.json`)
        .map(response => response.json())

        // for now, slice the first two mod posts
        .map(json => json.data.children.slice(2))
        .map(children =>

            // map only the objects that we want
            children.map(topic => {

                let topicData = topic.data;

                // get the large preview, if it exists, else we'll keep the placeholder
                let large_image = 
                Object.keys(topicData.preview).length > 0 
                ? topicData.preview.images[0].source.url 
                : 'https://placeholdit.imgix.net/~text?txtsize=45&txt=480%C3%97360&w=480&h=360';

                // destructure
                let { id, author, title, thumbnail } = topicData;

                // return a new topic instance
                return new Topic(id, title, thumbnail, large_image, author, false);

            })
        );
    }

    checkStorage(): void {
        // if there are existing comments, set them
        if (localStorage.getItem('comments')) {

            let localComments = localStorage.getItem('comments');

            if (localComments.length > 0) {
                this.comments = JSON.parse(localStorage.getItem('comments'));
            }

        } else {
            // else, create a new localstorage item
            this.setStorage();
        }
    }

    getStorage(): any {
        return JSON.parse(localStorage.getItem('comments'));
    }

    setStorage(): void {
        localStorage.setItem('comments', JSON.stringify(this.comment$));
    }

    setCommentsObservable(): void {
        
        Observable.from(this.comments)
        
        .subscribe(comments => {
            this.comment$.push(comments);
        });

    }

    getCommentsForTopic(topic_id): any {
        
        return this.comment$.filter(comment => comment.topic_id === topic_id);
        // return topicComments;
    }

    addComment(comment: Comment): void {
        this.comment$.push(comment);
        this.setStorage();
    }

    private _logFeed() {
        this.reddit$.subscribe(data => console.debug('data', data));
    }
}

{'fraction_non_alphanumeric': 0.1298417894162575, 'fraction_numerical': 0.007637752318603383, 'mean_word_length': 2.035320088300221, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 25, 'https://': 2, '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': '218322', 'n_tokens_mistral': 1581, 'n_tokens_neox': 1494, 'n_words': 335}