@ssv/ngx.command 3.0.0-dev.36 → 3.0.0-dev.38
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/command-ref.directive.d.ts +29 -0
- package/command.d.ts +59 -0
- package/command.directive.d.ts +24 -0
- package/command.model.d.ts +28 -0
- package/command.module.d.ts +8 -0
- package/command.options.d.ts +18 -0
- package/command.util.d.ts +15 -0
- package/esm2022/command-ref.directive.mjs +57 -0
- package/esm2022/command.directive.mjs +165 -0
- package/esm2022/command.mjs +149 -0
- package/esm2022/command.model.mjs +2 -0
- package/esm2022/command.module.mjs +23 -0
- package/esm2022/command.options.mjs +27 -0
- package/esm2022/command.util.mjs +28 -0
- package/esm2022/index.mjs +8 -0
- package/esm2022/ssv-ngx.command.mjs +5 -0
- package/esm2022/version.mjs +2 -0
- package/fesm2022/ssv-ngx.command.mjs +442 -0
- package/fesm2022/ssv-ngx.command.mjs.map +1 -0
- package/package.json +18 -3
- package/version.d.ts +1 -0
- package/eslint.config.js +0 -43
- package/index.ts +0 -1
- package/jest.config.ts +0 -21
- package/ng-package.json +0 -7
- package/project.json +0 -36
- package/src/command-ref.directive.ts +0 -57
- package/src/command.directive.ts +0 -190
- package/src/command.directive.xspec.ts +0 -105
- package/src/command.model.ts +0 -39
- package/src/command.module.ts +0 -17
- package/src/command.options.ts +0 -49
- package/src/command.spec.ts +0 -215
- package/src/command.ts +0 -208
- package/src/command.util.ts +0 -49
- package/src/test-setup.ts +0 -8
- package/src/version.ts +0 -1
- package/tsconfig.json +0 -28
- package/tsconfig.lib.json +0 -17
- package/tsconfig.lib.prod.json +0 -9
- package/tsconfig.spec.json +0 -16
- /package/{src/index.ts → index.d.ts} +0 -0
package/src/command.spec.ts
DELETED
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import { BehaviorSubject, EMPTY } from "rxjs";
|
|
2
|
-
|
|
3
|
-
import { Command } from "./command";
|
|
4
|
-
|
|
5
|
-
describe("CommandSpecs", () => {
|
|
6
|
-
let SUT: Command;
|
|
7
|
-
let executeFn: jest.Mock<void, unknown[], unknown> ;
|
|
8
|
-
// let executeSpyFn: jest.SpyInstance<void, unknown[], unknown>;
|
|
9
|
-
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
executeFn = jest.fn();
|
|
12
|
-
// executeSpyFn = executeFn;
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
describe("given a command without canExecute$ param", () => {
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
SUT = new Command(executeFn);
|
|
18
|
-
// executeSpyFn = jest.spyOn(SUT, "execute");
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
describe("when command is initialized", () => {
|
|
22
|
-
it("should have canExecute set to true", () => {
|
|
23
|
-
expect(SUT.canExecute).toBe(true);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("should have canExecute$ set to true", done => {
|
|
27
|
-
SUT.canExecute$.subscribe(x => {
|
|
28
|
-
expect(x).toBe(true);
|
|
29
|
-
done();
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
describe("when execute is invoked", () => {
|
|
35
|
-
beforeEach(() => {
|
|
36
|
-
SUT.execute();
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("should have isExecuting set to false after execute finishes", () => {
|
|
40
|
-
expect(SUT.isExecuting).toBe(false);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("should have canExecute set to true after execute finishes", () => {
|
|
44
|
-
expect(SUT.canExecute).toBe(true);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it("should invoke execute function", () => {
|
|
48
|
-
expect(executeFn).toHaveBeenCalledTimes(1);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
describe("given execute is invoked", () => {
|
|
54
|
-
describe("when canExecute is true", () => {
|
|
55
|
-
beforeEach(() => {
|
|
56
|
-
const isInitialValid = true;
|
|
57
|
-
SUT = new Command(executeFn, new BehaviorSubject<boolean>(isInitialValid));
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("should invoke execute function passed", () => {
|
|
61
|
-
SUT.execute();
|
|
62
|
-
expect(executeFn).toHaveBeenCalledTimes(1);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
describe("when observable completes", () => {
|
|
67
|
-
beforeEach(() => {
|
|
68
|
-
const isInitialValid = true;
|
|
69
|
-
executeFn = jest.fn().mockImplementation(() => EMPTY);
|
|
70
|
-
SUT = new Command(executeFn, new BehaviorSubject<boolean>(isInitialValid));
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("should invoke multiple times", () => {
|
|
74
|
-
SUT.execute();
|
|
75
|
-
SUT.execute();
|
|
76
|
-
expect(SUT.isExecuting).toBeFalsy();
|
|
77
|
-
expect(executeFn).toHaveBeenCalledTimes(2);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
describe("when an error is thrown", () => {
|
|
82
|
-
const _errorFn = console.error;
|
|
83
|
-
beforeAll(() => {
|
|
84
|
-
console.error = jest.fn();
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
beforeEach(() => {
|
|
88
|
-
const isInitialValid = true;
|
|
89
|
-
executeFn = jest.fn().mockImplementation(() => {
|
|
90
|
-
throw new Error("Execution failed!");
|
|
91
|
-
});
|
|
92
|
-
SUT = new Command(executeFn, new BehaviorSubject<boolean>(isInitialValid));
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it("should invoke multiple times", () => {
|
|
96
|
-
SUT.execute();
|
|
97
|
-
SUT.execute();
|
|
98
|
-
expect(SUT.isExecuting).toBeFalsy();
|
|
99
|
-
expect(executeFn).toHaveBeenCalledTimes(2);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
afterAll(() => {
|
|
103
|
-
console.error = _errorFn;
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
describe("when args are passed", () => {
|
|
108
|
-
beforeEach(() => {
|
|
109
|
-
const isInitialValid = true;
|
|
110
|
-
SUT = new Command(executeFn, new BehaviorSubject<boolean>(isInitialValid));
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it("and has 1 param should receive 1 arg", () => {
|
|
114
|
-
const args = { name: "rexxar" };
|
|
115
|
-
SUT.execute(args);
|
|
116
|
-
expect(executeFn).toHaveBeenCalledTimes(1);
|
|
117
|
-
expect(executeFn).toHaveBeenCalledWith(args);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it("and is array param should not spread", () => {
|
|
121
|
-
const hero = { name: "rexxar" };
|
|
122
|
-
const args = [hero, "yello"];
|
|
123
|
-
SUT.execute(args);
|
|
124
|
-
expect(executeFn).toHaveBeenCalledTimes(1);
|
|
125
|
-
expect(executeFn).toHaveBeenCalledWith([hero, "yello"]);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it("and multi args are pass should receive all", () => {
|
|
129
|
-
const hero = { name: "rexxar" };
|
|
130
|
-
SUT.execute(hero, "yello");
|
|
131
|
-
expect(executeFn).toHaveBeenCalledTimes(1);
|
|
132
|
-
expect(executeFn).toHaveBeenCalledWith(hero, "yello");
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
describe("when canExecute is false", () => {
|
|
137
|
-
beforeEach(() => {
|
|
138
|
-
const isInitialValid = false;
|
|
139
|
-
SUT = new Command(executeFn, new BehaviorSubject<boolean>(isInitialValid));
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it("should not execute the provided execute function", () => {
|
|
143
|
-
SUT.execute();
|
|
144
|
-
expect(executeFn).not.toHaveBeenCalled();
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
describe("given canExecute with an initial value of true", () => {
|
|
150
|
-
let canExecute$: BehaviorSubject<boolean>;
|
|
151
|
-
|
|
152
|
-
beforeEach(() => {
|
|
153
|
-
const isInitialValid = true;
|
|
154
|
-
canExecute$ = new BehaviorSubject<boolean>(isInitialValid);
|
|
155
|
-
SUT = new Command(executeFn, canExecute$);
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it("should have canExecute set to true", () => {
|
|
159
|
-
expect(SUT.canExecute).toBe(true);
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
it("should have canExecute$ set to true", done => {
|
|
163
|
-
SUT.canExecute$.subscribe(x => {
|
|
164
|
-
expect(x).toBe(true);
|
|
165
|
-
done();
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
describe("when the canExecute observable changes", () => {
|
|
170
|
-
beforeEach(() => {
|
|
171
|
-
canExecute$.next(false);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it("should update canExecute", () => {
|
|
175
|
-
expect(SUT.canExecute).toBe(false);
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
it("should update canExecute$", done => {
|
|
179
|
-
SUT.canExecute$.subscribe(x => {
|
|
180
|
-
expect(x).toBe(false);
|
|
181
|
-
done();
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
describe("given canExecute with an initial value of false", () => {
|
|
188
|
-
beforeEach(() => {
|
|
189
|
-
const isInitialValid = false;
|
|
190
|
-
SUT = new Command(executeFn, new BehaviorSubject<boolean>(isInitialValid));
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it("should have canExecute set to false", () => {
|
|
194
|
-
expect(SUT.canExecute).toBe(false);
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
it("should have canExecute$ set to false", done => {
|
|
198
|
-
SUT.canExecute$.subscribe(x => {
|
|
199
|
-
expect(x).toBe(false);
|
|
200
|
-
done();
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
describe("given destroy is invoked", () => {
|
|
206
|
-
beforeEach(() => {
|
|
207
|
-
const isInitialValid = false;
|
|
208
|
-
SUT = new Command(executeFn, new BehaviorSubject<boolean>(isInitialValid));
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
it("should destroy successfully", () => {
|
|
212
|
-
SUT.destroy();
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
});
|
package/src/command.ts
DELETED
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
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
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Command object used to encapsulate information which is needed to perform an action.
|
|
46
|
-
*/
|
|
47
|
-
export class Command implements ICommand {
|
|
48
|
-
|
|
49
|
-
/** Determines whether the command is currently executing, as a snapshot value. */
|
|
50
|
-
get isExecuting(): boolean {
|
|
51
|
-
return this._isExecuting;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/** Determines whether the command can execute or not, as a snapshot value. */
|
|
55
|
-
get canExecute(): boolean {
|
|
56
|
-
return this._canExecute;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/** Determines whether the command is currently executing, as an observable. */
|
|
60
|
-
get isExecuting$(): Observable<boolean> {
|
|
61
|
-
return this._isExecuting$.asObservable();
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** Determines whether to auto destroy when having 0 subscribers. */
|
|
65
|
-
autoDestroy = true;
|
|
66
|
-
|
|
67
|
-
/** Determines whether the command can execute or not, as an observable. */
|
|
68
|
-
readonly canExecute$: Observable<boolean>;
|
|
69
|
-
|
|
70
|
-
private _isExecuting$ = new BehaviorSubject<boolean>(false);
|
|
71
|
-
private _isExecuting = false;
|
|
72
|
-
private _canExecute = true;
|
|
73
|
-
private executionPipe$ = new Subject<unknown[] | undefined>();
|
|
74
|
-
private isExecuting$$ = Subscription.EMPTY;
|
|
75
|
-
private canExecute$$ = Subscription.EMPTY;
|
|
76
|
-
private executionPipe$$ = Subscription.EMPTY;
|
|
77
|
-
private subscribersCount = 0;
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Creates an instance of Command.
|
|
81
|
-
*
|
|
82
|
-
* @param execute Execute function to invoke - use `isAsync: true` when `Observable<any>`.
|
|
83
|
-
* @param canExecute Observable which determines whether it can execute or not.
|
|
84
|
-
* @param isAsync Indicates that the execute function is async e.g. Observable.
|
|
85
|
-
*/
|
|
86
|
-
constructor(
|
|
87
|
-
execute: ExecuteFn,
|
|
88
|
-
canExecute$?: CanExecute,
|
|
89
|
-
isAsync?: boolean,
|
|
90
|
-
) {
|
|
91
|
-
if (canExecute$) {
|
|
92
|
-
this.canExecute$ = combineLatest([
|
|
93
|
-
this._isExecuting$,
|
|
94
|
-
isSignal(canExecute$) ? toObservable(canExecute$) : canExecute$
|
|
95
|
-
]).pipe(
|
|
96
|
-
map(([isExecuting, canExecuteResult]) => {
|
|
97
|
-
// console.log("[command::combineLatest$] update!", { isExecuting, canExecuteResult });
|
|
98
|
-
this._isExecuting = isExecuting;
|
|
99
|
-
this._canExecute = !isExecuting && !!canExecuteResult;
|
|
100
|
-
return this._canExecute;
|
|
101
|
-
}),
|
|
102
|
-
);
|
|
103
|
-
this.canExecute$$ = this.canExecute$.subscribe();
|
|
104
|
-
} else {
|
|
105
|
-
this.canExecute$ = this._isExecuting$.pipe(
|
|
106
|
-
map(x => {
|
|
107
|
-
const canExecute = !x;
|
|
108
|
-
this._canExecute = canExecute;
|
|
109
|
-
return canExecute;
|
|
110
|
-
})
|
|
111
|
-
);
|
|
112
|
-
this.isExecuting$$ = this._isExecuting$
|
|
113
|
-
.pipe(tap(x => this._isExecuting = x))
|
|
114
|
-
.subscribe();
|
|
115
|
-
}
|
|
116
|
-
this.executionPipe$$ = this.buildExecutionPipe(execute, isAsync).subscribe();
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/** Execute function to invoke. */
|
|
120
|
-
execute(...args: unknown[]): void {
|
|
121
|
-
// console.warn("[command::execute]", args);
|
|
122
|
-
this.executionPipe$.next(args);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/** Disposes all resources held by subscriptions. */
|
|
126
|
-
destroy(): void {
|
|
127
|
-
// console.warn("[command::destroy]");
|
|
128
|
-
this.executionPipe$$.unsubscribe();
|
|
129
|
-
this.canExecute$$.unsubscribe();
|
|
130
|
-
this.isExecuting$$.unsubscribe();
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
subscribe(): void {
|
|
134
|
-
this.subscribersCount++;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
unsubscribe(): void {
|
|
138
|
-
this.subscribersCount--;
|
|
139
|
-
// console.log("[command::unsubscribe]", { autoDestroy: this.autoDestroy, subscribersCount: this.subscribersCount });
|
|
140
|
-
if (this.autoDestroy && this.subscribersCount <= 0) {
|
|
141
|
-
this.destroy();
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
private buildExecutionPipe(execute: (...args: unknown[]) => any, isAsync?: boolean): Observable<unknown> {
|
|
146
|
-
let pipe$ = this.executionPipe$.pipe(
|
|
147
|
-
// tap(x => console.warn(">>>> executionPipe", this._canExecute)),
|
|
148
|
-
filter(() => this._canExecute),
|
|
149
|
-
tap(() => {
|
|
150
|
-
// console.log("[command::executionPipe$] do#1 - set execute", { args: x });
|
|
151
|
-
this._isExecuting$.next(true);
|
|
152
|
-
})
|
|
153
|
-
);
|
|
154
|
-
|
|
155
|
-
const execFn = isAsync
|
|
156
|
-
? switchMap<unknown[] | undefined, any[]>(args => {
|
|
157
|
-
if (args) {
|
|
158
|
-
return execute(...args);
|
|
159
|
-
}
|
|
160
|
-
return execute();
|
|
161
|
-
})
|
|
162
|
-
: tap((args: unknown[] | undefined) => {
|
|
163
|
-
if (args) {
|
|
164
|
-
execute(...args);
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
execute();
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
pipe$ = pipe$.pipe(
|
|
171
|
-
switchMap(args => of(args).pipe(
|
|
172
|
-
execFn,
|
|
173
|
-
finalize(() => {
|
|
174
|
-
// console.log("[command::executionPipe$] finalize inner#1 - set idle");
|
|
175
|
-
this._isExecuting$.next(false);
|
|
176
|
-
}),
|
|
177
|
-
take(1),
|
|
178
|
-
catchError(error => {
|
|
179
|
-
console.error("Unhandled execute error", error);
|
|
180
|
-
return EMPTY;
|
|
181
|
-
}),
|
|
182
|
-
)),
|
|
183
|
-
tap(
|
|
184
|
-
() => {
|
|
185
|
-
// console.log("[command::executionPipe$] tap#2 - set idle");
|
|
186
|
-
this._isExecuting$.next(false);
|
|
187
|
-
},
|
|
188
|
-
)
|
|
189
|
-
);
|
|
190
|
-
return pipe$;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Async Command object used to encapsulate information which is needed to perform an action,
|
|
197
|
-
* which takes an execute function as Observable/Promise.
|
|
198
|
-
*/
|
|
199
|
-
export class CommandAsync extends Command {
|
|
200
|
-
|
|
201
|
-
constructor(
|
|
202
|
-
execute: ExecuteAsyncFn,
|
|
203
|
-
canExecute$?: CanExecute,
|
|
204
|
-
) {
|
|
205
|
-
super(execute, canExecute$, true);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
}
|
package/src/command.util.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { AbstractControl, AbstractControlDirective, FormControlStatus } from "@angular/forms";
|
|
2
|
-
import { Observable, of, map, distinctUntilChanged, startWith, delay } from "rxjs";
|
|
3
|
-
|
|
4
|
-
import { CommandCreator, ICommand } from "./command.model";
|
|
5
|
-
import { Command } from "./command";
|
|
6
|
-
|
|
7
|
-
/** Determines whether the arg object is of type `Command`. */
|
|
8
|
-
export function isCommand(arg: unknown): arg is ICommand {
|
|
9
|
-
return arg instanceof Command;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/** Determines whether the arg object is of type `CommandCreator`. */
|
|
13
|
-
export function isCommandCreator(arg: unknown): arg is CommandCreator {
|
|
14
|
-
if (arg instanceof Command) {
|
|
15
|
-
return false;
|
|
16
|
-
} else if (isAssumedType<CommandCreator>(arg) && arg.execute && arg.host) {
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface CanExecuteFormOptions {
|
|
23
|
-
/** Determines whether to check for validity. (defaults: true) */
|
|
24
|
-
validity?: boolean;
|
|
25
|
-
|
|
26
|
-
/** Determines whether to check whether UI has been touched. (defaults: true) */
|
|
27
|
-
dirty?: boolean;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** Get form is valid as an observable. */
|
|
31
|
-
export function canExecuteFromNgForm(
|
|
32
|
-
form: AbstractControl | AbstractControlDirective,
|
|
33
|
-
options?: CanExecuteFormOptions
|
|
34
|
-
): Observable<boolean> {
|
|
35
|
-
const opts: CanExecuteFormOptions = { validity: true, dirty: true, ...options };
|
|
36
|
-
|
|
37
|
-
return form.statusChanges
|
|
38
|
-
? (form.statusChanges as Observable<FormControlStatus>).pipe( // todo: remove cast when working correctly
|
|
39
|
-
delay(0),
|
|
40
|
-
startWith(form.valid),
|
|
41
|
-
map(() => !!(!opts.validity || form.valid) && !!(!opts.dirty || form.dirty)),
|
|
42
|
-
distinctUntilChanged(),
|
|
43
|
-
)
|
|
44
|
-
: of(true);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function isAssumedType<T = Record<string, unknown>>(x: unknown): x is Partial<T> {
|
|
48
|
-
return x !== null && typeof x === "object";
|
|
49
|
-
}
|
package/src/test-setup.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
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
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const VERSION = "3.0.0-dev.36";
|
package/tsconfig.json
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
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
|
-
}
|
package/tsconfig.lib.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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
|
-
}
|
package/tsconfig.lib.prod.json
DELETED
package/tsconfig.spec.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
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
|
-
}
|
|
File without changes
|