@ssv/ngx.command 3.0.0-dev.1 → 3.0.0-dev.1-dev.11
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 -43
- package/jest.config.ts +21 -21
- package/ng-package.json +7 -7
- package/package.json +4 -4
- package/project.json +36 -36
- package/src/command-ref.directive.ts +57 -57
- package/src/command.directive.ts +191 -192
- package/src/command.directive.xspec.ts +105 -105
- package/src/command.model.ts +36 -36
- package/src/command.options.ts +45 -45
- package/src/command.spec.ts +215 -215
- package/src/command.ts +170 -170
- package/src/command.util.ts +50 -50
- package/src/index.ts +8 -8
- package/src/module.ts +17 -17
- package/src/test-setup.ts +8 -8
- package/src/version.ts +1 -1
- package/tsconfig.json +28 -28
- package/tsconfig.lib.json +17 -17
- package/tsconfig.lib.prod.json +9 -9
- package/tsconfig.spec.json +16 -16
|
@@ -1,105 +1,105 @@
|
|
|
1
|
-
// import {Observable} from "rxjs/Observable";
|
|
2
|
-
// import {inject, addProviders, async} from "@angular/core/testing";
|
|
3
|
-
// import {TestComponentBuilder, ComponentFixture} from "@angular/compiler/testing";
|
|
4
|
-
// import {Component, provide} from "@angular/core";
|
|
5
|
-
|
|
6
|
-
// import {Command, ICommand, CommandDirective} from "./index";
|
|
7
|
-
|
|
8
|
-
// @Component({
|
|
9
|
-
// template: `<button class="btn" [ssvCommand]="saveCmd" >Save</button>`,
|
|
10
|
-
// directives: [
|
|
11
|
-
// CommandDirective
|
|
12
|
-
// ]
|
|
13
|
-
// })
|
|
14
|
-
// class TestContainer {
|
|
15
|
-
// saveCmd = new Command(() => Observable.of("yey").delay(2000), null, true);
|
|
16
|
-
// }
|
|
17
|
-
|
|
18
|
-
// @Component({
|
|
19
|
-
// template: `<button class="btn" [ssvCommand]="emptyCmd" >Save</button>`,
|
|
20
|
-
// directives: [
|
|
21
|
-
// CommandDirective
|
|
22
|
-
// ]
|
|
23
|
-
// })
|
|
24
|
-
// class NullCommandTestContainer {
|
|
25
|
-
|
|
26
|
-
// }
|
|
27
|
-
|
|
28
|
-
// describe("CommandDirectiveSpecs", () => {
|
|
29
|
-
|
|
30
|
-
// let testComponentBuilder: TestComponentBuilder;
|
|
31
|
-
|
|
32
|
-
// beforeEach(inject([
|
|
33
|
-
// TestComponentBuilder
|
|
34
|
-
// ], (
|
|
35
|
-
// _testComponentBuilder: TestComponentBuilder
|
|
36
|
-
// ) => {
|
|
37
|
-
// testComponentBuilder = _testComponentBuilder;
|
|
38
|
-
// })
|
|
39
|
-
// );
|
|
40
|
-
|
|
41
|
-
// describe("given an undefined command", () => {
|
|
42
|
-
// xit("should throw error", async(() => {
|
|
43
|
-
// testComponentBuilder
|
|
44
|
-
// .createAsync(NullCommandTestContainer)
|
|
45
|
-
// .then((fixture: ComponentFixture<NullCommandTestContainer>) => {
|
|
46
|
-
// expect(() => {
|
|
47
|
-
// fixture.detectChanges();
|
|
48
|
-
// }).toThrowError("[commandDirective] command should be defined!");
|
|
49
|
-
// });
|
|
50
|
-
|
|
51
|
-
// }));
|
|
52
|
-
// });
|
|
53
|
-
|
|
54
|
-
// describe("given command isExecuting is set to true", () => {
|
|
55
|
-
// xit("should have element disabled", async(() => {
|
|
56
|
-
// testComponentBuilder
|
|
57
|
-
// .createAsync(TestContainer)
|
|
58
|
-
// .then((fixture: ComponentFixture<TestContainer>) => {
|
|
59
|
-
// fixture.detectChanges();
|
|
60
|
-
// let container = fixture.componentInstance as TestContainer;
|
|
61
|
-
// let element = fixture.debugElement.nativeElement.querySelector("button");
|
|
62
|
-
// element.click();
|
|
63
|
-
// fixture.detectChanges();
|
|
64
|
-
// expect(element).toBeDisabled();
|
|
65
|
-
// });
|
|
66
|
-
// }));
|
|
67
|
-
|
|
68
|
-
// xit("should have executingCssClass added", () => {
|
|
69
|
-
|
|
70
|
-
// });
|
|
71
|
-
|
|
72
|
-
// xdescribe("when isExecuting has been finished", () => {
|
|
73
|
-
// xit("should have element enabled", () => {
|
|
74
|
-
|
|
75
|
-
// });
|
|
76
|
-
|
|
77
|
-
// xit("should have executingCssClass removed", () => {
|
|
78
|
-
|
|
79
|
-
// });
|
|
80
|
-
// });
|
|
81
|
-
// });
|
|
82
|
-
|
|
83
|
-
// xdescribe("given command canExecute is set to true", () => {
|
|
84
|
-
// xit("should have element enabled", () => {
|
|
85
|
-
|
|
86
|
-
// });
|
|
87
|
-
// });
|
|
88
|
-
|
|
89
|
-
// xdescribe("given command canExecute is set to false", () => {
|
|
90
|
-
// xit("should have element disabled", () => {
|
|
91
|
-
|
|
92
|
-
// });
|
|
93
|
-
// });
|
|
94
|
-
|
|
95
|
-
// xdescribe("given commandOptions are provided", () => {
|
|
96
|
-
// xdescribe("when isExecuting is set true", () => {
|
|
97
|
-
// xit("should have executingCssClass added with the provided option", () => {
|
|
98
|
-
|
|
99
|
-
// });
|
|
100
|
-
// });
|
|
101
|
-
|
|
102
|
-
// });
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
// });
|
|
1
|
+
// import {Observable} from "rxjs/Observable";
|
|
2
|
+
// import {inject, addProviders, async} from "@angular/core/testing";
|
|
3
|
+
// import {TestComponentBuilder, ComponentFixture} from "@angular/compiler/testing";
|
|
4
|
+
// import {Component, provide} from "@angular/core";
|
|
5
|
+
|
|
6
|
+
// import {Command, ICommand, CommandDirective} from "./index";
|
|
7
|
+
|
|
8
|
+
// @Component({
|
|
9
|
+
// template: `<button class="btn" [ssvCommand]="saveCmd" >Save</button>`,
|
|
10
|
+
// directives: [
|
|
11
|
+
// CommandDirective
|
|
12
|
+
// ]
|
|
13
|
+
// })
|
|
14
|
+
// class TestContainer {
|
|
15
|
+
// saveCmd = new Command(() => Observable.of("yey").delay(2000), null, true);
|
|
16
|
+
// }
|
|
17
|
+
|
|
18
|
+
// @Component({
|
|
19
|
+
// template: `<button class="btn" [ssvCommand]="emptyCmd" >Save</button>`,
|
|
20
|
+
// directives: [
|
|
21
|
+
// CommandDirective
|
|
22
|
+
// ]
|
|
23
|
+
// })
|
|
24
|
+
// class NullCommandTestContainer {
|
|
25
|
+
|
|
26
|
+
// }
|
|
27
|
+
|
|
28
|
+
// describe("CommandDirectiveSpecs", () => {
|
|
29
|
+
|
|
30
|
+
// let testComponentBuilder: TestComponentBuilder;
|
|
31
|
+
|
|
32
|
+
// beforeEach(inject([
|
|
33
|
+
// TestComponentBuilder
|
|
34
|
+
// ], (
|
|
35
|
+
// _testComponentBuilder: TestComponentBuilder
|
|
36
|
+
// ) => {
|
|
37
|
+
// testComponentBuilder = _testComponentBuilder;
|
|
38
|
+
// })
|
|
39
|
+
// );
|
|
40
|
+
|
|
41
|
+
// describe("given an undefined command", () => {
|
|
42
|
+
// xit("should throw error", async(() => {
|
|
43
|
+
// testComponentBuilder
|
|
44
|
+
// .createAsync(NullCommandTestContainer)
|
|
45
|
+
// .then((fixture: ComponentFixture<NullCommandTestContainer>) => {
|
|
46
|
+
// expect(() => {
|
|
47
|
+
// fixture.detectChanges();
|
|
48
|
+
// }).toThrowError("[commandDirective] command should be defined!");
|
|
49
|
+
// });
|
|
50
|
+
|
|
51
|
+
// }));
|
|
52
|
+
// });
|
|
53
|
+
|
|
54
|
+
// describe("given command isExecuting is set to true", () => {
|
|
55
|
+
// xit("should have element disabled", async(() => {
|
|
56
|
+
// testComponentBuilder
|
|
57
|
+
// .createAsync(TestContainer)
|
|
58
|
+
// .then((fixture: ComponentFixture<TestContainer>) => {
|
|
59
|
+
// fixture.detectChanges();
|
|
60
|
+
// let container = fixture.componentInstance as TestContainer;
|
|
61
|
+
// let element = fixture.debugElement.nativeElement.querySelector("button");
|
|
62
|
+
// element.click();
|
|
63
|
+
// fixture.detectChanges();
|
|
64
|
+
// expect(element).toBeDisabled();
|
|
65
|
+
// });
|
|
66
|
+
// }));
|
|
67
|
+
|
|
68
|
+
// xit("should have executingCssClass added", () => {
|
|
69
|
+
|
|
70
|
+
// });
|
|
71
|
+
|
|
72
|
+
// xdescribe("when isExecuting has been finished", () => {
|
|
73
|
+
// xit("should have element enabled", () => {
|
|
74
|
+
|
|
75
|
+
// });
|
|
76
|
+
|
|
77
|
+
// xit("should have executingCssClass removed", () => {
|
|
78
|
+
|
|
79
|
+
// });
|
|
80
|
+
// });
|
|
81
|
+
// });
|
|
82
|
+
|
|
83
|
+
// xdescribe("given command canExecute is set to true", () => {
|
|
84
|
+
// xit("should have element enabled", () => {
|
|
85
|
+
|
|
86
|
+
// });
|
|
87
|
+
// });
|
|
88
|
+
|
|
89
|
+
// xdescribe("given command canExecute is set to false", () => {
|
|
90
|
+
// xit("should have element disabled", () => {
|
|
91
|
+
|
|
92
|
+
// });
|
|
93
|
+
// });
|
|
94
|
+
|
|
95
|
+
// xdescribe("given commandOptions are provided", () => {
|
|
96
|
+
// xdescribe("when isExecuting is set true", () => {
|
|
97
|
+
// xit("should have executingCssClass added with the provided option", () => {
|
|
98
|
+
|
|
99
|
+
// });
|
|
100
|
+
// });
|
|
101
|
+
|
|
102
|
+
// });
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
// });
|
package/src/command.model.ts
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import { Observable } from "rxjs";
|
|
2
|
-
|
|
3
|
-
export interface ICommand {
|
|
4
|
-
/** Determines whether the command is currently executing, as a snapshot value. */
|
|
5
|
-
readonly isExecuting: boolean;
|
|
6
|
-
/** Determines whether the command is currently executing, as an observable. */
|
|
7
|
-
readonly isExecuting$: Observable<boolean>;
|
|
8
|
-
/** Determines whether the command can execute or not, as a snapshot value. */
|
|
9
|
-
readonly canExecute: boolean;
|
|
10
|
-
/** Determines whether the command can execute or not, as an observable. */
|
|
11
|
-
readonly canExecute$: Observable<boolean>;
|
|
12
|
-
|
|
13
|
-
/** Determines whether to auto destroy when having 0 subscribers (defaults to `true`). */
|
|
14
|
-
autoDestroy: boolean;
|
|
15
|
-
|
|
16
|
-
/** Execute function to invoke. */
|
|
17
|
-
execute(...args: unknown[]): void;
|
|
18
|
-
|
|
19
|
-
/** Disposes all resources held by subscriptions. */
|
|
20
|
-
destroy(): void;
|
|
21
|
-
|
|
22
|
-
/** Subscribe listener, in order to handle auto disposing. */
|
|
23
|
-
subscribe(): void;
|
|
24
|
-
|
|
25
|
-
/** Unsubscribe listener, in order to handle auto disposing. */
|
|
26
|
-
unsubscribe(): void;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface CommandCreator {
|
|
30
|
-
execute: (...args: unknown[]) => Observable<unknown> | Promise<unknown> | void;
|
|
31
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
32
|
-
canExecute?: Observable<boolean> | Function;
|
|
33
|
-
params?: unknown | unknown[];
|
|
34
|
-
isAsync?: boolean;
|
|
35
|
-
host: unknown;
|
|
36
|
-
}
|
|
1
|
+
import { Observable } from "rxjs";
|
|
2
|
+
|
|
3
|
+
export interface ICommand {
|
|
4
|
+
/** Determines whether the command is currently executing, as a snapshot value. */
|
|
5
|
+
readonly isExecuting: boolean;
|
|
6
|
+
/** Determines whether the command is currently executing, as an observable. */
|
|
7
|
+
readonly isExecuting$: Observable<boolean>;
|
|
8
|
+
/** Determines whether the command can execute or not, as a snapshot value. */
|
|
9
|
+
readonly canExecute: boolean;
|
|
10
|
+
/** Determines whether the command can execute or not, as an observable. */
|
|
11
|
+
readonly canExecute$: Observable<boolean>;
|
|
12
|
+
|
|
13
|
+
/** Determines whether to auto destroy when having 0 subscribers (defaults to `true`). */
|
|
14
|
+
autoDestroy: boolean;
|
|
15
|
+
|
|
16
|
+
/** Execute function to invoke. */
|
|
17
|
+
execute(...args: unknown[]): void;
|
|
18
|
+
|
|
19
|
+
/** Disposes all resources held by subscriptions. */
|
|
20
|
+
destroy(): void;
|
|
21
|
+
|
|
22
|
+
/** Subscribe listener, in order to handle auto disposing. */
|
|
23
|
+
subscribe(): void;
|
|
24
|
+
|
|
25
|
+
/** Unsubscribe listener, in order to handle auto disposing. */
|
|
26
|
+
unsubscribe(): void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface CommandCreator {
|
|
30
|
+
execute: (...args: unknown[]) => Observable<unknown> | Promise<unknown> | void;
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
32
|
+
canExecute?: Observable<boolean> | Function;
|
|
33
|
+
params?: unknown | unknown[];
|
|
34
|
+
isAsync?: boolean;
|
|
35
|
+
host: unknown;
|
|
36
|
+
}
|
package/src/command.options.ts
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import { EnvironmentProviders, InjectionToken, makeEnvironmentProviders } from "@angular/core";
|
|
2
|
-
|
|
3
|
-
export interface CommandOptions {
|
|
4
|
-
/**
|
|
5
|
-
* Css Class which gets added/removed on the Command element's host while Command `isExecuting$`.
|
|
6
|
-
*/
|
|
7
|
-
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;
|
|
14
|
-
|
|
15
|
-
/** Determine whether to set a `delay(1)` when setting the disabled. Which might be needed when working with external
|
|
16
|
-
* components/directives (such as material button)
|
|
17
|
-
*/
|
|
18
|
-
hasDisabledDelay: boolean;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const DEFAULT_OPTIONS = Object.freeze<CommandOptions>({
|
|
22
|
-
executingCssClass: "executing",
|
|
23
|
-
handleDisabled: true,
|
|
24
|
-
hasDisabledDelay: false,
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
export const COMMAND_OPTIONS = new InjectionToken<CommandOptions>("SSV_COMMAND_OPTIONS", {
|
|
28
|
-
factory: () => DEFAULT_OPTIONS,
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
export function provideSsvCommandOptions(options: CommandOptions | (() => CommandOptions)): EnvironmentProviders {
|
|
32
|
-
let opts = typeof options === "function" ? options() : options;
|
|
33
|
-
opts = opts
|
|
34
|
-
? {
|
|
35
|
-
...DEFAULT_OPTIONS,
|
|
36
|
-
...opts,
|
|
37
|
-
}
|
|
38
|
-
: DEFAULT_OPTIONS;
|
|
39
|
-
return makeEnvironmentProviders([
|
|
40
|
-
{
|
|
41
|
-
provide: DEFAULT_OPTIONS,
|
|
42
|
-
useValue: opts,
|
|
43
|
-
},
|
|
44
|
-
]);
|
|
45
|
-
}
|
|
1
|
+
import { EnvironmentProviders, InjectionToken, makeEnvironmentProviders } from "@angular/core";
|
|
2
|
+
|
|
3
|
+
export interface CommandOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Css Class which gets added/removed on the Command element's host while Command `isExecuting$`.
|
|
6
|
+
*/
|
|
7
|
+
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;
|
|
14
|
+
|
|
15
|
+
/** Determine whether to set a `delay(1)` when setting the disabled. Which might be needed when working with external
|
|
16
|
+
* components/directives (such as material button)
|
|
17
|
+
*/
|
|
18
|
+
hasDisabledDelay: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const DEFAULT_OPTIONS = Object.freeze<CommandOptions>({
|
|
22
|
+
executingCssClass: "executing",
|
|
23
|
+
handleDisabled: true,
|
|
24
|
+
hasDisabledDelay: false,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export const COMMAND_OPTIONS = new InjectionToken<CommandOptions>("SSV_COMMAND_OPTIONS", {
|
|
28
|
+
factory: () => DEFAULT_OPTIONS,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export function provideSsvCommandOptions(options: CommandOptions | (() => CommandOptions)): EnvironmentProviders {
|
|
32
|
+
let opts = typeof options === "function" ? options() : options;
|
|
33
|
+
opts = opts
|
|
34
|
+
? {
|
|
35
|
+
...DEFAULT_OPTIONS,
|
|
36
|
+
...opts,
|
|
37
|
+
}
|
|
38
|
+
: DEFAULT_OPTIONS;
|
|
39
|
+
return makeEnvironmentProviders([
|
|
40
|
+
{
|
|
41
|
+
provide: DEFAULT_OPTIONS,
|
|
42
|
+
useValue: opts,
|
|
43
|
+
},
|
|
44
|
+
]);
|
|
45
|
+
}
|