Skip to content

Commit abb2b85

Browse files
authored
fix(ngxs): upgrade to NGXS 18.1.3 (#1527)
1 parent f075c16 commit abb2b85

File tree

19 files changed

+84
-51
lines changed

19 files changed

+84
-51
lines changed

libs/ngxs/decorators/data-action/data-action.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ import {
1717
DataStateClass,
1818
DispatchedResult,
1919
ImmutableDataRepository,
20+
type MappedStore,
2021
NgxsDataOperation,
2122
NgxsRepositoryMeta,
2223
RepositoryActionOptions,
2324
} from '@angular-ru/ngxs/typings';
24-
import {MappedStore} from '@ngxs/store/src/internal/internals';
2525
import {isObservable, Observable, of} from 'rxjs';
2626
import {map} from 'rxjs/operators';
2727

@@ -48,11 +48,12 @@ export function DataAction(options: RepositoryActionOptions = {}): MethodDecorat
4848
NgxsDataFactory.getRepositoryByInstance(instance);
4949
const operations: PlainObjectOf<NgxsDataOperation> = repository.operations!;
5050
let operation: NgxsDataOperation | undefined = operations[key];
51+
const operationNotSet = isNil(operation);
5152
const stateMeta: any = repository.stateMeta;
5253
const registry: MethodArgsRegistry | undefined =
5354
getMethodArgsRegistry(originalMethod);
5455

55-
if (isNil(operation)) {
56+
if (operationNotSet) {
5657
// Note: late init operation when first invoke action method
5758
const argumentsNames: string[] = $args(originalMethod);
5859
const type: string = actionNameCreator({
@@ -67,15 +68,13 @@ export function DataAction(options: RepositoryActionOptions = {}): MethodDecorat
6768
options: {cancelUncompleted: config.cancelUncompleted ?? false},
6869
};
6970

70-
if (isNotNil(operation)) {
71-
stateMeta.actions[operation.type] = [
72-
{
73-
type: operation.type,
74-
options: operation.options,
75-
fn: operation.type,
76-
},
77-
];
78-
}
71+
stateMeta.actions[operation.type] = [
72+
{
73+
type: operation.type,
74+
options: operation.options,
75+
fn: operation.type,
76+
},
77+
];
7978
}
8079

8180
const mapped: MappedStore = NgxsDataFactory.ensureMappedState(stateMeta)!;
@@ -98,8 +97,19 @@ export function DataAction(options: RepositoryActionOptions = {}): MethodDecorat
9897
: result;
9998
};
10099

100+
if (operationNotSet) {
101+
const factory = NgxsDataInjector.factory!;
102+
103+
factory.hydrateActionMetasMap({
104+
...mapped,
105+
actions: {
106+
[operation.type]: mapped.actions[operation.type],
107+
},
108+
});
109+
}
110+
101111
const event: ActionEvent = NgxsDataFactory.createAction(
102-
operation,
112+
operation.type,
103113
args,
104114
registry,
105115
);

libs/ngxs/internals/services/ngxs-data-factory.service.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ import {
66
ActionEvent,
77
DataStateClass,
88
MappedState,
9-
NgxsDataOperation,
9+
MappedStore,
1010
NgxsRepositoryMeta,
1111
PayloadName,
1212
} from '@angular-ru/ngxs/typings';
1313
import {StateContext} from '@ngxs/store';
14-
import {MappedStore} from '@ngxs/store/src/internal/internals';
1514

1615
import {dynamicActionByType} from '../utils/action/dynamic-action';
1716
import {MethodArgsRegistry} from '../utils/method-args-registry/method-args-registry';
@@ -26,8 +25,8 @@ export class NgxsDataFactory {
2625
NgxsDataFactory.statesCachedMeta.clear();
2726
}
2827

29-
public static createStateContext<T>(metadata: MappedStore): StateContext<T> {
30-
return NgxsDataInjector.context.createStateContext(metadata);
28+
public static createStateContext<T>(path: string): StateContext<T> {
29+
return NgxsDataInjector.context.createStateContext(path);
3130
}
3231

3332
public static ensureMappedState(stateMeta: any | undefined): MappedState | never {
@@ -93,22 +92,22 @@ export class NgxsDataFactory {
9392
}
9493

9594
public static createAction(
96-
operation: NgxsDataOperation,
95+
type: string,
9796
args: any[],
9897
registry?: MethodArgsRegistry,
9998
): ActionEvent {
10099
const payload: PlainObjectOf<any> | null = NgxsDataFactory.createPayload(
101100
args,
102101
registry,
103102
);
104-
const dynamicActionByTypeFactory: Type<any> = dynamicActionByType(operation.type);
103+
const dynamicActionByTypeFactory: Type<any> = dynamicActionByType(type);
105104

106105
return new dynamicActionByTypeFactory(payload);
107106
}
108107

109108
private static ensureMeta(stateMeta: any): MappedStore | null | undefined {
110109
const meta: MappedState = isNotNil(stateMeta.name)
111-
? (NgxsDataInjector.factory.states as MappedStore[])?.find(
110+
? NgxsDataInjector.factory!.states?.find(
112111
(state: MappedStore): boolean => state.name === stateMeta.name,
113112
)
114113
: null;

libs/ngxs/internals/services/ngxs-data-injector.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {Inject, Injectable, Injector, NgZone} from '@angular/core';
2+
import type {StateFactory} from '@angular-ru/ngxs/typings';
23
import {Store} from '@ngxs/store';
34
import {
45
ɵNGXS_STATE_CONTEXT_FACTORY as NGXS_STATE_CONTEXT_FACTORY,
@@ -12,7 +13,7 @@ export class NgxsDataInjector {
1213
public static store: Store | null = null;
1314
public static computed: NgxsDataSequence | null = null;
1415
public static context: any | null = null;
15-
public static factory: any | null = null;
16+
public static factory: StateFactory | null = null;
1617
public static ngZone: NgZone | null = null;
1718
public static injector: Injector | null = null;
1819

libs/ngxs/internals/utils/state-context/create-context.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import {DataStateClass, NgxsRepositoryMeta} from '@angular-ru/ngxs/typings';
1+
import {DataStateClass, MappedStore, NgxsRepositoryMeta} from '@angular-ru/ngxs/typings';
22
import {StateContext} from '@ngxs/store';
3-
import {MappedStore} from '@ngxs/store/src/internal/internals';
43

54
import {NgxsDataFactory} from '../../services/ngxs-data-factory.service';
65
import {getRepository} from '../repository/get-repository';
@@ -15,7 +14,7 @@ export function createContext(stateClass: DataStateClass): PropertyDescriptor {
1514
meta.stateMeta,
1615
)!;
1716

18-
return NgxsDataFactory.createStateContext(mappedMeta);
17+
return NgxsDataFactory.createStateContext(mappedMeta.path);
1918
},
2019
};
2120
}

libs/ngxs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"license": "MIT",
99
"author": "angular-ru@yandex.ru",
1010
"peerDependencies": {
11-
"@ngxs/store": ">=18.0.0"
11+
"@ngxs/store": ">=18.1.3"
1212
},
1313
"publishConfig": {
1414
"access": "public"

libs/ngxs/storage/utils/rehydrate.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ export function rehydrate<T>(params: RehydrateInfoOptions<T>): RehydrateInfo {
2323
const prevData: T = getValue(states, path);
2424

2525
if (isTruthy(info.versionMismatch)) {
26-
const stateInstance: any = provider.stateInstance;
27-
const instance: NgxsDataMigrateStorage = stateInstance;
26+
const instance: NgxsDataMigrateStorage = provider.stateInstance;
2827
const migrateFn: MigrateFn =
2928
provider.migrate ??
3029
instance.ngxsDataStorageMigrate?.bind(provider.stateInstance);

libs/ngxs/testing/platform/ngxs-data-testing.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
NGXS_DATA_STORAGE_EXTENSION,
77
} from '@angular-ru/ngxs/storage';
88
import {NgxsModule} from '@ngxs/store';
9-
import {ɵStateClass as StateClass} from '@ngxs/store/internals/symbols';
9+
import {ɵStateClass as StateClass} from '@ngxs/store/internals';
1010

1111
import {createInternalNgxsRootElement} from './internal/create-internal-ngxs-root-element';
1212
import {NgxsAppMockModule} from './ngxs-app-mock.module';

libs/ngxs/testing/platform/ngxs-platform.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {TestBed, TestModuleMetadata} from '@angular/core/testing';
33
import {isNil} from '@angular-ru/cdk/utils';
44
import {getStateMetadata} from '@angular-ru/ngxs/internals';
55
import {Store} from '@ngxs/store';
6-
import {ɵStateClass as StateClass} from '@ngxs/store/internals/symbols';
6+
import {ɵStateClass as StateClass} from '@ngxs/store/internals';
77

88
import {TestSpec} from './internal/types';
99
import {NgxsDataTestingModule} from './ngxs-data-testing.module';

libs/ngxs/tests/common-extensions/action-decorator.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {NgxsModule, State} from '@ngxs/store';
1010
describe('[TEST]: Action decorator', () => {
1111
afterEach(() => TestBed.resetTestingModule());
1212

13-
it("don't should be working without @StateRepository decorator", () => {
13+
it('should not be working without @StateRepository decorator', () => {
1414
let message: string | null = null;
1515

1616
try {
@@ -41,7 +41,7 @@ describe('[TEST]: Action decorator', () => {
4141
expect(message).toEqual(NGXS_DATA_EXCEPTIONS.NGXS_DATA_STATE_DECORATOR);
4242
});
4343

44-
it.skip("don't should be working without @StateRepository and @State decorator", () => {
44+
it.skip('should not be working without @StateRepository and @State decorator', () => {
4545
let message: string | null = null;
4646

4747
try {
@@ -73,7 +73,7 @@ describe('[TEST]: Action decorator', () => {
7373
);
7474
});
7575

76-
it.skip("don't should be working without provided meta information", () => {
76+
it.skip('should not be working without provided meta information', () => {
7777
let message: string | null = null;
7878

7979
try {
@@ -104,7 +104,7 @@ describe('[TEST]: Action decorator', () => {
104104
expect(message).toEqual(NGXS_DATA_EXCEPTIONS.NGXS_DATA_STATE_DECORATOR);
105105
});
106106

107-
it.skip("don't should be working when register as service", () => {
107+
it.skip('should not be working when register as service', () => {
108108
let message: string | null = null;
109109

110110
try {

libs/ngxs/tests/common-extensions/state-context.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import {
99
} from '@angular-ru/ngxs/internals';
1010
import {NgxsImmutableDataRepository} from '@angular-ru/ngxs/repositories';
1111
import {NgxsModule, State, Store} from '@ngxs/store';
12-
import {MetaDataModel, SharedSelectorOptions} from '@ngxs/store/src/internal/internals';
12+
import {
13+
ɵMetaDataModel as MetaDataModel,
14+
ɵSharedSelectorOptions as SharedSelectorOptions,
15+
} from '@ngxs/store/internals';
1316
import {isObservable} from 'rxjs';
1417

1518
describe('[TEST]: Utils', () => {

0 commit comments

Comments
 (0)