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

Commit d1083d5

Browse files
Merge pull request #45 from sketch7/release/1.6
release 1.6 - merge from master
2 parents ee95f21 + d8ec5b0 commit d1083d5

File tree

8 files changed

+53
-14
lines changed

8 files changed

+53
-14
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## [vNext](https://github.com/sketch7/ngx.ux/compare/1.5.2...2.0.0) (2020-x-x)
1+
## [vNext](https://github.com/sketch7/ngx.ux/compare/1.6.0...2.0.0) (2020-x-x)
22

33
### Features
44

@@ -12,6 +12,12 @@
1212
This was added due to a limitation (which previously was handled via hack and is not supported anymore). [See this issue](https://github.com/angular/angular/issues/8277).
1313
- **module:** rename module to `SsvCommandModule` from `CommandModule`
1414

15+
## [1.6.0](https://github.com/sketch7/ngx.ux/compare/1.5.2...1.6.0) (2020-11-04)
16+
17+
### Features
18+
19+
- **command:** add option `handleDisabled` which won't update `disabled` attribute and manually have to manage it (as sometimes it doesn't play well with components/directives or pipes)
20+
1521
## [1.5.2](https://github.com/sketch7/ngx.ux/compare/1.5.1...1.5.2) (2020-10-30)
1622

1723
### Bug Fixes

examples/projects/example-app/src/app/command/example-command.component.html

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,27 @@ <h1>Command</h1>
105105
Save
106106
<small>with [options]</small>
107107
</button>
108+
<button mat-raised-button
109+
color="primary"
110+
[disabled]="!saveCmd.canExecute"
111+
[ssvCommand]="saveCmd"
112+
[ssvCommandOptions]="{handleDisabled: false}">
113+
Save
114+
<small>with [handleDisabled]</small>
115+
</button>
116+
117+
<button mat-raised-button
118+
color="primary"
119+
[disabled]="!saveCmd.canExecute"
120+
[ssvCommand]="saveCmd"
121+
[ssvCommandOptions]="{handleDisabled: false}">
122+
Save
123+
<small>with [handleDisabled]</small>
124+
</button>
108125
</mat-card-actions>
109126
</mat-card>
110127

111-
<mat-card>
128+
<mat-card *ngIf="true">
112129
<mat-card-title>Using Command Redux</mat-card-title>
113130
<mat-card-content>
114131
<div class="btn-group"

examples/projects/example-app/tsconfig.app.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* To learn more about this file see: https://angular.io/config/tsconfig. */
12
{
23
"extends": "../../tsconfig.json",
34
"compilerOptions": {

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ssv/ngx.command",
3-
"version": "1.5.2",
3+
"version": "1.6.0",
44
"versionSuffix": "",
55
"description": "Command pattern implementation for angular. Command used to encapsulate information which is needed to perform an action.",
66
"keywords": [

src/command.directive.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
OnInit,
44
OnDestroy,
55
Input,
6-
HostBinding,
76
HostListener,
87
ElementRef,
98
Inject,
@@ -61,21 +60,25 @@ import { CommandCreator, ICommand } from "./command.model";
6160
* ```
6261
*
6362
*/
63+
64+
const SELECTOR = "ssvCommand";
65+
6466
@Directive({
65-
selector: "[ssvCommand], [command]", // todo: @deprecated - remove `[command]` after next major
67+
selector: `[${SELECTOR}], [command]`, // todo: @deprecated - remove `[command]` after next major
6668
exportAs: "ssvCommand"
6769
})
6870
export class CommandDirective implements OnInit, OnDestroy {
6971

70-
@Input("ssvCommand") commandOrCreator: ICommand | CommandCreator | undefined;
72+
@Input(SELECTOR) commandOrCreator: ICommand | CommandCreator | undefined;
7173

7274
/** @deprecated Use `commandInput` instead. */
7375
@Input("command")
7476
get _commandOrCreator(): ICommand | CommandCreator | undefined { return this.commandOrCreator; }
7577
set _commandOrCreator(value: ICommand | CommandCreator | undefined) {
7678
this.commandOrCreator = value;
7779
}
78-
@Input("ssvCommandOptions")
80+
81+
@Input(`${SELECTOR}Options`)
7982
get commandOptions(): CommandOptions { return this._commandOptions; }
8083
set commandOptions(value: CommandOptions) {
8184
if (value === this._commandOptions) {
@@ -94,14 +97,13 @@ export class CommandDirective implements OnInit, OnDestroy {
9497
this.commandOptions = value;
9598
}
9699

97-
@Input("ssvCommandParams") commandParams: unknown | unknown[];
100+
@Input(`${SELECTOR}Params`) commandParams: unknown | unknown[];
98101
/** @deprecated Use `commandParams` instead. */
99102
@Input("commandParams")
100103
get _commandParams(): unknown | unknown[] { return this.commandParams; }
101104
set _commandParams(value: unknown | unknown[]) {
102105
this.commandParams = value;
103106
}
104-
@HostBinding("disabled") isDisabled: boolean | undefined;
105107

106108
get command(): ICommand { return this._command; }
107109
private _command!: ICommand;
@@ -118,7 +120,7 @@ export class CommandDirective implements OnInit, OnDestroy {
118120

119121
ngOnInit(): void {
120122
// console.log("[ssvCommand::init]", this.config);
121-
this.isDisabled = true;
123+
this.trySetDisabled(true);
122124
if (!this.commandOrCreator) {
123125
throw new Error("ssvCommand: [ssvCommand] should be defined!");
124126
} else if (isCommand(this.commandOrCreator)) {
@@ -148,8 +150,8 @@ export class CommandDirective implements OnInit, OnDestroy {
148150
this._command.canExecute$.pipe(
149151
delay(1),
150152
tap(x => {
151-
this.isDisabled = !x;
152-
// console.log("[ssvCommand::canExecute$] x2", x, this.isDisabled);
153+
this.trySetDisabled(!x);
154+
// console.log("[ssvCommand::canExecute$]", { canExecute: x });
153155
this.cdr.markForCheck();
154156
}),
155157
takeUntil(this._destroy$),
@@ -195,5 +197,11 @@ export class CommandDirective implements OnInit, OnDestroy {
195197
}
196198
}
197199

200+
private trySetDisabled(disabled: boolean) {
201+
if (this.commandOptions.handleDisabled) {
202+
this.renderer.setProperty(this.element.nativeElement, "disabled", disabled);
203+
}
204+
}
205+
198206
}
199207

src/config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@ export interface CommandOptions {
55
* Css Class which gets added/removed on the Command element's host while Command `isExecuting$`.
66
*/
77
executingCssClass: string;
8+
9+
/** Determines whether the disabled will be handled by the directive or not.
10+
* Disable handled by directive's doesn't always play nice when used with other component/pipe/directive and they also handle disabled.
11+
* This disables the handling manually and need to pass explicitly `[disabled]="!saveCmd.canExecute"`.
12+
*/
13+
handleDisabled: boolean;
814
}
915

1016
export const COMMAND_DEFAULT_CONFIG: Readonly<CommandOptions> = Object.freeze({
1117
executingCssClass: "executing",
18+
handleDisabled: true,
1219
});
1320

1421
export const COMMAND_CONFIG = new InjectionToken<CommandOptions>("command-config");

src/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const _MODULE_CONFIG = new InjectionToken<CommandOptions>("_command-confi
1414
})
1515
export class CommandModule { // todo: rename to SsvCommandModule
1616

17-
static forRoot(config?: CommandOptions | (() => CommandOptions)): ModuleWithProviders<CommandModule> {
17+
static forRoot(config?: Partial<CommandOptions> | (() => Partial<CommandOptions>)): ModuleWithProviders<CommandModule> {
1818
return {
1919
ngModule: CommandModule,
2020
providers: [

0 commit comments

Comments
 (0)