Skip to content

Instantly share code, notes, and snippets.

View wojtek1150's full-sized avatar
🏕️

Wojciech wojtek1150

🏕️
View GitHub Profile
@Injectable()
export class UsersEffect {
constructor(
private actions$: Actions,
private usersService: UsersService
) {}
@Effect()
loadUsers$ = this.actions$
.ofType(usersActions.LOAD_USERS)
import { Store } from '@ngrx/store';
import * as fromStore from '../../store';
export class MyComponent(){
constructor(private store: Store<fromStore.UsersState>) { }
loadUsers(){
this.store.dispatch(new fromStore.LoadUsers());
}
}
import * as fromUsers from '../actions/users.action';
import { Users } from 'resources/users/users';
export interface UsersState {
entities: Users.Entities;
loaded: boolean,
loading: boolean
}
export const initialState: UsersState = {
import { Action } from '@ngrx/store';
export const LOAD_USERS = '[Users] Load Users'; // It's good practice to add namespace for each action module
export const LOAD_USERS_FAIL = '[Users] Load Users Fail';
export const LOAD_USERS_SUCCESS = '[Users] Load Users Success';
export class LoadUsers implements Action {
readonly type = LOAD_USERS;
}