Skip to content
This repository has been archived by the owner on Nov 3, 2024. It is now read-only.

Commit

Permalink
fix(utils): canExecuteFromNgForm add delay to cater for pristine ch…
Browse files Browse the repository at this point in the history
…anges (#63)
  • Loading branch information
Exslims authored Jul 12, 2022
1 parent ace6802 commit 30e4ecd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<!-- ## [vNext](https://github.com/sktch7/ngx.command/compare/2.0.0...3.0.0) (2020-x-x) -->

## [2.1.0](https://github.com/sketch7/ngx.command/compare/2.0.0...2.1.0) (2022-07-12)

### Features

- **util:** `canExecuteFromNgForm` now have delay(0) which is fixing issue when observable `form.statusChanges` wasn't triggered after reset or make pristine form from the code.

## [2.0.0](https://github.com/sketch7/ngx.command/compare/1.6.0...2.0.0) (2021-08-25)

### Features
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ssv/ngx.command",
"version": "2.0.0",
"version": "2.1.0",
"versionSuffix": "",
"description": "Command pattern implementation for angular. Command used to encapsulate information which is needed to perform an action.",
"keywords": [
Expand Down
3 changes: 2 additions & 1 deletion src/command.util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AbstractControl, AbstractControlDirective } from "@angular/forms";
import { Observable, of } from "rxjs";
import { map, distinctUntilChanged, startWith } from "rxjs/operators";
import { map, distinctUntilChanged, startWith, delay } from "rxjs/operators";

import { CommandCreator, ICommand } from "./command.model";
import { Command } from "./command";
Expand Down Expand Up @@ -37,6 +37,7 @@ export function canExecuteFromNgForm(

return form.statusChanges
? form.statusChanges.pipe(
delay(0),
startWith(form.valid),
map(() => !!(!opts.validity || form.valid) && !!(!opts.dirty || form.dirty)),
distinctUntilChanged(),
Expand Down

0 comments on commit 30e4ecd

Please sign in to comment.