<commit_before>import { Component, OnInit } from '@angular/core';
import { NgRedux } from 'ng2-redux';
import { Observable } from 'rxjs/Observable';
import * as _ from "lodash";

import { FilterState } from '../state/app.initialState';

import { FilteringHotelsService } from '../filtering-hotels.service';

@Component({
  moduleId: module.id,
  selector: 'hotels-list',
  templateUrl: './hotels-list.html'
})
export class HotelsListComponent implements OnInit {
  private hotels: Object[];
  private allHotels: Object[];
  private accommodationTypesState$

  constructor(
    private filteringHotelsService: FilteringHotelsService,
    private ngRedux: NgRedux<FilterState>
  ) {

    this.accommodationTypesState$ = this.ngRedux.subscribe(() => {
      console.log(this.ngRedux.getState());
      this.onFilterHotels(this.ngRedux.getState());
    });
  }

  ngOnInit() {
    this.filteringHotelsService.getHotels()
      .then(hotels => {
        this.allHotels = hotels;
        this.onFilterHotels(this.ngRedux.getState());
      });
  }

  onFilterHotels(state) {
    var selectedAccommodations = state.accommodationTypes.filter(accommodationType => accommodationType.checked);

    var hotels = this.allHotels.filter(hotel => {
      var x = false;
      selectedAccommodations.forEach(accommodation => {
        x = accommodation.name === hotel.accommodationType;
      });
      return x;
    });

    this.hotels = hotels;
  }
}
<commit_msg>Filtering accommodations based on state<commit_after>import { Component, OnInit } from '@angular/core';
import { NgRedux } from 'ng2-redux';
import { Observable } from 'rxjs/Observable';
import * as _ from "lodash";

import { FilterState } from '../state/app.initialState';

import { FilteringHotelsService } from '../filtering-hotels.service';

@Component({
  moduleId: module.id,
  selector: 'hotels-list',
  templateUrl: './hotels-list.html'
})
export class HotelsListComponent implements OnInit {
  private hotels: Object[];
  private allHotels: Object[];
  private accommodationTypesState$

  constructor(
    private filteringHotelsService: FilteringHotelsService,
    private ngRedux: NgRedux<FilterState>
  ) {
    this.accommodationTypesState$ = this.ngRedux.subscribe(() => {
      this.onFilterHotels(this.ngRedux.getState());
    });
  }

  ngOnInit() {
    this.filteringHotelsService.getHotels()
      .then(hotels => {
        this.allHotels = hotels;
        this.onFilterHotels(this.ngRedux.getState());
      });
  }

  onFilterHotels(state) {
    var selectedAccommodations = state.accommodationTypes.filter(accommodationType => accommodationType.checked);

    this.hotels = this.allHotels.filter(hotel => {
      return !!_.find(selectedAccommodations, {name: hotel.accommodationType});
    });
  }
}

{'fraction_non_alphanumeric': 0.12950937950937952, 'fraction_numerical': 0.0007215007215007215, 'mean_word_length': 3.873462214411248, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 14, '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': '5817896', 'n_tokens_mistral': 878, 'n_tokens_neox': 866, 'n_words': 157}