Chat with Angular and Django./ User list store. Frontent.

Add an interface UserListState based on EntityState class.

Create a new action core/src/store/actions/user.action.ts.

Create a new reducer based on EntityAdapter.

Add the new UserReducer reducer into ActionReducerMap.

admin

Dispach an action from index component.

...
import { EntityState } from '@ngrx/entity';

export interface IUserState {
    id: number;
    username: string;
    gender: string;
    birthday: string;
    main_photo: string;
    is_online: boolean;
}

export class UserState implements IUserState {
    constructor(
        public id: number = 0,
        public username: string = 'undefined',
        public gender: string = 'undefined',
        public birthday: string = 'undefined',
        public main_photo: string = 'undefined',
        public is_online: boolean = false
        ) {


    }
}

export interface UserListState extends EntityState<UserState> {
}

export const defaultState = {
};
import { Action } from '@ngrx/store';
import { UserState } from '../states/user.state';

export enum UserActionTypes {
  UpdateUsers = '[User] Update users',
  UpdateUser = '[User] Update One user',
  UpdateUsersDone = '[User] Update users DONE!!!',
}

export class UpdateUsers implements Action {
  readonly type = UserActionTypes.UpdateUsers;
  constructor(public payload: UserState[]) {}
}

export class UpdateUser implements Action {
  readonly type = UserActionTypes.UpdateUser;
  constructor(public payload: UserState) {}
}

export class UpdateUsersDone implements Action {
  readonly type = UserActionTypes.UpdateUsersDone;
}


export type UserActionsUnion =
UpdateUsers |
UpdateUser |
UpdateUsersDone;
admin
Потратить 2 кредита и начать обучение! У вас кредитов(а)
Задать вопрос, прокомментировать.