@ssv/ngx.command 3.0.0-dev.21 → 3.0.0-dev.25
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/index.ts +1 -0
- package/package.json +1 -1
- package/src/command.directive.ts +4 -5
- package/src/command.options.ts +1 -1
- package/src/command.ts +46 -8
- package/src/command.util.ts +1 -2
- package/src/index.ts +7 -7
- package/src/version.ts +1 -1
- /package/src/{module.ts → command.module.ts} +0 -0
package/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ssv/ngx.command",
|
|
3
|
-
"version": "3.0.0-dev.
|
|
3
|
+
"version": "3.0.0-dev.25",
|
|
4
4
|
"versionSuffix": "",
|
|
5
5
|
"description": "Command pattern implementation for angular. Command used to encapsulate information which is needed to perform an action.",
|
|
6
6
|
"keywords": [
|
package/src/command.directive.ts
CHANGED
|
@@ -9,13 +9,12 @@ import {
|
|
|
9
9
|
ChangeDetectorRef,
|
|
10
10
|
inject,
|
|
11
11
|
} from "@angular/core";
|
|
12
|
-
import { Subject } from "rxjs";
|
|
13
|
-
import { tap, delay, takeUntil } from "rxjs/operators";
|
|
12
|
+
import { Subject, tap, delay, takeUntil } from "rxjs";
|
|
14
13
|
|
|
15
|
-
import { CommandOptions, COMMAND_OPTIONS } from "./command.options";
|
|
14
|
+
import { type CommandOptions, COMMAND_OPTIONS } from "./command.options";
|
|
16
15
|
import { Command } from "./command";
|
|
17
16
|
import { isCommand, isCommandCreator } from "./command.util";
|
|
18
|
-
import { CommandCreator, ICommand } from "./command.model";
|
|
17
|
+
import { CommandCreator, type ICommand } from "./command.model";
|
|
19
18
|
|
|
20
19
|
/**
|
|
21
20
|
* Controls the state of a component in sync with `Command`.
|
|
@@ -100,7 +99,7 @@ export class CommandDirective implements OnInit, OnDestroy {
|
|
|
100
99
|
private _destroy$ = new Subject<void>();
|
|
101
100
|
|
|
102
101
|
ngOnInit(): void {
|
|
103
|
-
// console.log("[ssvCommand::init]", this.
|
|
102
|
+
// console.log("[ssvCommand::init]", this.globalOptions);
|
|
104
103
|
if (!this.commandOrCreator) {
|
|
105
104
|
throw new Error(`${NAME_CAMEL}: [${NAME_CAMEL}] should be defined!`);
|
|
106
105
|
} else if (isCommand(this.commandOrCreator)) {
|
package/src/command.options.ts
CHANGED
package/src/command.ts
CHANGED
|
@@ -1,7 +1,45 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import {
|
|
3
|
+
Observable, combineLatest, Subscription, Subject, BehaviorSubject, of, EMPTY,
|
|
4
|
+
tap, map, filter, switchMap, catchError, finalize, take,
|
|
5
|
+
} from "rxjs";
|
|
6
|
+
import type { ICommand } from "./command.model";
|
|
7
|
+
import { DestroyRef, inject, isSignal, type Signal } from "@angular/core";
|
|
8
|
+
import { toObservable } from "@angular/core/rxjs-interop";
|
|
9
|
+
|
|
10
|
+
export type ExecuteFn = (...args: any[]) => unknown;
|
|
11
|
+
export type ExecuteAsyncFn = (...args: any[]) => Observable<unknown> | Promise<unknown>;
|
|
12
|
+
export type CanExecute = Signal<boolean> | Observable<boolean>;
|
|
13
|
+
|
|
14
|
+
/** Creates an async {@link Command}. Must be used within an injection context.
|
|
15
|
+
* NOTE: this auto injects `DestroyRef` and handles auto destroy. {@link ICommand.autoDestroy} should not be used.
|
|
16
|
+
*/
|
|
17
|
+
export function createCommandAsync(
|
|
18
|
+
execute: ExecuteAsyncFn,
|
|
19
|
+
canExecute$?: CanExecute,
|
|
20
|
+
): Command {
|
|
21
|
+
return createCommand(execute, canExecute$, true);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Creates a {@link Command}. Must be used within an injection context.
|
|
25
|
+
* NOTE: this auto injects `DestroyRef` and handles auto destroy. {@link ICommand.autoDestroy} should not be used.
|
|
26
|
+
*/
|
|
27
|
+
export function createCommand(
|
|
28
|
+
execute: ExecuteFn,
|
|
29
|
+
canExecute$?: CanExecute,
|
|
30
|
+
isAsync?: boolean,
|
|
31
|
+
): Command {
|
|
32
|
+
const destroyRef = inject(DestroyRef);
|
|
33
|
+
|
|
34
|
+
const cmd = new Command(execute, canExecute$, isAsync);
|
|
35
|
+
cmd.autoDestroy = false;
|
|
36
|
+
|
|
37
|
+
destroyRef.onDestroy(() => {
|
|
38
|
+
// console.warn("[createCommandAsync::destroy]");
|
|
39
|
+
cmd.destroy();
|
|
40
|
+
});
|
|
41
|
+
return cmd;
|
|
42
|
+
}
|
|
5
43
|
|
|
6
44
|
/**
|
|
7
45
|
* Command object used to encapsulate information which is needed to perform an action.
|
|
@@ -46,14 +84,14 @@ export class Command implements ICommand {
|
|
|
46
84
|
* @param isAsync Indicates that the execute function is async e.g. Observable.
|
|
47
85
|
*/
|
|
48
86
|
constructor(
|
|
49
|
-
execute:
|
|
50
|
-
canExecute$?:
|
|
87
|
+
execute: ExecuteFn,
|
|
88
|
+
canExecute$?: CanExecute,
|
|
51
89
|
isAsync?: boolean,
|
|
52
90
|
) {
|
|
53
91
|
if (canExecute$) {
|
|
54
92
|
this.canExecute$ = combineLatest([
|
|
55
93
|
this._isExecuting$,
|
|
56
|
-
canExecute$
|
|
94
|
+
isSignal(canExecute$) ? toObservable(canExecute$) : canExecute$
|
|
57
95
|
]).pipe(
|
|
58
96
|
map(([isExecuting, canExecuteResult]) => {
|
|
59
97
|
// console.log("[command::combineLatest$] update!", { isExecuting, canExecuteResult });
|
|
@@ -161,8 +199,8 @@ export class Command implements ICommand {
|
|
|
161
199
|
export class CommandAsync extends Command {
|
|
162
200
|
|
|
163
201
|
constructor(
|
|
164
|
-
execute:
|
|
165
|
-
canExecute$?:
|
|
202
|
+
execute: ExecuteAsyncFn,
|
|
203
|
+
canExecute$?: CanExecute,
|
|
166
204
|
) {
|
|
167
205
|
super(execute, canExecute$, true);
|
|
168
206
|
}
|
package/src/command.util.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { AbstractControl, AbstractControlDirective, FormControlStatus } from "@angular/forms";
|
|
2
|
-
import { Observable, of } from "rxjs";
|
|
3
|
-
import { map, distinctUntilChanged, startWith, delay } from "rxjs/operators";
|
|
2
|
+
import { Observable, of, map, distinctUntilChanged, startWith, delay } from "rxjs";
|
|
4
3
|
|
|
5
4
|
import { CommandCreator, ICommand } from "./command.model";
|
|
6
5
|
import { Command } from "./command";
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
export { SsvCommandModule } from "./command.module";
|
|
2
|
+
export { provideSsvCommandOptions, COMMAND_OPTIONS, type CommandOptions } from "./command.options";
|
|
1
3
|
export * from "./command";
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export { CommandCreator, ICommand } from "./command.model";
|
|
6
|
-
export
|
|
7
|
-
export * from "./module";
|
|
8
|
-
export * from "./version";
|
|
4
|
+
export { CommandDirective } from "./command.directive";
|
|
5
|
+
export { CommandRefDirective } from "./command-ref.directive";
|
|
6
|
+
export { type CanExecuteFormOptions, isCommand, isCommandCreator, canExecuteFromNgForm } from "./command.util";
|
|
7
|
+
export type { CommandCreator, ICommand } from "./command.model";
|
|
8
|
+
export { VERSION } from "./version";
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "3.0.0-dev.
|
|
1
|
+
export const VERSION = "3.0.0-dev.25";
|
|
File without changes
|