From c7f137c48aec0298fc05b3886619cceb919e20f0 Mon Sep 17 00:00:00 2001 From: Florian Hartwich Date: Tue, 21 Mar 2017 03:34:47 +0100 Subject: [PATCH] Optimize database structure --- .../services/login-service/login-service.ts | 9 ++--- .../src/app/services/stores/user.store.ts | 33 +------------------ 2 files changed, 3 insertions(+), 39 deletions(-) diff --git a/project-manager/src/app/services/login-service/login-service.ts b/project-manager/src/app/services/login-service/login-service.ts index f5cb318..041041b 100644 --- a/project-manager/src/app/services/login-service/login-service.ts +++ b/project-manager/src/app/services/login-service/login-service.ts @@ -1,9 +1,8 @@ import {Injectable, Inject, Optional} from '@angular/core'; import {User} from '../../models/model-interfaces'; -import {Http, URLSearchParams, RequestMethod, RequestOptions} from '@angular/http'; +import {Http} from '@angular/http'; import {Observable} from 'rxjs/Observable'; -import {BehaviorSubject} from 'rxjs/BehaviorSubject'; -import {LOAD, ADD, EDIT, REMOVE, UserStore} from '../stores/user.store'; +import {UserStore} from '../stores/user.store'; import {SOCKET_IO, AUTH_ENABLED} from '../../app.tokens'; const BASE_URL = `http://localhost:3000/api/users`; @@ -25,10 +24,6 @@ export class LoginService { @Inject(SOCKET_IO) socketIO) { this.users$ = userStore.items$; this.socket = socketIO(WEB_SOCKET_URL); - Observable.fromEvent(this.socket, 'user_saved') - .subscribe((action) => { - this.userStore.dispatch(action); - }); } getUser(name: string) : User[]{ diff --git a/project-manager/src/app/services/stores/user.store.ts b/project-manager/src/app/services/stores/user.store.ts index 262e61f..1cf06c2 100644 --- a/project-manager/src/app/services/stores/user.store.ts +++ b/project-manager/src/app/services/stores/user.store.ts @@ -1,39 +1,8 @@ import {BehaviorSubject} from 'rxjs/BehaviorSubject'; import {User} from '../../models/model-interfaces'; -export const LOAD = 'LOAD'; -export const ADD = 'ADD'; -export const EDIT = 'EDIT'; -export const REMOVE = 'REMOVE'; - export class UserStore { - private users: User[] = []; + items$ = new BehaviorSubject([]); - dispatch(action) { - console.log("dispatched") - this.users = this._reduce(this.users, action); - this.items$.next(this.users); - } - - _reduce(users: User[], action) { - switch (action.type) { - case LOAD: - return [...action.data]; - case ADD: - return [...users, action.data]; - case EDIT: - return users.map(user => { - const editedUser = action.data; - if (user.id !== editedUser.id){ - return user; - } - return editedUser; - }); - case REMOVE: - return users.filter(user => user.id !== action.data.id); - default: - return users; - } - } }