Browse Source

Merge pull request #2085 from abpframework/refactor/update-actions

refactor(identity): remove redundant getById dispatch in update actions
pull/2090/head
Mehmet Erim 7 years ago
committed by GitHub
parent
commit
9c91a8609d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      npm/ng-packs/packages/identity/src/lib/components/roles/roles.component.ts
  2. 1
      npm/ng-packs/packages/identity/src/lib/components/users/users.component.ts
  3. 14
      npm/ng-packs/packages/identity/src/lib/states/identity.state.ts

2
npm/ng-packs/packages/identity/src/lib/components/roles/roles.component.ts

@ -87,7 +87,7 @@ export class RolesComponent implements OnInit {
this.store this.store
.dispatch( .dispatch(
this.selected.id this.selected.id
? new UpdateRole({ ...this.form.value, id: this.selected.id }) ? new UpdateRole({ ...this.selected, ...this.form.value, id: this.selected.id })
: new CreateRole(this.form.value), : new CreateRole(this.form.value),
) )
.subscribe(() => { .subscribe(() => {

1
npm/ng-packs/packages/identity/src/lib/components/users/users.component.ts

@ -176,6 +176,7 @@ export class UsersComponent implements OnInit {
.dispatch( .dispatch(
this.selected.id this.selected.id
? new UpdateUser({ ? new UpdateUser({
...this.selected,
...this.form.value, ...this.form.value,
id: this.selected.id, id: this.selected.id,
roleNames: mappedRoleNames, roleNames: mappedRoleNames,

14
npm/ng-packs/packages/identity/src/lib/states/identity.state.ts

@ -77,10 +77,9 @@ export class IdentityState {
@Action(UpdateRole) @Action(UpdateRole)
updateRole({ getState, dispatch }: StateContext<Identity.State>, { payload }: UpdateRole) { updateRole({ getState, dispatch }: StateContext<Identity.State>, { payload }: UpdateRole) {
return dispatch(new GetRoleById(payload.id)).pipe( return this.identityService
switchMap(() => this.identityService.updateRole({ ...getState().selectedRole, ...payload })), .updateRole({ ...getState().selectedRole, ...payload })
switchMap(() => dispatch(new GetRoles())), .pipe(switchMap(() => dispatch(new GetRoles())));
);
} }
@Action(GetUsers) @Action(GetUsers)
@ -117,10 +116,9 @@ export class IdentityState {
@Action(UpdateUser) @Action(UpdateUser)
updateUser({ getState, dispatch }: StateContext<Identity.State>, { payload }: UpdateUser) { updateUser({ getState, dispatch }: StateContext<Identity.State>, { payload }: UpdateUser) {
return dispatch(new GetUserById(payload.id)).pipe( return this.identityService
switchMap(() => this.identityService.updateUser({ ...getState().selectedUser, ...payload })), .updateUser({ ...getState().selectedUser, ...payload })
switchMap(() => dispatch(new GetUsers())), .pipe(switchMap(() => dispatch(new GetUsers())));
);
} }
@Action(GetUserRoles) @Action(GetUserRoles)

Loading…
Cancel
Save