Skip to content
This repository was archived by the owner on May 24, 2022. It is now read-only.

Commit 6f8f40c

Browse files
authored
refactoring (#229)
1 parent 58c57fb commit 6f8f40c

File tree

77 files changed

+2003
-672
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+2003
-672
lines changed

.eslintrc.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extends: '@angular-ru/eslint-config'
3+
};

.eslintrc.json

-117
This file was deleted.

.travis.yml

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
sudo: required
2-
dist: trusty
3-
41
language: node_js
2+
sudo: false
53
node_js:
6-
- '12'
4+
- '12.0.0'
75

86
cache:
97
directories:
@@ -20,5 +18,5 @@ script:
2018
- yarn test:types
2119

2220
after_success:
23-
- test $TRAVIS_BRANCH = "master" && yarn coverage
24-
- test $TRAVIS_BRANCH = "master" && yarn deploy
21+
- test $TRAVIS_PULL_REQUEST == "false" && test $TRAVIS_BRANCH == "master" && yarn coverage
22+
- test $TRAVIS_PULL_REQUEST == "false" && test $TRAVIS_BRANCH == "master" && yarn deploy

docs/pages/persistence-state.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
```ts
44
import { NgxsDataPluginModule } from '@ngxs-labs/data';
5-
import { NGXS_DATA_STORAGE_CONTAINER, NGXS_DATA_STORAGE_EXTENSION } from '@ngxs-labs/data/storage';
5+
import { NGXS_DATA_STORAGE_PLUGIN } from '@ngxs-labs/data/storage';
66

77
@NgModule({
88
// ..
99
imports: [
1010
NgxsModule.forRoot([TodoState]),
11-
NgxsDataPluginModule.forRoot([NGXS_DATA_STORAGE_EXTENSION, NGXS_DATA_STORAGE_CONTAINER])
11+
NgxsDataPluginModule.forRoot([NGXS_DATA_STORAGE_PLUGIN])
1212
]
1313
})
1414
export class AppModule {}

integration/app/app-routing.module.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { NgModule } from '@angular/core';
22
import { RouterModule } from '@angular/router';
33

4+
import { CountModule } from './examples/count/count.module';
5+
import { TodoModule } from './examples/todo/todo.module';
6+
47
@NgModule({
58
imports: [
69
RouterModule.forRoot(
@@ -12,11 +15,17 @@ import { RouterModule } from '@angular/router';
1215
},
1316
{
1417
path: 'count',
15-
loadChildren: () => import('./examples/count/count.module').then((m) => m.CountModule)
18+
loadChildren: (): Promise<CountModule> =>
19+
import('./examples/count/count.module').then(
20+
(m: { CountModule: CountModule }): CountModule => m.CountModule
21+
)
1622
},
1723
{
1824
path: 'todo',
19-
loadChildren: () => import('./examples/todo/todo.module').then((m) => m.TodoModule)
25+
loadChildren: (): Promise<TodoModule> =>
26+
import('./examples/todo/todo.module').then(
27+
(m: { TodoModule: TodoModule }): TodoModule => m.TodoModule
28+
)
2029
}
2130
],
2231
{ useHash: true }

integration/app/app.component.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import { Observable } from 'rxjs';
88
changeDetection: ChangeDetectionStrategy.OnPush
99
})
1010
export class AppComponent implements OnInit {
11-
public snapshot: Observable<unknown> = this.store.select((state) => state);
11+
public snapshot: Observable<unknown> = this.store.select((state: unknown): unknown => state);
1212

1313
constructor(private readonly store: Store) {}
1414

1515
public ngOnInit(): void {
16+
// eslint-disable-next-line no-console
1617
console.log('[isDevMode]', isDevMode());
1718
}
1819
}

integration/app/examples/count/count-sub.state.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { Injectable } from '@angular/core';
22
import { Persistence, StateRepository } from '@ngxs-labs/data/decorators';
3+
import { PersistenceProvider } from '@ngxs-labs/data/typings';
34
import { State } from '@ngxs/store';
45

56
import { CountModel } from './count.model';
67

7-
const options = [{ path: 'count.countSub.val', existingEngine: sessionStorage }];
8+
const options: PersistenceProvider[] = [{ path: 'count.countSub.val', existingEngine: sessionStorage }];
89

910
@Persistence(options)
1011
@StateRepository()

integration/app/examples/count/count.state.ts

+22-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Observable } from 'rxjs';
77
import { map } from 'rxjs/operators';
88

99
import { CountSubState } from './count-sub.state';
10-
import { ParentCountModel } from './count.model';
10+
import { CountModel, ParentCountModel } from './count.model';
1111

1212
const COUNT_TOKEN: StateToken<ParentCountModel> = new StateToken<ParentCountModel>('count');
1313

@@ -19,28 +19,41 @@ const COUNT_TOKEN: StateToken<ParentCountModel> = new StateToken<ParentCountMode
1919
})
2020
@Injectable()
2121
export class CountState extends NgxsDataRepository<ParentCountModel> {
22-
public readonly values$: Observable<ParentCountModel> = this.state$.pipe(map((state) => state.countSub!));
22+
public readonly values$: Observable<ParentCountModel> = this.state$.pipe(
23+
map((state: Immutable<ParentCountModel>): CountModel => state.countSub!)
24+
);
2325

2426
@action()
2527
public increment(): void {
26-
this.ctx.setState((state: Immutable<ParentCountModel>) => ({ ...state, val: state.val + 1 }));
28+
this.ctx.setState(
29+
(state: Immutable<ParentCountModel>): Immutable<ParentCountModel> => ({ ...state, val: state.val + 1 })
30+
);
2731
}
2832

2933
@action()
3034
public countSubIncrement(): void {
31-
this.ctx.setState((state) => ({
32-
...state,
33-
countSub: { val: state.countSub!.val + 1 }
34-
}));
35+
this.ctx.setState(
36+
(state: Immutable<ParentCountModel>): Immutable<ParentCountModel> => ({
37+
...state,
38+
countSub: { val: state.countSub!.val + 1 }
39+
})
40+
);
3541
}
3642

3743
@action()
3844
public decrement(): void {
39-
this.setState((state) => ({ ...state, val: state.val - 1 }));
45+
this.setState(
46+
(state: Immutable<ParentCountModel>): Immutable<ParentCountModel> => ({ ...state, val: state.val - 1 })
47+
);
4048
}
4149

4250
@action({ async: true, debounce: 300 })
4351
public setValueFromInput(val: string | number): void {
44-
this.ctx.setState((state) => ({ ...state, val: parseFloat(val as string) || 0 }));
52+
this.ctx.setState(
53+
(state: Immutable<ParentCountModel>): Immutable<ParentCountModel> => ({
54+
...state,
55+
val: parseFloat(val as string) || 0
56+
})
57+
);
4558
}
4659
}

integration/app/examples/todo/todo.state.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ export class TodoState extends NgxsDataRepository<string[]> {
1515
@action()
1616
public addTodo(todo: string): void {
1717
if (todo) {
18-
this.ctx.setState((state: Immutable<string[]>) => state.concat(todo));
18+
this.ctx.setState((state: Immutable<string[]>): Immutable<string[]> => state.concat(todo));
1919
}
2020
}
2121

2222
@action()
2323
public removeTodo(idx: number): void {
24-
this.ctx.setState((state: Immutable<string[]>) => state.filter((_: string, index: number) => index !== idx));
24+
this.ctx.setState(
25+
(state: Immutable<string[]>): Immutable<string[]> =>
26+
state.filter((_: string, index: number): boolean => index !== idx)
27+
);
2528
}
2629
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export const environment = {
1+
export const environment: { production: boolean } = {
22
production: true
33
};

integration/environments/environment.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// `ng build ---prod` replaces `environment.ts` with `environment.prod.ts`.
33
// The list of file replacements can be found in `angular.json`.
44

5-
export const environment = {
5+
export const environment: { production: boolean } = {
66
production: false
77
};
88

integration/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ if (environment.production) {
1010

1111
platformBrowserDynamic()
1212
.bootstrapModule(AppModule)
13-
.catch((err) => console.log(err));
13+
.catch((err: Error): void => console.error(err));

jest.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = {
1212
preset: 'jest-preset-angular',
1313
rootDir: path.resolve('.'),
1414
testMatch: ['<rootDir>/**/*.spec.ts'],
15-
collectCoverageFrom: ['<rootDir>/src/**/*.ts'],
15+
collectCoverageFrom: ['<rootDir>/lib/**/*.ts'],
1616
setupFilesAfterEnv: ['<rootDir>/setupJest.ts'],
1717
coverageReporters: ['json', 'lcovonly', 'lcov', 'text', 'html'],
1818
coveragePathIgnorePatterns: ['/node_modules/'],

lib/decorators/src/action/action.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable */
12
import { $args, actionNameCreator, NgxsDataFactory, NgxsDataInjector } from '@ngxs-labs/data/internals';
23
import { NGXS_DATA_EXCEPTIONS, REPOSITORY_ACTION_OPTIONS } from '@ngxs-labs/data/tokens';
34
import {
@@ -34,7 +35,7 @@ export function action(options: RepositoryActionOptions = REPOSITORY_ACTION_OPTI
3435
descriptor.value = function() {
3536
const instance: DataRepository<Any> = (this as Any) as DataRepository<Any>;
3637

37-
let result: Any | Observable<Any> = undefined;
38+
let result: Any | Observable<Any>;
3839
const args: IArguments = arguments;
3940
const repository: NgxsRepositoryMeta = NgxsDataFactory.getRepositoryByInstance(instance);
4041
const operations: PlainObjectOf<NgxsDataOperation> | null = (repository && repository.operations) || null;
@@ -119,7 +120,9 @@ export function action(options: RepositoryActionOptions = REPOSITORY_ACTION_OPTI
119120

120121
return source.pipe(
121122
debounceTime(debounce),
122-
finalize(() => scheduleTask && scheduleTask.complete())
123+
finalize((): void => {
124+
scheduleTask && scheduleTask.complete();
125+
})
123126
);
124127
} else {
125128
const dispatcher: Observable<Any> = NgxsDataInjector.store!.dispatch(event);

0 commit comments

Comments
 (0)