import {IWeatherUpdate} from '../../common/interfaces/WeatherInterfaces';
import * as Rx from '@reactivex/rxjs';

export class WeatherService {

	sleepTime = 10000;
	weatherPub: Rx.Subject<IWeatherUpdate>;
	timer: any;

	constructor() {
		this.weatherPub = new Rx.Subject<IWeatherUpdate>();
		this.start();
	}

	getWeatherUpdatePub() : Rx.Subject<IWeatherUpdate> {
		return this.weatherPub;
	}

	start() {
		this.timer = setInterval(() => {
			this.monitorWeather();
		}, this.sleepTime);
	}

	stop() {
		if (this.timer) {
			clearInterval(this.timer);
		}
	}

	monitorWeather() {
		let update:IWeatherUpdate = {
			city: 'New York',
			time: new Date(),
			tempFarenheight: 80
		};

		this.weatherPub.next(update);
	}
}

import {IWeatherUpdate} from '../../common/interfaces/WeatherInterfaces';
import * as Rx from '@reactivex/rxjs';

export class WeatherService {

	sleepTime = 1000;
	weatherPub: Rx.Subject<IWeatherUpdate>;
	timer: any;
	cities:string[];

	constructor() {
		this.cities = ['New York', 'Los Angeles', 'Chicago', 'Miami', 'Dallas', 'Washington'];
		this.weatherPub = new Rx.Subject<IWeatherUpdate>();
		this.start();
	}

	getWeatherUpdatePub() : Rx.Subject<IWeatherUpdate> {
		return this.weatherPub;
	}

	start() {
		this.timer = setInterval(() => {
			this.monitorWeather();
		}, this.sleepTime);
	}

	stop() {
		if (this.timer) {
			clearInterval(this.timer);
		}
	}

	monitorWeather() {
		let index:number = Math.floor(Math.random() * this.cities.length);

		let update:IWeatherUpdate = {
			city: this.cities[index],
			time: new Date(),
			tempFarenheight: Math.floor(Math.random() * 80) + 20
		};

		this.weatherPub.next(update);
	}
}

Put mock data in the weather service
Put mock data in the weather service
