Created
December 4, 2018 21:55
-
-
Save whisher/bba0720c35d9b365b4a641c8dea755fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { select, Store } from '@ngrx/store'; | |
import { Observable } from 'rxjs'; | |
import { selectAllProjects, selectCurrentProject } from '..'; | |
import { Project } from '../../projects/project.model'; | |
import { ProjectsState } from './projects.reducer'; | |
import { LoadProjects, AddProject, UpdateProject, DeleteProject, SelectProject } from './projects.actions'; | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class ProjectsFacade { | |
projects$: Observable<Project[]>; | |
currentProject$: Observable<Project>; | |
constructor(private store: Store<ProjectsState>){ | |
this.projects$ = store.pipe(select(selectAllProjects)); | |
this.currentProject$ = store.pipe(select(selectCurrentProject)); | |
} | |
getProjects() { | |
this.store.dispatch(new LoadProjects()); | |
} | |
selectProject(project) { | |
this.store.dispatch(new SelectProject(project.id)); | |
} | |
createProject(project) { | |
this.store.dispatch(new AddProject(project)); | |
} | |
updateProject(project) { | |
this.store.dispatch(new UpdateProject(project)); | |
} | |
deleteProject(project) { | |
this.store.dispatch(new DeleteProject(project)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment