@ssv/ngx.command 2.3.2-dev.11 → 3.0.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +242 -242
- package/eslint.config.js +43 -0
- package/jest.config.ts +21 -0
- package/ng-package.json +7 -0
- package/package.json +2 -26
- package/project.json +36 -0
- package/src/command-ref.directive.ts +57 -0
- package/src/command.directive.ts +192 -0
- package/src/command.directive.xspec.ts +105 -0
- package/src/command.model.ts +36 -0
- package/src/command.options.ts +45 -0
- package/src/command.spec.ts +215 -0
- package/src/command.ts +170 -0
- package/src/command.util.ts +50 -0
- package/{index.d.ts → src/index.ts} +8 -8
- package/src/module.ts +17 -0
- package/src/test-setup.ts +8 -0
- package/src/version.ts +1 -0
- package/tsconfig.json +28 -0
- package/tsconfig.lib.json +17 -0
- package/tsconfig.lib.prod.json +9 -0
- package/tsconfig.spec.json +16 -0
- package/LICENSE +0 -21
- package/command-ref.directive.d.ts +0 -29
- package/command.d.ts +0 -47
- package/command.directive.d.ts +0 -25
- package/command.model.d.ts +0 -28
- package/command.util.d.ts +0 -15
- package/config.d.ts +0 -18
- package/esm2020/command-ref.directive.mjs +0 -54
- package/esm2020/command.directive.mjs +0 -166
- package/esm2020/command.mjs +0 -127
- package/esm2020/command.model.mjs +0 -2
- package/esm2020/command.util.mjs +0 -29
- package/esm2020/config.mjs +0 -8
- package/esm2020/index.mjs +0 -8
- package/esm2020/module.mjs +0 -49
- package/esm2020/ssv-ngx.command.mjs +0 -5
- package/esm2020/version.mjs +0 -2
- package/fesm2015/ssv-ngx.command.mjs +0 -419
- package/fesm2015/ssv-ngx.command.mjs.map +0 -1
- package/fesm2020/ssv-ngx.command.mjs +0 -424
- package/fesm2020/ssv-ngx.command.mjs.map +0 -1
- package/module.d.ts +0 -15
- package/version.d.ts +0 -1
package/src/command.ts
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { Observable, combineLatest, Subscription, Subject, BehaviorSubject, of, EMPTY } from "rxjs";
|
|
3
|
+
import { tap, map, filter, switchMap, catchError, finalize, take } from "rxjs/operators";
|
|
4
|
+
import { ICommand } from "./command.model";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Command object used to encapsulate information which is needed to perform an action.
|
|
8
|
+
*/
|
|
9
|
+
export class Command implements ICommand {
|
|
10
|
+
|
|
11
|
+
/** Determines whether the command is currently executing, as a snapshot value. */
|
|
12
|
+
get isExecuting(): boolean {
|
|
13
|
+
return this._isExecuting;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Determines whether the command can execute or not, as a snapshot value. */
|
|
17
|
+
get canExecute(): boolean {
|
|
18
|
+
return this._canExecute;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Determines whether the command is currently executing, as an observable. */
|
|
22
|
+
get isExecuting$(): Observable<boolean> {
|
|
23
|
+
return this._isExecuting$.asObservable();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Determines whether to auto destroy when having 0 subscribers. */
|
|
27
|
+
autoDestroy = true;
|
|
28
|
+
|
|
29
|
+
/** Determines whether the command can execute or not, as an observable. */
|
|
30
|
+
readonly canExecute$: Observable<boolean>;
|
|
31
|
+
|
|
32
|
+
private _isExecuting$ = new BehaviorSubject<boolean>(false);
|
|
33
|
+
private _isExecuting = false;
|
|
34
|
+
private _canExecute = true;
|
|
35
|
+
private executionPipe$ = new Subject<unknown[] | undefined>();
|
|
36
|
+
private isExecuting$$ = Subscription.EMPTY;
|
|
37
|
+
private canExecute$$ = Subscription.EMPTY;
|
|
38
|
+
private executionPipe$$ = Subscription.EMPTY;
|
|
39
|
+
private subscribersCount = 0;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Creates an instance of Command.
|
|
43
|
+
*
|
|
44
|
+
* @param execute Execute function to invoke - use `isAsync: true` when `Observable<any>`.
|
|
45
|
+
* @param canExecute Observable which determines whether it can execute or not.
|
|
46
|
+
* @param isAsync Indicates that the execute function is async e.g. Observable.
|
|
47
|
+
*/
|
|
48
|
+
constructor(
|
|
49
|
+
execute: (...args: unknown[]) => unknown,
|
|
50
|
+
canExecute$?: Observable<boolean>,
|
|
51
|
+
isAsync?: boolean,
|
|
52
|
+
) {
|
|
53
|
+
if (canExecute$) {
|
|
54
|
+
this.canExecute$ = combineLatest([
|
|
55
|
+
this._isExecuting$,
|
|
56
|
+
canExecute$
|
|
57
|
+
]).pipe(
|
|
58
|
+
map(([isExecuting, canExecuteResult]) => {
|
|
59
|
+
// console.log("[command::combineLatest$] update!", { isExecuting, canExecuteResult });
|
|
60
|
+
this._isExecuting = isExecuting;
|
|
61
|
+
this._canExecute = !isExecuting && !!canExecuteResult;
|
|
62
|
+
return this._canExecute;
|
|
63
|
+
}),
|
|
64
|
+
);
|
|
65
|
+
this.canExecute$$ = this.canExecute$.subscribe();
|
|
66
|
+
} else {
|
|
67
|
+
this.canExecute$ = this._isExecuting$.pipe(
|
|
68
|
+
map(x => {
|
|
69
|
+
const canExecute = !x;
|
|
70
|
+
this._canExecute = canExecute;
|
|
71
|
+
return canExecute;
|
|
72
|
+
})
|
|
73
|
+
);
|
|
74
|
+
this.isExecuting$$ = this._isExecuting$
|
|
75
|
+
.pipe(tap(x => this._isExecuting = x))
|
|
76
|
+
.subscribe();
|
|
77
|
+
}
|
|
78
|
+
this.executionPipe$$ = this.buildExecutionPipe(execute, isAsync).subscribe();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Execute function to invoke. */
|
|
82
|
+
execute(...args: unknown[]): void {
|
|
83
|
+
// console.warn("[command::execute]", args);
|
|
84
|
+
this.executionPipe$.next(args);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Disposes all resources held by subscriptions. */
|
|
88
|
+
destroy(): void {
|
|
89
|
+
// console.warn("[command::destroy]");
|
|
90
|
+
this.executionPipe$$.unsubscribe();
|
|
91
|
+
this.canExecute$$.unsubscribe();
|
|
92
|
+
this.isExecuting$$.unsubscribe();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
subscribe(): void {
|
|
96
|
+
this.subscribersCount++;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
unsubscribe(): void {
|
|
100
|
+
this.subscribersCount--;
|
|
101
|
+
// console.log("[command::unsubscribe]", { autoDestroy: this.autoDestroy, subscribersCount: this.subscribersCount });
|
|
102
|
+
if (this.autoDestroy && this.subscribersCount <= 0) {
|
|
103
|
+
this.destroy();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
private buildExecutionPipe(execute: (...args: unknown[]) => any, isAsync?: boolean): Observable<unknown> {
|
|
108
|
+
let pipe$ = this.executionPipe$.pipe(
|
|
109
|
+
// tap(x => console.warn(">>>> executionPipe", this._canExecute)),
|
|
110
|
+
filter(() => this._canExecute),
|
|
111
|
+
tap(() => {
|
|
112
|
+
// console.log("[command::executionPipe$] do#1 - set execute", { args: x });
|
|
113
|
+
this._isExecuting$.next(true);
|
|
114
|
+
})
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
const execFn = isAsync
|
|
118
|
+
? switchMap<unknown[] | undefined, any[]>(args => {
|
|
119
|
+
if (args) {
|
|
120
|
+
return execute(...args);
|
|
121
|
+
}
|
|
122
|
+
return execute();
|
|
123
|
+
})
|
|
124
|
+
: tap((args: unknown[] | undefined) => {
|
|
125
|
+
if (args) {
|
|
126
|
+
execute(...args);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
execute();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
pipe$ = pipe$.pipe(
|
|
133
|
+
switchMap(args => of(args).pipe(
|
|
134
|
+
execFn,
|
|
135
|
+
finalize(() => {
|
|
136
|
+
// console.log("[command::executionPipe$] finalize inner#1 - set idle");
|
|
137
|
+
this._isExecuting$.next(false);
|
|
138
|
+
}),
|
|
139
|
+
take(1),
|
|
140
|
+
catchError(error => {
|
|
141
|
+
console.error("Unhandled execute error", error);
|
|
142
|
+
return EMPTY;
|
|
143
|
+
}),
|
|
144
|
+
)),
|
|
145
|
+
tap(
|
|
146
|
+
() => {
|
|
147
|
+
// console.log("[command::executionPipe$] tap#2 - set idle");
|
|
148
|
+
this._isExecuting$.next(false);
|
|
149
|
+
},
|
|
150
|
+
)
|
|
151
|
+
);
|
|
152
|
+
return pipe$;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Async Command object used to encapsulate information which is needed to perform an action,
|
|
159
|
+
* which takes an execute function as Observable/Promise.
|
|
160
|
+
*/
|
|
161
|
+
export class CommandAsync extends Command {
|
|
162
|
+
|
|
163
|
+
constructor(
|
|
164
|
+
execute: (...args: any[]) => Observable<unknown> | Promise<unknown>,
|
|
165
|
+
canExecute$?: Observable<boolean>,
|
|
166
|
+
) {
|
|
167
|
+
super(execute, canExecute$, true);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { AbstractControl, AbstractControlDirective, FormControlStatus } from "@angular/forms";
|
|
2
|
+
import { Observable, of } from "rxjs";
|
|
3
|
+
import { map, distinctUntilChanged, startWith, delay } from "rxjs/operators";
|
|
4
|
+
|
|
5
|
+
import { CommandCreator, ICommand } from "./command.model";
|
|
6
|
+
import { Command } from "./command";
|
|
7
|
+
|
|
8
|
+
/** Determines whether the arg object is of type `Command`. */
|
|
9
|
+
export function isCommand(arg: unknown): arg is ICommand {
|
|
10
|
+
return arg instanceof Command;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Determines whether the arg object is of type `CommandCreator`. */
|
|
14
|
+
export function isCommandCreator(arg: unknown): arg is CommandCreator {
|
|
15
|
+
if (arg instanceof Command) {
|
|
16
|
+
return false;
|
|
17
|
+
} else if (isAssumedType<CommandCreator>(arg) && arg.execute && arg.host) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface CanExecuteFormOptions {
|
|
24
|
+
/** Determines whether to check for validity. (defaults: true) */
|
|
25
|
+
validity?: boolean;
|
|
26
|
+
|
|
27
|
+
/** Determines whether to check whether UI has been touched. (defaults: true) */
|
|
28
|
+
dirty?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Get form is valid as an observable. */
|
|
32
|
+
export function canExecuteFromNgForm(
|
|
33
|
+
form: AbstractControl | AbstractControlDirective,
|
|
34
|
+
options?: CanExecuteFormOptions
|
|
35
|
+
): Observable<boolean> {
|
|
36
|
+
const opts: CanExecuteFormOptions = { validity: true, dirty: true, ...options };
|
|
37
|
+
|
|
38
|
+
return form.statusChanges
|
|
39
|
+
? (form.statusChanges as Observable<FormControlStatus>).pipe( // todo: remove cast when working correctly
|
|
40
|
+
delay(0),
|
|
41
|
+
startWith(form.valid),
|
|
42
|
+
map(() => !!(!opts.validity || form.valid) && !!(!opts.dirty || form.dirty)),
|
|
43
|
+
distinctUntilChanged(),
|
|
44
|
+
)
|
|
45
|
+
: of(true);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function isAssumedType<T = Record<string, unknown>>(x: unknown): x is Partial<T> {
|
|
49
|
+
return x !== null && typeof x === "object";
|
|
50
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from "./command";
|
|
2
|
-
export * from "./command.directive";
|
|
3
|
-
export * from "./command-ref.directive";
|
|
4
|
-
export * from "./command.util";
|
|
5
|
-
export { CommandCreator, ICommand } from "./command.model";
|
|
6
|
-
export * from "./
|
|
7
|
-
export * from "./module";
|
|
8
|
-
export * from "./version";
|
|
1
|
+
export * from "./command";
|
|
2
|
+
export * from "./command.directive";
|
|
3
|
+
export * from "./command-ref.directive";
|
|
4
|
+
export * from "./command.util";
|
|
5
|
+
export { CommandCreator, ICommand } from "./command.model";
|
|
6
|
+
export * from "./command.options";
|
|
7
|
+
export * from "./module";
|
|
8
|
+
export * from "./version";
|
package/src/module.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { NgModule } from "@angular/core";
|
|
2
|
+
|
|
3
|
+
import { CommandDirective } from "./command.directive";
|
|
4
|
+
import { CommandRefDirective } from "./command-ref.directive";
|
|
5
|
+
|
|
6
|
+
const EXPORTED_IMPORTS = [
|
|
7
|
+
CommandDirective,
|
|
8
|
+
CommandRefDirective
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
@NgModule({
|
|
12
|
+
imports: [EXPORTED_IMPORTS],
|
|
13
|
+
exports: [EXPORTED_IMPORTS]
|
|
14
|
+
})
|
|
15
|
+
export class SsvCommandModule {
|
|
16
|
+
|
|
17
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// @ts-expect-error https://thymikee.github.io/jest-preset-angular/docs/getting-started/test-environment
|
|
2
|
+
globalThis.ngJest = {
|
|
3
|
+
testEnvironmentOptions: {
|
|
4
|
+
errorOnUnknownElements: true,
|
|
5
|
+
errorOnUnknownProperties: true,
|
|
6
|
+
},
|
|
7
|
+
};
|
|
8
|
+
import 'jest-preset-angular/setup-jest';
|
package/src/version.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const VERSION = "0.0.0-PLACEHOLDER";
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2022",
|
|
4
|
+
"forceConsistentCasingInFileNames": true,
|
|
5
|
+
"strict": true,
|
|
6
|
+
"noImplicitOverride": true,
|
|
7
|
+
"noPropertyAccessFromIndexSignature": true,
|
|
8
|
+
"noImplicitReturns": true,
|
|
9
|
+
"noFallthroughCasesInSwitch": true
|
|
10
|
+
},
|
|
11
|
+
"files": [],
|
|
12
|
+
"include": [],
|
|
13
|
+
"references": [
|
|
14
|
+
{
|
|
15
|
+
"path": "./tsconfig.lib.json"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"path": "./tsconfig.spec.json"
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"extends": "../../tsconfig.base.json",
|
|
22
|
+
"angularCompilerOptions": {
|
|
23
|
+
"enableI18nLegacyMessageIdFormat": false,
|
|
24
|
+
"strictInjectionParameters": true,
|
|
25
|
+
"strictInputAccessModifiers": true,
|
|
26
|
+
"strictTemplates": true
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "../../dist/out-tsc",
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"declarationMap": true,
|
|
7
|
+
"inlineSources": true,
|
|
8
|
+
"types": []
|
|
9
|
+
},
|
|
10
|
+
"exclude": [
|
|
11
|
+
"src/**/*.spec.ts",
|
|
12
|
+
"src/test-setup.ts",
|
|
13
|
+
"jest.config.ts",
|
|
14
|
+
"src/**/*.test.ts"
|
|
15
|
+
],
|
|
16
|
+
"include": ["src/**/*.ts"]
|
|
17
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "../../dist/out-tsc",
|
|
5
|
+
"module": "commonjs",
|
|
6
|
+
"target": "es2016",
|
|
7
|
+
"types": ["jest", "node"]
|
|
8
|
+
},
|
|
9
|
+
"files": ["src/test-setup.ts"],
|
|
10
|
+
"include": [
|
|
11
|
+
"jest.config.ts",
|
|
12
|
+
"src/**/*.test.ts",
|
|
13
|
+
"src/**/*.spec.ts",
|
|
14
|
+
"src/**/*.d.ts"
|
|
15
|
+
]
|
|
16
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2016
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { OnInit, OnDestroy } from "@angular/core";
|
|
2
|
-
import { ICommand, CommandCreator } from "./command.model";
|
|
3
|
-
import * as i0 from "@angular/core";
|
|
4
|
-
/**
|
|
5
|
-
* Command creator ref, directive which allows creating Command in the template
|
|
6
|
-
* and associate it to a command (in order to share executions).
|
|
7
|
-
* @example
|
|
8
|
-
* ### Most common usage
|
|
9
|
-
* ```html
|
|
10
|
-
* <div #actionCmd="ssvCommandRef" [ssvCommandRef]="{host: this, execute: removeHero$, canExecute: isValid$}">
|
|
11
|
-
* <button [ssvCommand]="actionCmd.command" [ssvCommandParams]="hero">
|
|
12
|
-
* Remove
|
|
13
|
-
* </button>
|
|
14
|
-
* <button [ssvCommand]="actionCmd.command" [ssvCommandParams]="hero">
|
|
15
|
-
* Remove
|
|
16
|
-
* </button>
|
|
17
|
-
* </div>
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
*/
|
|
21
|
-
export declare class CommandRefDirective implements OnInit, OnDestroy {
|
|
22
|
-
commandCreator: CommandCreator | undefined;
|
|
23
|
-
get command(): ICommand;
|
|
24
|
-
private _command;
|
|
25
|
-
ngOnInit(): void;
|
|
26
|
-
ngOnDestroy(): void;
|
|
27
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<CommandRefDirective, never>;
|
|
28
|
-
static ɵdir: i0.ɵɵDirectiveDeclaration<CommandRefDirective, "[ssvCommandRef]", ["ssvCommandRef"], { "commandCreator": "ssvCommandRef"; }, {}, never, never, false, never>;
|
|
29
|
-
}
|
package/command.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { Observable } from "rxjs";
|
|
2
|
-
import { ICommand } from "./command.model";
|
|
3
|
-
/**
|
|
4
|
-
* Command object used to encapsulate information which is needed to perform an action.
|
|
5
|
-
*/
|
|
6
|
-
export declare class Command implements ICommand {
|
|
7
|
-
/** Determines whether the command is currently executing, as a snapshot value. */
|
|
8
|
-
get isExecuting(): boolean;
|
|
9
|
-
/** Determines whether the command can execute or not, as a snapshot value. */
|
|
10
|
-
get canExecute(): boolean;
|
|
11
|
-
/** Determines whether the command is currently executing, as an observable. */
|
|
12
|
-
get isExecuting$(): Observable<boolean>;
|
|
13
|
-
/** Determines whether to auto destroy when having 0 subscribers. */
|
|
14
|
-
autoDestroy: boolean;
|
|
15
|
-
/** Determines whether the command can execute or not, as an observable. */
|
|
16
|
-
readonly canExecute$: Observable<boolean>;
|
|
17
|
-
private _isExecuting$;
|
|
18
|
-
private _isExecuting;
|
|
19
|
-
private _canExecute;
|
|
20
|
-
private executionPipe$;
|
|
21
|
-
private isExecuting$$;
|
|
22
|
-
private canExecute$$;
|
|
23
|
-
private executionPipe$$;
|
|
24
|
-
private subscribersCount;
|
|
25
|
-
/**
|
|
26
|
-
* Creates an instance of Command.
|
|
27
|
-
*
|
|
28
|
-
* @param execute Execute function to invoke - use `isAsync: true` when `Observable<any>`.
|
|
29
|
-
* @param canExecute Observable which determines whether it can execute or not.
|
|
30
|
-
* @param isAsync Indicates that the execute function is async e.g. Observable.
|
|
31
|
-
*/
|
|
32
|
-
constructor(execute: (...args: unknown[]) => unknown, canExecute$?: Observable<boolean>, isAsync?: boolean);
|
|
33
|
-
/** Execute function to invoke. */
|
|
34
|
-
execute(...args: unknown[]): void;
|
|
35
|
-
/** Disposes all resources held by subscriptions. */
|
|
36
|
-
destroy(): void;
|
|
37
|
-
subscribe(): void;
|
|
38
|
-
unsubscribe(): void;
|
|
39
|
-
private buildExecutionPipe;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Async Command object used to encapsulate information which is needed to perform an action,
|
|
43
|
-
* which takes an execute function as Observable/Promise.
|
|
44
|
-
*/
|
|
45
|
-
export declare class CommandAsync extends Command {
|
|
46
|
-
constructor(execute: (...args: any[]) => Observable<unknown> | Promise<unknown>, canExecute$?: Observable<boolean>);
|
|
47
|
-
}
|
package/command.directive.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { OnInit, OnDestroy, ElementRef, Renderer2, ChangeDetectorRef } from "@angular/core";
|
|
2
|
-
import { CommandOptions } from "./config";
|
|
3
|
-
import { CommandCreator, ICommand } from "./command.model";
|
|
4
|
-
import * as i0 from "@angular/core";
|
|
5
|
-
export declare class CommandDirective implements OnInit, OnDestroy {
|
|
6
|
-
private config;
|
|
7
|
-
private renderer;
|
|
8
|
-
private element;
|
|
9
|
-
private cdr;
|
|
10
|
-
commandOrCreator: ICommand | CommandCreator | undefined;
|
|
11
|
-
get commandOptions(): CommandOptions;
|
|
12
|
-
set commandOptions(value: Partial<CommandOptions>);
|
|
13
|
-
commandParams: unknown | unknown[];
|
|
14
|
-
get command(): ICommand;
|
|
15
|
-
private _command;
|
|
16
|
-
private _commandOptions;
|
|
17
|
-
private _destroy$;
|
|
18
|
-
constructor(config: CommandOptions, renderer: Renderer2, element: ElementRef, cdr: ChangeDetectorRef);
|
|
19
|
-
ngOnInit(): void;
|
|
20
|
-
onClick(): void;
|
|
21
|
-
ngOnDestroy(): void;
|
|
22
|
-
private trySetDisabled;
|
|
23
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<CommandDirective, never>;
|
|
24
|
-
static ɵdir: i0.ɵɵDirectiveDeclaration<CommandDirective, "[ssvCommand]", ["ssvCommand"], { "commandOrCreator": "ssvCommand"; "commandOptions": "ssvCommandOptions"; "commandParams": "ssvCommandParams"; }, {}, never, never, false, never>;
|
|
25
|
-
}
|
package/command.model.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Observable } from "rxjs";
|
|
2
|
-
export interface ICommand {
|
|
3
|
-
/** Determines whether the command is currently executing, as a snapshot value. */
|
|
4
|
-
readonly isExecuting: boolean;
|
|
5
|
-
/** Determines whether the command is currently executing, as an observable. */
|
|
6
|
-
readonly isExecuting$: Observable<boolean>;
|
|
7
|
-
/** Determines whether the command can execute or not, as a snapshot value. */
|
|
8
|
-
readonly canExecute: boolean;
|
|
9
|
-
/** Determines whether the command can execute or not, as an observable. */
|
|
10
|
-
readonly canExecute$: Observable<boolean>;
|
|
11
|
-
/** Determines whether to auto destroy when having 0 subscribers (defaults to `true`). */
|
|
12
|
-
autoDestroy: boolean;
|
|
13
|
-
/** Execute function to invoke. */
|
|
14
|
-
execute(...args: unknown[]): void;
|
|
15
|
-
/** Disposes all resources held by subscriptions. */
|
|
16
|
-
destroy(): void;
|
|
17
|
-
/** Subscribe listener, in order to handle auto disposing. */
|
|
18
|
-
subscribe(): void;
|
|
19
|
-
/** Unsubscribe listener, in order to handle auto disposing. */
|
|
20
|
-
unsubscribe(): void;
|
|
21
|
-
}
|
|
22
|
-
export interface CommandCreator {
|
|
23
|
-
execute: (...args: any[]) => Observable<unknown> | Promise<unknown> | void;
|
|
24
|
-
canExecute?: Observable<boolean> | Function;
|
|
25
|
-
params?: unknown | unknown[];
|
|
26
|
-
isAsync?: boolean;
|
|
27
|
-
host: unknown;
|
|
28
|
-
}
|
package/command.util.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { AbstractControl, AbstractControlDirective } from "@angular/forms";
|
|
2
|
-
import { Observable } from "rxjs";
|
|
3
|
-
import { CommandCreator, ICommand } from "./command.model";
|
|
4
|
-
/** Determines whether the arg object is of type `Command`. */
|
|
5
|
-
export declare function isCommand(arg: unknown): arg is ICommand;
|
|
6
|
-
/** Determines whether the arg object is of type `CommandCreator`. */
|
|
7
|
-
export declare function isCommandCreator(arg: unknown): arg is CommandCreator;
|
|
8
|
-
export interface CanExecuteFormOptions {
|
|
9
|
-
/** Determines whether to check for validity. (defaults: true) */
|
|
10
|
-
validity?: boolean;
|
|
11
|
-
/** Determines whether to check whether UI has been touched. (defaults: true) */
|
|
12
|
-
dirty?: boolean;
|
|
13
|
-
}
|
|
14
|
-
/** Get form is valid as an observable. */
|
|
15
|
-
export declare function canExecuteFromNgForm(form: AbstractControl | AbstractControlDirective, options?: CanExecuteFormOptions): Observable<boolean>;
|
package/config.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { InjectionToken } from "@angular/core";
|
|
2
|
-
export interface CommandOptions {
|
|
3
|
-
/**
|
|
4
|
-
* Css Class which gets added/removed on the Command element's host while Command `isExecuting$`.
|
|
5
|
-
*/
|
|
6
|
-
executingCssClass: string;
|
|
7
|
-
/** Determines whether the disabled will be handled by the directive or not.
|
|
8
|
-
* Disable handled by directive's doesn't always play nice when used with other component/pipe/directive and they also handle disabled.
|
|
9
|
-
* This disables the handling manually and need to pass explicitly `[disabled]="!saveCmd.canExecute"`.
|
|
10
|
-
*/
|
|
11
|
-
handleDisabled: boolean;
|
|
12
|
-
/** Determine whether to set a `delay(1)` when setting the disabled. Which might be needed when working with external
|
|
13
|
-
* components/directives (such as material button)
|
|
14
|
-
*/
|
|
15
|
-
hasDisabledDelay: boolean;
|
|
16
|
-
}
|
|
17
|
-
export declare const COMMAND_DEFAULT_CONFIG: Readonly<CommandOptions>;
|
|
18
|
-
export declare const COMMAND_CONFIG: InjectionToken<CommandOptions>;
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { Directive, Input } from "@angular/core";
|
|
2
|
-
import { isCommandCreator } from "./command.util";
|
|
3
|
-
import { Command } from "./command";
|
|
4
|
-
import * as i0 from "@angular/core";
|
|
5
|
-
const NAME_CAMEL = "ssvCommandRef";
|
|
6
|
-
/**
|
|
7
|
-
* Command creator ref, directive which allows creating Command in the template
|
|
8
|
-
* and associate it to a command (in order to share executions).
|
|
9
|
-
* @example
|
|
10
|
-
* ### Most common usage
|
|
11
|
-
* ```html
|
|
12
|
-
* <div #actionCmd="ssvCommandRef" [ssvCommandRef]="{host: this, execute: removeHero$, canExecute: isValid$}">
|
|
13
|
-
* <button [ssvCommand]="actionCmd.command" [ssvCommandParams]="hero">
|
|
14
|
-
* Remove
|
|
15
|
-
* </button>
|
|
16
|
-
* <button [ssvCommand]="actionCmd.command" [ssvCommandParams]="hero">
|
|
17
|
-
* Remove
|
|
18
|
-
* </button>
|
|
19
|
-
* </div>
|
|
20
|
-
* ```
|
|
21
|
-
*
|
|
22
|
-
*/
|
|
23
|
-
export class CommandRefDirective {
|
|
24
|
-
get command() { return this._command; }
|
|
25
|
-
ngOnInit() {
|
|
26
|
-
if (isCommandCreator(this.commandCreator)) {
|
|
27
|
-
const isAsync = this.commandCreator.isAsync || this.commandCreator.isAsync === undefined;
|
|
28
|
-
const execFn = this.commandCreator.execute.bind(this.commandCreator.host);
|
|
29
|
-
this._command = new Command(execFn, this.commandCreator.canExecute, isAsync);
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
throw new Error(`${NAME_CAMEL}: [${NAME_CAMEL}] is not defined properly!`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
ngOnDestroy() {
|
|
36
|
-
// console.log("[commandRef::destroy]");
|
|
37
|
-
if (this._command) {
|
|
38
|
-
this._command.destroy();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
CommandRefDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: CommandRefDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
43
|
-
CommandRefDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.9", type: CommandRefDirective, selector: "[ssvCommandRef]", inputs: { commandCreator: ["ssvCommandRef", "commandCreator"] }, exportAs: ["ssvCommandRef"], ngImport: i0 });
|
|
44
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: CommandRefDirective, decorators: [{
|
|
45
|
-
type: Directive,
|
|
46
|
-
args: [{
|
|
47
|
-
selector: `[${NAME_CAMEL}]`,
|
|
48
|
-
exportAs: NAME_CAMEL
|
|
49
|
-
}]
|
|
50
|
-
}], propDecorators: { commandCreator: [{
|
|
51
|
-
type: Input,
|
|
52
|
-
args: [NAME_CAMEL]
|
|
53
|
-
}] } });
|
|
54
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29tbWFuZC1yZWYuZGlyZWN0aXZlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2NvbW1hbmQtcmVmLmRpcmVjdGl2ZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEVBQUUsU0FBUyxFQUFxQixLQUFLLEVBQUUsTUFBTSxlQUFlLENBQUM7QUFHcEUsT0FBTyxFQUFFLGdCQUFnQixFQUFFLE1BQU0sZ0JBQWdCLENBQUM7QUFDbEQsT0FBTyxFQUFFLE9BQU8sRUFBRS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