@one-paragon/angular-utilities 1.2.18 → 1.3.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/action-state/action-state-spinner/action-state-spinner.component.d.ts +12 -0
- package/action-state/action-state-ui/action-state-ui.module.d.ts +7 -0
- package/{src/action-state/index.ts → action-state/index.d.ts} +4 -8
- package/action-state/ngrx-ext/ngrx-ext.module.d.ts +8 -0
- package/action-state/ngrx.d.ts +31 -0
- package/fesm2022/one-paragon-angular-utilities.mjs +5760 -0
- package/fesm2022/one-paragon-angular-utilities.mjs.map +1 -0
- package/http-request-state/HttpRequestStateFactory.d.ts +17 -0
- package/http-request-state/HttpRequestStateStore.d.ts +58 -0
- package/http-request-state/directives/HttpStateDirectiveBase.d.ts +14 -0
- package/http-request-state/directives/http-error-state-directive.d.ts +9 -0
- package/http-request-state/directives/http-inProgress-state-directive.d.ts +9 -0
- package/http-request-state/directives/http-notStarted-state-directive.d.ts +9 -0
- package/http-request-state/directives/http-success-state-directive.d.ts +16 -0
- package/{src/http-request-state/directives/index.ts → http-request-state/directives/index.d.ts} +5 -5
- package/http-request-state/directives/request-state-directive.d.ts +34 -0
- package/http-request-state/helpers.d.ts +9 -0
- package/http-request-state/http-request-state.d.ts +12 -0
- package/http-request-state/http-state-module.d.ts +11 -0
- package/{src/http-request-state/index.ts → http-request-state/index.d.ts} +6 -6
- package/http-request-state/rxjs/getRequestorBody.d.ts +3 -0
- package/http-request-state/rxjs/getRequestorState.d.ts +3 -0
- package/{src/http-request-state/rxjs/index.ts → http-request-state/rxjs/index.d.ts} +4 -4
- package/http-request-state/rxjs/tapError.d.ts +3 -0
- package/http-request-state/rxjs/tapSuccess.d.ts +3 -0
- package/http-request-state/types.d.ts +41 -0
- package/index.d.ts +5 -0
- package/ngrx/actionable-selector.d.ts +31 -0
- package/ngrx/index.d.ts +1 -0
- package/package.json +28 -16
- package/{src/public-api.ts → public-api.d.ts} +16 -35
- package/rxjs/defaultShareReplay.d.ts +2 -0
- package/{src/rxjs/index.ts → rxjs/index.d.ts} +5 -5
- package/rxjs/mapError.d.ts +2 -0
- package/rxjs/rxjs-operators.d.ts +13 -0
- package/rxjs/subjectifier.d.ts +8 -0
- package/rxjs/subscriber.directive.d.ts +14 -0
- package/table-builder/classes/DefaultSettings.d.ts +9 -0
- package/table-builder/classes/MatTableObservableDataSource.d.ts +9 -0
- package/table-builder/classes/TableBuilderConfig.d.ts +23 -0
- package/table-builder/classes/TableBuilderDataSource.d.ts +12 -0
- package/table-builder/classes/TableState.d.ts +66 -0
- package/table-builder/classes/data-store.d.ts +8 -0
- package/{src/table-builder/classes/display-col.ts → table-builder/classes/display-col.d.ts} +5 -5
- package/table-builder/classes/filter-info.d.ts +35 -0
- package/table-builder/classes/table-builder-general-settings.d.ts +85 -0
- package/table-builder/classes/table-builder.d.ts +18 -0
- package/table-builder/classes/table-store.d.ts +138 -0
- package/table-builder/components/array-column.component.d.ts +15 -0
- package/table-builder/components/column-builder/column-builder.component.d.ts +50 -0
- package/table-builder/components/column-builder/column-helpers.d.ts +36 -0
- package/table-builder/components/date-filter/date-filter.component.d.ts +37 -0
- package/table-builder/components/date-time-filter/date-time-filter.component.d.ts +37 -0
- package/table-builder/components/filter/filter.component.d.ts +46 -0
- package/table-builder/components/filter/in-list/in-list-filter.component.d.ts +24 -0
- package/table-builder/components/gen-col-displayer/gen-col-displayer.component.d.ts +17 -0
- package/table-builder/components/generic-table/generic-table.component.d.ts +84 -0
- package/table-builder/components/generic-table/paginator.component.d.ts +30 -0
- package/table-builder/components/group-by-list/group-by-list.component.d.ts +7 -0
- package/table-builder/components/header-menu/header-menu.component.d.ts +51 -0
- package/table-builder/components/in-filter/in-filter.component.d.ts +20 -0
- package/{src/table-builder/components/index.ts → table-builder/components/index.d.ts} +9 -9
- package/table-builder/components/initialization-component/initialization-component.d.ts +13 -0
- package/table-builder/components/link-column.component.d.ts +25 -0
- package/table-builder/components/number-filter/number-filter.component.d.ts +39 -0
- package/table-builder/components/profiles-menu/profiles-menu.component.d.ts +32 -0
- package/table-builder/components/scroll-strategy.d.ts +22 -0
- package/table-builder/components/sort-menu/sort-menu.component-store.d.ts +24 -0
- package/table-builder/components/sort-menu/sort-menu.component.d.ts +24 -0
- package/{src/table-builder/components/table-container/table-container-imports.ts → table-builder/components/table-container/table-container-imports.d.ts} +14 -32
- package/table-builder/components/table-container/table-container.d.ts +81 -0
- package/table-builder/components/table-container/table-container.helpers/data-state.helpers.d.ts +6 -0
- package/table-builder/components/table-container/table-container.helpers/filter-state.helpers.d.ts +17 -0
- package/table-builder/components/table-container/table-container.helpers/groupBy.helpers.d.ts +17 -0
- package/table-builder/components/table-container/table-container.helpers/sort-state.helpers.d.ts +8 -0
- package/table-builder/components/table-container/tableProps.d.ts +12 -0
- package/table-builder/components/table-container/virtual-scroll-container.d.ts +36 -0
- package/table-builder/components/table-container-filter/filter-list/filter-list.component.d.ts +15 -0
- package/table-builder/components/table-container-filter/gen-filter-displayer/gen-filter-displayer.component.d.ts +12 -0
- package/table-builder/components/table-container-filter/table-wrapper-filter-store.d.ts +14 -0
- package/table-builder/directives/custom-cell-directive.d.ts +33 -0
- package/{src/table-builder/directives/index.ts → table-builder/directives/index.d.ts} +5 -6
- package/table-builder/directives/multi-sort.directive.d.ts +10 -0
- package/table-builder/directives/resize-column.directive.d.ts +43 -0
- package/table-builder/directives/table-wrapper.directive.d.ts +8 -0
- package/table-builder/directives/tb-filter.directive.d.ts +115 -0
- package/table-builder/enums/filterTypes.d.ts +36 -0
- package/table-builder/functions/boolean-filter-function.d.ts +3 -0
- package/table-builder/functions/date-filter-function.d.ts +4 -0
- package/table-builder/functions/download-data.d.ts +1 -0
- package/table-builder/functions/null-filter-function.d.ts +2 -0
- package/table-builder/functions/number-filter-function.d.ts +4 -0
- package/table-builder/functions/sort-data-function.d.ts +6 -0
- package/table-builder/functions/string-filter-function.d.ts +5 -0
- package/{src/table-builder/interfaces/ColumnInfo.ts → table-builder/interfaces/ColumnInfo.d.ts} +6 -7
- package/{src/table-builder/interfaces/dictionary.ts → table-builder/interfaces/dictionary.d.ts} +3 -3
- package/table-builder/interfaces/report-def.d.ts +147 -0
- package/table-builder/ngrx/tableBuilderStateStore.d.ts +70 -0
- package/table-builder/pipes/column-total.pipe.d.ts +8 -0
- package/table-builder/pipes/format-filter-type.pipe.d.ts +8 -0
- package/table-builder/pipes/format-filter-value.pipe.d.ts +12 -0
- package/table-builder/pipes/key-display.d.ts +10 -0
- package/table-builder/services/export-to-csv.service.d.ts +14 -0
- package/table-builder/services/link-creator.service.d.ts +16 -0
- package/table-builder/services/table-template-service.d.ts +14 -0
- package/table-builder/services/transform-creator.d.ts +16 -0
- package/table-builder/table-builder.module.d.ts +21 -0
- package/utilities/array-helpers.d.ts +1 -0
- package/utilities/directives/auto-focus.directive.d.ts +9 -0
- package/utilities/directives/clickEmitterDirective.d.ts +7 -0
- package/utilities/directives/clickSubject.d.ts +9 -0
- package/utilities/directives/conditional-classes.directive.d.ts +13 -0
- package/utilities/directives/dialog-service.d.ts +10 -0
- package/utilities/directives/dialog.d.ts +44 -0
- package/utilities/directives/mat-toggle-group-directive.d.ts +21 -0
- package/utilities/directives/prevent-enter.directive.d.ts +6 -0
- package/utilities/directives/stop-propagation.directive.d.ts +7 -0
- package/utilities/directives/styler.d.ts +15 -0
- package/utilities/directives/trim-whitespace.directive.d.ts +7 -0
- package/{src/utilities/index.ts → utilities/index.d.ts} +15 -22
- package/utilities/module.d.ts +19 -0
- package/utilities/pipes/function.pipe.d.ts +7 -0
- package/utilities/pipes/phone.pipe.d.ts +7 -0
- package/utilities/pipes/space-case.pipes.d.ts +17 -0
- package/karma.conf.js +0 -44
- package/ng-package.json +0 -7
- package/src/action-state/action-state-spinner/action-state-spinner.component.css +0 -16
- package/src/action-state/action-state-spinner/action-state-spinner.component.html +0 -6
- package/src/action-state/action-state-spinner/action-state-spinner.component.spec.ts +0 -25
- package/src/action-state/action-state-spinner/action-state-spinner.component.ts +0 -26
- package/src/action-state/action-state-ui/action-state-ui.module.ts +0 -13
- package/src/action-state/ngrx-ext/ngrx-ext.module.ts +0 -15
- package/src/action-state/ngrx.ts +0 -69
- package/src/http-request-state/HttpRequestStateFactory.ts +0 -66
- package/src/http-request-state/HttpRequestStateStore.ts +0 -191
- package/src/http-request-state/directives/HttpStateDirectiveBase.ts +0 -29
- package/src/http-request-state/directives/http-error-state-directive.ts +0 -21
- package/src/http-request-state/directives/http-inProgress-state-directive.ts +0 -19
- package/src/http-request-state/directives/http-notStarted-state-directive.ts +0 -19
- package/src/http-request-state/directives/http-success-state-directive.ts +0 -29
- package/src/http-request-state/directives/request-state-directive.spec.ts +0 -72
- package/src/http-request-state/directives/request-state-directive.ts +0 -78
- package/src/http-request-state/helpers.ts +0 -30
- package/src/http-request-state/http-request-state.ts +0 -69
- package/src/http-request-state/http-state-module.ts +0 -23
- package/src/http-request-state/observable.spec.ts +0 -43
- package/src/http-request-state/rxjs/getRequestorBody.ts +0 -10
- package/src/http-request-state/rxjs/getRequestorState.ts +0 -8
- package/src/http-request-state/rxjs/tapError.ts +0 -16
- package/src/http-request-state/rxjs/tapSuccess.ts +0 -16
- package/src/http-request-state/strategies.spec.ts +0 -42
- package/src/http-request-state/types.ts +0 -55
- package/src/ngrx/actionable-selector.ts +0 -152
- package/src/ngrx/index.ts +0 -1
- package/src/rxjs/defaultShareReplay.ts +0 -8
- package/src/rxjs/mapError.ts +0 -8
- package/src/rxjs/rxjs-operators.ts +0 -132
- package/src/rxjs/subjectifier.ts +0 -17
- package/src/rxjs/subscriber.directive.ts +0 -57
- package/src/specs/clickSubject.spec.ts +0 -95
- package/src/specs/dialog.spec.ts +0 -101
- package/src/specs/toggleGroupDirective.spec.ts +0 -229
- package/src/table-builder/classes/DefaultSettings.ts +0 -11
- package/src/table-builder/classes/MatTableObservableDataSource.ts +0 -23
- package/src/table-builder/classes/TableBuilderConfig.ts +0 -36
- package/src/table-builder/classes/TableBuilderDataSource.ts +0 -61
- package/src/table-builder/classes/TableState.ts +0 -93
- package/src/table-builder/classes/data-store.ts +0 -10
- package/src/table-builder/classes/filter-info.ts +0 -108
- package/src/table-builder/classes/table-builder-general-settings.ts +0 -141
- package/src/table-builder/classes/table-builder.ts +0 -95
- package/src/table-builder/classes/table-store.ts +0 -476
- package/src/table-builder/components/array-column.component.ts +0 -36
- package/src/table-builder/components/column-builder/column-builder.component.html +0 -61
- package/src/table-builder/components/column-builder/column-builder.component.scss +0 -43
- package/src/table-builder/components/column-builder/column-builder.component.spec.ts +0 -49
- package/src/table-builder/components/column-builder/column-builder.component.ts +0 -146
- package/src/table-builder/components/column-builder/column-helpers.ts +0 -52
- package/src/table-builder/components/date-filter/date-filter.component.html +0 -23
- package/src/table-builder/components/date-filter/date-filter.component.ts +0 -24
- package/src/table-builder/components/date-time-filter/date-time-filter.component.html +0 -9
- package/src/table-builder/components/date-time-filter/date-time-filter.component.ts +0 -22
- package/src/table-builder/components/filter/filter.component.html +0 -91
- package/src/table-builder/components/filter/filter.component.scss +0 -60
- package/src/table-builder/components/filter/filter.component.spec.ts +0 -87
- package/src/table-builder/components/filter/filter.component.ts +0 -60
- package/src/table-builder/components/filter/in-list/in-list-filter.component.ts +0 -93
- package/src/table-builder/components/gen-col-displayer/gen-col-displayer.component.html +0 -55
- package/src/table-builder/components/gen-col-displayer/gen-col-displayer.component.scss +0 -57
- package/src/table-builder/components/gen-col-displayer/gen-col-displayer.component.ts +0 -46
- package/src/table-builder/components/generic-table/generic-table.component.html +0 -77
- package/src/table-builder/components/generic-table/generic-table.component.scss +0 -38
- package/src/table-builder/components/generic-table/generic-table.component.ts +0 -325
- package/src/table-builder/components/generic-table/paginator.component.ts +0 -99
- package/src/table-builder/components/group-by-list/group-by-list.component.css +0 -8
- package/src/table-builder/components/group-by-list/group-by-list.component.html +0 -12
- package/src/table-builder/components/group-by-list/group-by-list.component.spec.ts +0 -23
- package/src/table-builder/components/group-by-list/group-by-list.component.ts +0 -21
- package/src/table-builder/components/header-menu/header-menu.component.html +0 -104
- package/src/table-builder/components/header-menu/header-menu.component.scss +0 -96
- package/src/table-builder/components/header-menu/header-menu.component.ts +0 -99
- package/src/table-builder/components/in-filter/in-filter.component.css +0 -3
- package/src/table-builder/components/in-filter/in-filter.component.html +0 -20
- package/src/table-builder/components/in-filter/in-filter.component.ts +0 -66
- package/src/table-builder/components/initialization-component/initialization-component.html +0 -29
- package/src/table-builder/components/initialization-component/initialization-component.ts +0 -24
- package/src/table-builder/components/link-column.component.ts +0 -47
- package/src/table-builder/components/number-filter/number-filter.component.css +0 -10
- package/src/table-builder/components/number-filter/number-filter.component.html +0 -19
- package/src/table-builder/components/number-filter/number-filter.component.spec.ts +0 -30
- package/src/table-builder/components/number-filter/number-filter.component.ts +0 -25
- package/src/table-builder/components/profiles-menu/profiles-menu.component.html +0 -78
- package/src/table-builder/components/profiles-menu/profiles-menu.component.scss +0 -126
- package/src/table-builder/components/profiles-menu/profiles-menu.component.spec.ts +0 -23
- package/src/table-builder/components/profiles-menu/profiles-menu.component.ts +0 -65
- package/src/table-builder/components/scroll-strategy.ts +0 -76
- package/src/table-builder/components/sort-menu/sort-menu.component-store.ts +0 -66
- package/src/table-builder/components/sort-menu/sort-menu.component.html +0 -111
- package/src/table-builder/components/sort-menu/sort-menu.component.scss +0 -119
- package/src/table-builder/components/sort-menu/sort-menu.component.ts +0 -98
- package/src/table-builder/components/table-container/table-container.helpers/data-state.helpers.ts +0 -141
- package/src/table-builder/components/table-container/table-container.helpers/filter-state.helpers.ts +0 -106
- package/src/table-builder/components/table-container/table-container.helpers/groupBy.helpers.ts +0 -86
- package/src/table-builder/components/table-container/table-container.helpers/sort-state.helpers.ts +0 -45
- package/src/table-builder/components/table-container/table-container.html +0 -94
- package/src/table-builder/components/table-container/table-container.scss +0 -47
- package/src/table-builder/components/table-container/table-container.spec.ts +0 -154
- package/src/table-builder/components/table-container/table-container.ts +0 -356
- package/src/table-builder/components/table-container/tableProps.ts +0 -20
- package/src/table-builder/components/table-container/virtual-scroll-container.ts +0 -156
- package/src/table-builder/components/table-container-filter/filter-list/filter-list.component.html +0 -31
- package/src/table-builder/components/table-container-filter/filter-list/filter-list.component.ts +0 -46
- package/src/table-builder/components/table-container-filter/gen-filter-displayer/gen-filter-displayer.component.css +0 -42
- package/src/table-builder/components/table-container-filter/gen-filter-displayer/gen-filter-displayer.component.html +0 -10
- package/src/table-builder/components/table-container-filter/gen-filter-displayer/gen-filter-displayer.component.spec.ts +0 -85
- package/src/table-builder/components/table-container-filter/gen-filter-displayer/gen-filter-displayer.component.ts +0 -33
- package/src/table-builder/components/table-container-filter/table-wrapper-filter-store.ts +0 -23
- package/src/table-builder/directives/custom-cell-directive.ts +0 -58
- package/src/table-builder/directives/multi-sort.directive.spec.ts +0 -124
- package/src/table-builder/directives/multi-sort.directive.ts +0 -51
- package/src/table-builder/directives/resize-column.directive.ts +0 -108
- package/src/table-builder/directives/table-wrapper.directive.ts +0 -14
- package/src/table-builder/directives/tb-filter.directive.ts +0 -382
- package/src/table-builder/enums/filterTypes.ts +0 -40
- package/src/table-builder/functions/boolean-filter-function.ts +0 -12
- package/src/table-builder/functions/date-filter-function.ts +0 -68
- package/src/table-builder/functions/download-data.ts +0 -11
- package/src/table-builder/functions/null-filter-function.ts +0 -9
- package/src/table-builder/functions/number-filter-function.ts +0 -41
- package/src/table-builder/functions/sort-data-function.ts +0 -23
- package/src/table-builder/functions/string-filter-function.ts +0 -51
- package/src/table-builder/interfaces/column-template.ts +0 -9
- package/src/table-builder/interfaces/report-def.ts +0 -155
- package/src/table-builder/ngrx/tableBuilderStateStore.ts +0 -199
- package/src/table-builder/pipes/column-total.pipe.ts +0 -17
- package/src/table-builder/pipes/format-filter-type.pipe.ts +0 -12
- package/src/table-builder/pipes/format-filter-value.pipe.ts +0 -42
- package/src/table-builder/pipes/key-display.ts +0 -16
- package/src/table-builder/services/export-to-csv.service.ts +0 -78
- package/src/table-builder/services/link-creator.service.ts +0 -67
- package/src/table-builder/services/table-template-service.ts +0 -59
- package/src/table-builder/services/transform-creator.ts +0 -95
- package/src/table-builder/specs/table-custom-filters.spec.ts +0 -262
- package/src/table-builder/styles/collapser.styles.scss +0 -16
- package/src/table-builder/table-builder.module.ts +0 -73
- package/src/test.ts +0 -17
- package/src/utilities/array-helpers.ts +0 -13
- package/src/utilities/directives/auto-focus.directive.ts +0 -21
- package/src/utilities/directives/clickEmitterDirective.ts +0 -16
- package/src/utilities/directives/clickSubject.ts +0 -20
- package/src/utilities/directives/conditional-classes.directive.ts +0 -36
- package/src/utilities/directives/dialog-service.ts +0 -19
- package/src/utilities/directives/dialog.ts +0 -144
- package/src/utilities/directives/mat-toggle-group-directive.ts +0 -61
- package/src/utilities/directives/prevent-enter.directive.ts +0 -13
- package/src/utilities/directives/stop-propagation.directive.ts +0 -20
- package/src/utilities/directives/styler.ts +0 -40
- package/src/utilities/directives/trim-whitespace.directive.ts +0 -21
- package/src/utilities/module.ts +0 -55
- package/src/utilities/pipes/function.pipe.ts +0 -16
- package/src/utilities/pipes/phone.pipe.ts +0 -15
- package/src/utilities/pipes/space-case.pipes.spec.ts +0 -47
- package/src/utilities/pipes/space-case.pipes.ts +0 -23
- package/tsconfig.lib.json +0 -19
- package/tsconfig.lib.prod.json +0 -10
- package/tsconfig.spec.json +0 -17
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { MockHttpRequestState } from "./directives/request-state-directive.spec";
|
|
2
|
-
import { createSuccess, inProgress, notStarted, createFailure } from "./helpers";
|
|
3
|
-
|
|
4
|
-
describe('HttpRequestStateStore', () => {
|
|
5
|
-
|
|
6
|
-
it('should begin with the state of not started', (done) => {
|
|
7
|
-
const requestState = new MockHttpRequestState<string>();
|
|
8
|
-
requestState.state$.subscribe( state => {
|
|
9
|
-
expect(state).toEqual({ requestParams: null as any , response: notStarted});
|
|
10
|
-
done();
|
|
11
|
-
});
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('should be in progress when request is made', (done) => {
|
|
15
|
-
const requestState = new MockHttpRequestState<string>();
|
|
16
|
-
requestState.request();
|
|
17
|
-
requestState.state$.subscribe( state => {
|
|
18
|
-
expect(state).toEqual({ requestParams: [], response: inProgress});
|
|
19
|
-
done();
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('should be in success when request completes successfully', (done) => {
|
|
24
|
-
const requestState = new MockHttpRequestState<string>();
|
|
25
|
-
requestState.request();
|
|
26
|
-
requestState.subject.next('hi');
|
|
27
|
-
requestState.state$.subscribe( state => {
|
|
28
|
-
expect(state).toEqual({ requestParams: [], response: createSuccess('hi')});
|
|
29
|
-
done();
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('should be in error when request errors', (done) => {
|
|
34
|
-
const requestState = new MockHttpRequestState<string>();
|
|
35
|
-
requestState.request();
|
|
36
|
-
requestState.subject.error('error');
|
|
37
|
-
requestState.state$.subscribe( state => {
|
|
38
|
-
expect(state).toEqual({ requestParams: [], response: createFailure('error') });
|
|
39
|
-
done();
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { isSuccessState } from '../helpers';
|
|
2
|
-
import { HttpRequestState } from '../types';
|
|
3
|
-
import { Observable } from 'rxjs';
|
|
4
|
-
import { filter, map } from 'rxjs/operators';
|
|
5
|
-
|
|
6
|
-
export const getRequestorBody = <T>(source: Observable<HttpRequestState<T>>) =>
|
|
7
|
-
source.pipe(
|
|
8
|
-
filter(isSuccessState),
|
|
9
|
-
map( res => res.body)
|
|
10
|
-
);
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Observable } from 'rxjs';
|
|
2
|
-
import { tap } from 'rxjs/operators';
|
|
3
|
-
import { HttpRequestState } from '../types';
|
|
4
|
-
import { isErrorState } from '../helpers';
|
|
5
|
-
|
|
6
|
-
export function tapError(onError: (error: any) => void) {
|
|
7
|
-
return function (src: Observable<HttpRequestState>): Observable<HttpRequestState> {
|
|
8
|
-
return src.pipe(
|
|
9
|
-
tap( result => {
|
|
10
|
-
if(isErrorState(result)) {
|
|
11
|
-
onError(result.error);
|
|
12
|
-
}
|
|
13
|
-
})
|
|
14
|
-
);
|
|
15
|
-
};
|
|
16
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Observable } from 'rxjs';
|
|
2
|
-
import { tap } from 'rxjs/operators';
|
|
3
|
-
import { HttpRequestState } from '../types';
|
|
4
|
-
import { isSuccessState } from '../helpers';
|
|
5
|
-
|
|
6
|
-
export function tapSuccess<T>(onSuccess: (body: T) => void) {
|
|
7
|
-
return function (src: Observable<HttpRequestState<T>>): Observable<HttpRequestState<T>> {
|
|
8
|
-
return src.pipe(
|
|
9
|
-
tap( result => {
|
|
10
|
-
if(isSuccessState(result)) {
|
|
11
|
-
onSuccess(result.body);
|
|
12
|
-
}
|
|
13
|
-
})
|
|
14
|
-
);
|
|
15
|
-
};
|
|
16
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { toArray } from "rxjs/operators";
|
|
2
|
-
import { MockHttpRequestState } from "./directives/request-state-directive.spec";
|
|
3
|
-
import { HttpRequestStrategy } from "./types";
|
|
4
|
-
|
|
5
|
-
describe('HttpRequestStateStore', () => {
|
|
6
|
-
|
|
7
|
-
it('should throw when strategy is use once and it was reused', () => {
|
|
8
|
-
const requestState = new MockHttpRequestState<string>({strategy: HttpRequestStrategy.singleUse});
|
|
9
|
-
requestState.request();
|
|
10
|
-
expect( ()=>{
|
|
11
|
-
requestState.request();
|
|
12
|
-
} ).toThrow();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
it('should emit both when strategy is concurrent', (done) => {
|
|
17
|
-
const requestState = new MockHttpRequestState<string>({strategy: HttpRequestStrategy.concurrent});
|
|
18
|
-
requestState.request();
|
|
19
|
-
requestState.request();
|
|
20
|
-
requestState.selectResponse$.pipe( toArray()
|
|
21
|
-
).subscribe( d => {
|
|
22
|
-
expect(d.length).toBe(2);
|
|
23
|
-
done();
|
|
24
|
-
});
|
|
25
|
-
requestState.subject.next('hi');
|
|
26
|
-
requestState.ngOnDestroy();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('should emit only one when strategy is cancel previous', (done) => {
|
|
30
|
-
const requestState = new MockHttpRequestState<string>({strategy: HttpRequestStrategy.cancelPrevious});
|
|
31
|
-
requestState.request();
|
|
32
|
-
requestState.request();
|
|
33
|
-
requestState.selectResponse$.pipe( toArray()
|
|
34
|
-
).subscribe( d => {
|
|
35
|
-
expect(d.length).toBe(1);
|
|
36
|
-
done();
|
|
37
|
-
});
|
|
38
|
-
requestState.subject.next('hi');
|
|
39
|
-
requestState.ngOnDestroy();
|
|
40
|
-
|
|
41
|
-
});
|
|
42
|
-
});
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { Injector } from '@angular/core';
|
|
2
|
-
import { Observable } from 'rxjs';
|
|
3
|
-
export enum HttpRequestStatus {
|
|
4
|
-
notStarted,
|
|
5
|
-
inProgress,
|
|
6
|
-
success,
|
|
7
|
-
fail,
|
|
8
|
-
cancelled,
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export type HttpRequestStateCancelled = {
|
|
12
|
-
status: HttpRequestStatus.cancelled
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export type HttpRequestStateNotStarted = {
|
|
16
|
-
status: HttpRequestStatus.notStarted
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export type HttpRequestStateInProgress = {
|
|
20
|
-
status: HttpRequestStatus.inProgress
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export type HttpRequestStateSuccess<T> = {
|
|
24
|
-
status: HttpRequestStatus.success;
|
|
25
|
-
body: T;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export type HttpRequestStateError = {
|
|
29
|
-
status: HttpRequestStatus.fail;
|
|
30
|
-
error: any;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
export type HttpRequestState<T = any> =
|
|
35
|
-
HttpRequestStateCancelled |
|
|
36
|
-
HttpRequestStateNotStarted |
|
|
37
|
-
HttpRequestStateInProgress |
|
|
38
|
-
HttpRequestStateSuccess<T> |
|
|
39
|
-
HttpRequestStateError ;
|
|
40
|
-
|
|
41
|
-
export enum HttpRequestStrategy {
|
|
42
|
-
concurrent = 1,
|
|
43
|
-
singleUse = 2,
|
|
44
|
-
cancelPrevious = 3,
|
|
45
|
-
sequential = 4,
|
|
46
|
-
}
|
|
47
|
-
export interface RequestStateOptions<TParam extends any[] = any> {
|
|
48
|
-
strategy?: HttpRequestStrategy;
|
|
49
|
-
autoRequestWith?: [...TParam];
|
|
50
|
-
injector?: Injector;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface RequestCreatorOptions<TParam extends any[] = any> extends RequestStateOptions<TParam> {}
|
|
54
|
-
|
|
55
|
-
export type HttpRequestFactory<TParam extends any[], T> = (...params: [...TParam]) => Observable<T>
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { APP_INITIALIZER, EnvironmentInjector, Injector, makeEnvironmentProviders, runInInjectionContext, untracked } from "@angular/core";
|
|
2
|
-
import { Action, createSelector, MemoizedSelector, Store } from "@ngrx/store";
|
|
3
|
-
import { v4 as uuid } from 'uuid';
|
|
4
|
-
|
|
5
|
-
let _store: Store<any>;
|
|
6
|
-
let _cache: AppStoreCache;
|
|
7
|
-
let _ei : EnvironmentInjector;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Creates a selector that can dispatch an action if conditions are met.
|
|
11
|
-
* Note: The props of the selector factory must include the props of the action.
|
|
12
|
-
* @param selectorFactory A method that returns selector.
|
|
13
|
-
* @param action The action that will be dispatched when conditions are met.
|
|
14
|
-
* @param [dispatchIf = defaultFilter] Optional. A method that takes the result of the selector and returns a boolean. The actions gets dispatched
|
|
15
|
-
* if true is returned. If no method is passed in than the action will be dispatched if the selector returns undefined or null.
|
|
16
|
-
*/
|
|
17
|
-
export const createActionableSelector = <State, Result, Props extends any[]>(
|
|
18
|
-
selectorFactory: ((...props: Props) => MemoizedSelector<State, Result>),
|
|
19
|
-
action: ActionReturner<Props>,
|
|
20
|
-
dispatchIf: (data: Result) => boolean = defaultFilter,
|
|
21
|
-
) => {
|
|
22
|
-
const options = {
|
|
23
|
-
selectorFactory,
|
|
24
|
-
action: (...props: Props) => () => _store.dispatch(action(...props)),
|
|
25
|
-
dispatchIf
|
|
26
|
-
}
|
|
27
|
-
const actionable = createActionResultSelector(options);
|
|
28
|
-
return (...props: Props) => createSelector(actionable(...props), b => b.result);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const createActionSelector = <State, Result, Props extends any[] = any[]>(options: CreateActionResultsOptions<State, Result, Props>) => {
|
|
32
|
-
const actionable = createActionResultSelector(options);
|
|
33
|
-
return ((...props: Props) => createSelector(actionable(...props), b => b.result));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export const createActionableResultSelector = <State, Result, Props extends any[]>(
|
|
37
|
-
selectorFactory: ((...props: Props) => MemoizedSelector<State, Result>),
|
|
38
|
-
action: ActionReturner<Props>,
|
|
39
|
-
dispatchIf: (data: Result) => boolean = defaultFilter,
|
|
40
|
-
) => {
|
|
41
|
-
const options: CreateActionResultsOptions<State, Result, Props> = {
|
|
42
|
-
selectorFactory,
|
|
43
|
-
action: (...props: Props) => () => _store.dispatch(action(...props)),
|
|
44
|
-
dispatchIf
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
return createActionResultSelector(options);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export const createActionResultSelector = <State, Result, Props extends any[] = any[]>(options: CreateActionResultsOptions<State, Result, Props>) => {
|
|
51
|
-
const id = uuid();
|
|
52
|
-
const slctr = (...props: Props) => createSelector(
|
|
53
|
-
options.selectorFactory(...props),
|
|
54
|
-
(selected: Result) => {
|
|
55
|
-
const needsDispatch = (options.dispatchIf || defaultFilter)(selected);
|
|
56
|
-
if(needsDispatch && !_cache.isInCache(id, ...props)){
|
|
57
|
-
queueMicrotask(() =>
|
|
58
|
-
runInInjectionContext(options.injector || _ei, () => {
|
|
59
|
-
options.action(...props)()
|
|
60
|
-
}));
|
|
61
|
-
}
|
|
62
|
-
return ({
|
|
63
|
-
loading: needsDispatch,
|
|
64
|
-
result: selected
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
) as ActionableMemoizedSelector<State, LoadingState<Result>>;
|
|
68
|
-
return slctr;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
class AppStoreCache {
|
|
72
|
-
cache: Cache = {};
|
|
73
|
-
isInCache = (actionableSelectorId: string, ...p: any[]): boolean => {
|
|
74
|
-
const props = p.reduce((a, b) => {
|
|
75
|
-
if(typeof b != 'object') b = { b };
|
|
76
|
-
return({ ...a, ...b })
|
|
77
|
-
}, {});
|
|
78
|
-
|
|
79
|
-
let itemsInCache = this.cache[actionableSelectorId] = (this.cache[actionableSelectorId] || []);
|
|
80
|
-
|
|
81
|
-
if(itemsInCache.some(itemInCache => shallowEquals(itemInCache, props))){
|
|
82
|
-
return true;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
itemsInCache.push(props);
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export const clearActionableSelectorRequestCache = () => _cache.cache = {};
|
|
91
|
-
|
|
92
|
-
const shallowEquals = (cachedItem: object, newItem: object): boolean => {
|
|
93
|
-
const cachedItemKeys = Object.keys(cachedItem);
|
|
94
|
-
const secondKeys = Object.keys(newItem);
|
|
95
|
-
if(cachedItemKeys.length !== secondKeys.length) {
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
for(let index = 0; index < cachedItemKeys.length; index++) {
|
|
99
|
-
const currentKey = cachedItemKeys[index];
|
|
100
|
-
if(cachedItem[currentKey] !== newItem[currentKey]){
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return true;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export function defaultFilter(data: any) {
|
|
108
|
-
return data == null || data == undefined;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const setStore = (store: Store) => {
|
|
112
|
-
if(store instanceof Store) _store ??= store;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const setEnvironmentInjector = (ei: EnvironmentInjector) => {
|
|
116
|
-
if(ei instanceof EnvironmentInjector) _ei ??= ei;
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
export function provideActionableSelector(){
|
|
120
|
-
return makeEnvironmentProviders([
|
|
121
|
-
{ provide: APP_INITIALIZER, useFactory: setUpStoreFactory, multi: true, deps: [Store, EnvironmentInjector] },
|
|
122
|
-
])
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export function setUpStoreFactory(store: Store, env: EnvironmentInjector){
|
|
126
|
-
_cache ??= new AppStoreCache();
|
|
127
|
-
return () => new Promise((resolve, reject) => {
|
|
128
|
-
setStore(store);
|
|
129
|
-
setEnvironmentInjector(env)
|
|
130
|
-
resolve(null);
|
|
131
|
-
})
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export interface CreateActionResultsOptions<State, Result, Props extends any[]>{
|
|
135
|
-
selectorFactory: (...props: Props) => MemoizedSelector<State, Result>,
|
|
136
|
-
action: (...props: Props) => () => void,
|
|
137
|
-
dispatchIf?: (data: Result) => boolean,
|
|
138
|
-
injector?: Injector
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
interface LoadingState<T> {
|
|
142
|
-
loading: boolean;
|
|
143
|
-
result?: T;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
type ActionableMemoizedSelector<State, Result> = MemoizedSelector<State, Result>;
|
|
147
|
-
|
|
148
|
-
export type ActionReturner<Props extends any[]> = (...props: Props) => Action;
|
|
149
|
-
|
|
150
|
-
type Cache = {
|
|
151
|
-
[key: string]: { [key: string]: any }[];
|
|
152
|
-
}
|
package/src/ngrx/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './actionable-selector';
|
package/src/rxjs/mapError.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Observable, of } from 'rxjs';
|
|
2
|
-
import { catchError } from 'rxjs/operators';
|
|
3
|
-
|
|
4
|
-
export function mapError<T, TResult>(projection: (error: any) => TResult) {
|
|
5
|
-
return function (src: Observable<T>): Observable<T | TResult> {
|
|
6
|
-
return src.pipe(catchError(e => of(projection(e))),);
|
|
7
|
-
};
|
|
8
|
-
}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { Predicate } from '@angular/core';
|
|
2
|
-
import { flatten } from 'lodash';
|
|
3
|
-
import {
|
|
4
|
-
filter,
|
|
5
|
-
first,
|
|
6
|
-
map,
|
|
7
|
-
pairwise,
|
|
8
|
-
startWith,
|
|
9
|
-
Observable,
|
|
10
|
-
combineLatest,
|
|
11
|
-
Subscription,
|
|
12
|
-
MonoTypeOperatorFunction,
|
|
13
|
-
OperatorFunction,
|
|
14
|
-
concatMap,
|
|
15
|
-
merge,
|
|
16
|
-
of,
|
|
17
|
-
delay
|
|
18
|
-
} from 'rxjs';
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
export const onceWhen = <T>(predicate: Predicate<T>) => (src: Observable<T>) : Observable<T> => {
|
|
22
|
-
return src.pipe(filter(predicate),first());
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const mapArray = <T, U>(mapFunc: (src: T, index?: number) => U ) => (source: Observable<T[]>) =>
|
|
26
|
-
source.pipe( map( src => src.map(mapFunc) ) );
|
|
27
|
-
|
|
28
|
-
export const filterArray = <T>(filterFunc: (src: T) => boolean ) => (source: Observable<T[]>) =>
|
|
29
|
-
source.pipe( map( src => src.filter(filterFunc) ) );
|
|
30
|
-
|
|
31
|
-
export const onWait = startWithIfEmpty;
|
|
32
|
-
export function startWithIfEmpty<T,V extends T>(val: V, wait = 0) : MonoTypeOperatorFunction<T> {
|
|
33
|
-
return (source: Observable<T>) => {
|
|
34
|
-
return new Observable<T>(subscriber => {
|
|
35
|
-
let emitted = false;
|
|
36
|
-
setTimeout(() => {
|
|
37
|
-
if(!emitted) {
|
|
38
|
-
subscriber.next(val);
|
|
39
|
-
}
|
|
40
|
-
}, wait);
|
|
41
|
-
const sub = source.subscribe({
|
|
42
|
-
next(x) { emitted = true; subscriber.next(x) },
|
|
43
|
-
error(err) { emitted = true; subscriber.error(err) },
|
|
44
|
-
complete() { emitted = true; subscriber.complete(); }
|
|
45
|
-
});
|
|
46
|
-
return () => sub.unsubscribe();
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export const combineArrays = <T>(sources: Observable<T[]>[]): Observable<T[]> => {
|
|
53
|
-
return combineLatest(
|
|
54
|
-
sources.map( src => src.pipe(startWithIfEmpty([] as T [])))
|
|
55
|
-
).pipe(
|
|
56
|
-
map( res => res.flat() )
|
|
57
|
-
);
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
export function switchOff( switchSource: Observable<boolean>, defaultState: boolean = true) {
|
|
61
|
-
return <T>(source: Observable<T>) : Observable<T> => {
|
|
62
|
-
return new Observable(subsciber => {
|
|
63
|
-
let isOn = defaultState;
|
|
64
|
-
const subscription = new Subscription();
|
|
65
|
-
subscription.add( switchSource.subscribe( on => isOn = on ));
|
|
66
|
-
subscription.add(source.subscribe({
|
|
67
|
-
next(value) {
|
|
68
|
-
if(isOn) {
|
|
69
|
-
subsciber.next(value);
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
error: error => subsciber.error(error),
|
|
73
|
-
complete: () => subsciber.complete()
|
|
74
|
-
}));
|
|
75
|
-
return subscription;
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export function skipOneWhen( skipper: Observable<any> ) {
|
|
81
|
-
return <T>(source: Observable<T>) : Observable<T> => {
|
|
82
|
-
return new Observable(subsriber => {
|
|
83
|
-
const subscription = new Subscription();
|
|
84
|
-
let skipNext = false;
|
|
85
|
-
subscription.add(skipper.subscribe( _ => skipNext = true));
|
|
86
|
-
subscription.add(source.subscribe({
|
|
87
|
-
next(value) {
|
|
88
|
-
if(skipNext) {
|
|
89
|
-
skipNext = false;
|
|
90
|
-
} else {
|
|
91
|
-
subsriber.next(value);
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
error: error => subsriber.error(error),
|
|
95
|
-
complete: () => subsriber.complete()
|
|
96
|
-
}));
|
|
97
|
-
return subscription;
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export function previousAndCurrent<T>(startingValue : T) : OperatorFunction<T, [T, T]> {
|
|
103
|
-
return (source: Observable<T>) => {
|
|
104
|
-
return source.pipe(startWith(startingValue), pairwise());
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export function notNull<T>(): OperatorFunction<(T | null | undefined), T> {
|
|
109
|
-
return (source: Observable<T | null | undefined>) => {
|
|
110
|
-
return source.pipe(filter( (o: T | null | undefined): o is T => o != null) )
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export function delayOn<T>(predicate: (t: T) => boolean, delayTime: number) {
|
|
115
|
-
return (src: Observable<T>) => {
|
|
116
|
-
return src.pipe(
|
|
117
|
-
concatMap(r => {
|
|
118
|
-
if (predicate(r)) {
|
|
119
|
-
return merge(
|
|
120
|
-
of({ r }),
|
|
121
|
-
of(null).pipe(delay(delayTime))
|
|
122
|
-
).pipe(
|
|
123
|
-
notNull(),
|
|
124
|
-
map(d => d.r)
|
|
125
|
-
);
|
|
126
|
-
} else {
|
|
127
|
-
return of(r);
|
|
128
|
-
}
|
|
129
|
-
})
|
|
130
|
-
);
|
|
131
|
-
};
|
|
132
|
-
}
|
package/src/rxjs/subjectifier.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { merge, Observable, Observer, Subject } from 'rxjs';
|
|
2
|
-
type PipeLike<T> = Observable<T>['pipe'];
|
|
3
|
-
export class Subjectifier<T> extends Observable<T>{
|
|
4
|
-
private _subj = new Subject<T>();
|
|
5
|
-
private merged: Observable<T>;
|
|
6
|
-
constructor(_source: Observable<T>){
|
|
7
|
-
super((obs: Observer<T>) => {
|
|
8
|
-
const s = merge( _source, this._subj ).subscribe(obs);
|
|
9
|
-
return s;
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
this.merged = merge(_source, this._subj);
|
|
13
|
-
}
|
|
14
|
-
next: Subject<T>['next'] = this._subj.next.bind(this._subj);
|
|
15
|
-
newSubj = (...operations: Parameters<PipeLike<T>>) =>
|
|
16
|
-
new Subjectifier(this.merged.pipe(...operations));
|
|
17
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { DestroyRef, Directive, Injector, OnDestroy, assertInInjectionContext, inject } from "@angular/core";
|
|
2
|
-
import { Observable, Subscription } from "rxjs";
|
|
3
|
-
|
|
4
|
-
@Directive()
|
|
5
|
-
export class Subscriber implements OnDestroy{
|
|
6
|
-
subscriptions: Subscription[] = [];
|
|
7
|
-
handle = (subscription: Subscription) => {
|
|
8
|
-
this.subscriptions.push(subscription);
|
|
9
|
-
}
|
|
10
|
-
on = <T = any>(obs: Observable<T>, action: (t: T) => any) => {
|
|
11
|
-
this.handle(obs.subscribe(action));
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
ngOnDestroy() {
|
|
15
|
-
this.subscriptions.forEach(subscription => {
|
|
16
|
-
subscription.unsubscribe();
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function subscriber(injector: Injector): Subscriber
|
|
22
|
-
export function subscriber(subscription?: Subscription, injector?: Injector): Subscriber
|
|
23
|
-
export function subscriber<T = any>(obs: Observable<T>, action: (t: T) => any, injector?: Injector): Subscriber
|
|
24
|
-
export function subscriber<T = any>(obsOrSubOrInjector?: Observable<T> | Subscription | Injector, actionOrInjector?: ((t: T) => any) | Injector, injector?: Injector): Subscriber {
|
|
25
|
-
|
|
26
|
-
const destroyRef = getDestroyRef(obsOrSubOrInjector, actionOrInjector, injector);
|
|
27
|
-
|
|
28
|
-
const subscriber = new Subscriber();
|
|
29
|
-
|
|
30
|
-
if(obsOrSubOrInjector instanceof Subscription){
|
|
31
|
-
subscriber.handle(obsOrSubOrInjector);
|
|
32
|
-
} else if(obsOrSubOrInjector instanceof Observable){
|
|
33
|
-
subscriber.handle(obsOrSubOrInjector.subscribe(actionOrInjector as (t: T) => any));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
destroyRef.onDestroy(() => subscriber?.ngOnDestroy());
|
|
37
|
-
|
|
38
|
-
return subscriber;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function getDestroyRef(obsOrSubOrInjector: any, actionOrInjector?: any, injector?: Injector){
|
|
42
|
-
const providedInjector = obsOrSubOrInjector instanceof Injector ? obsOrSubOrInjector
|
|
43
|
-
: actionOrInjector instanceof Injector ? actionOrInjector
|
|
44
|
-
: injector;
|
|
45
|
-
|
|
46
|
-
if(!providedInjector){
|
|
47
|
-
try {
|
|
48
|
-
assertInInjectionContext(subscriber);
|
|
49
|
-
} catch (error) {
|
|
50
|
-
throw new Error('createRequestor() must be used in an Injection Context or you must provide an injector to createRequestor()');
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const destroyRef = providedInjector?.get(DestroyRef) || inject(DestroyRef);
|
|
55
|
-
|
|
56
|
-
return destroyRef;
|
|
57
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { Component } from "@angular/core";
|
|
2
|
-
import { ComponentFixture, fakeAsync, TestBed, waitForAsync } from "@angular/core/testing";
|
|
3
|
-
import { Subject } from "rxjs";
|
|
4
|
-
import { ClickEmitterDirective, ClickSubjectDirective } from "../utilities";
|
|
5
|
-
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
|
|
6
|
-
import {HarnessLoader} from '@angular/cdk/testing';
|
|
7
|
-
import { MatButtonModule } from "@angular/material/button";
|
|
8
|
-
import { MatButtonHarness } from "@angular/material/button/testing";
|
|
9
|
-
|
|
10
|
-
@Component({
|
|
11
|
-
template: `
|
|
12
|
-
<a mat-button clickEmitter #subj='clickEmitter' >click me</a>
|
|
13
|
-
<div *ngIf='subj | async'>Hello World!</div>
|
|
14
|
-
`
|
|
15
|
-
}) export class TestComponent {
|
|
16
|
-
subject = new Subject();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
@Component({
|
|
20
|
-
template: `
|
|
21
|
-
<a mat-button [clickSubject]='{content: "Hello World!" }' #subj='clickSubject' >click me</a>
|
|
22
|
-
<div *ngIf='subj | async as o'>{{o.content}}</div>
|
|
23
|
-
`
|
|
24
|
-
}) export class TestContentComponent {
|
|
25
|
-
subject = new Subject();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
let fixture: ComponentFixture<TestComponent>;
|
|
30
|
-
let loader: HarnessLoader;
|
|
31
|
-
|
|
32
|
-
const setupTest = (): void => {
|
|
33
|
-
TestBed.configureTestingModule({
|
|
34
|
-
imports: [MatButtonModule],
|
|
35
|
-
declarations: [
|
|
36
|
-
TestComponent,
|
|
37
|
-
ClickEmitterDirective,
|
|
38
|
-
],
|
|
39
|
-
providers: [ ]
|
|
40
|
-
});
|
|
41
|
-
fixture = TestBed.createComponent(TestComponent);
|
|
42
|
-
fixture.detectChanges();
|
|
43
|
-
loader = TestbedHarnessEnvironment.documentRootLoader(fixture);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const setupContentTest = (): void => {
|
|
47
|
-
TestBed.configureTestingModule({
|
|
48
|
-
imports: [MatButtonModule],
|
|
49
|
-
declarations: [
|
|
50
|
-
TestContentComponent,
|
|
51
|
-
ClickSubjectDirective,
|
|
52
|
-
],
|
|
53
|
-
providers: [ ]
|
|
54
|
-
});
|
|
55
|
-
fixture = TestBed.createComponent(TestContentComponent);
|
|
56
|
-
fixture.detectChanges();
|
|
57
|
-
loader = TestbedHarnessEnvironment.documentRootLoader(fixture);
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
describe("ClickSubjectDirective", () => {
|
|
62
|
-
describe("Default Subject", () => {
|
|
63
|
-
beforeEach(waitForAsync(setupTest));
|
|
64
|
-
|
|
65
|
-
it('before button is clicked the text should remain hidden',async () => {
|
|
66
|
-
expect(fixture.nativeElement.textContent).not.toContain('Hello World!');
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('when button is clicked the text should display', fakeAsync( async () => {
|
|
70
|
-
const buttonHarness = await loader.getHarness(MatButtonHarness);
|
|
71
|
-
await buttonHarness.click();
|
|
72
|
-
fixture.detectChanges();
|
|
73
|
-
expect(fixture.nativeElement.textContent).toContain('Hello World!');
|
|
74
|
-
}));
|
|
75
|
-
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
describe("Subject with Content", () => {
|
|
79
|
-
beforeEach(waitForAsync(setupContentTest));
|
|
80
|
-
|
|
81
|
-
it('before button is clicked the text should remain hidden',async () => {
|
|
82
|
-
expect(fixture.nativeElement.textContent).not.toContain('Hello World!');
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('when button is clicked the text should display', fakeAsync( async () => {
|
|
86
|
-
const buttonHarness = await loader.getHarness(MatButtonHarness);
|
|
87
|
-
await buttonHarness.click();
|
|
88
|
-
fixture.detectChanges();
|
|
89
|
-
expect(fixture.nativeElement.textContent).toContain('Hello World!');
|
|
90
|
-
}));
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
|