Skip to content

Commit

Permalink
chore: format files after upgradinng to prettier@3
Browse files Browse the repository at this point in the history
No functional changes, only formatting. Making this change now because
newer versions of Prettier can correctly format the Angular control flow.
  • Loading branch information
arturovt committed Mar 10, 2024
1 parent dbed85b commit a836c51
Show file tree
Hide file tree
Showing 31 changed files with 142 additions and 77 deletions.
5 changes: 4 additions & 1 deletion docs/advanced/action-handlers.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ import { Actions, ofActionDispatched } from '@ngxs/store';

@Injectable({ providedIn: 'root' })
export class RouteHandler {
constructor(private router: Router, private actions$: Actions) {
constructor(
private router: Router,
private actions$: Actions
) {
this.actions$
.pipe(ofActionDispatched(RouteNavigate))
.subscribe(({ payload }) => this.router.navigate([payload]));
Expand Down
5 changes: 4 additions & 1 deletion docs/advanced/life-cycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,10 @@ export class VersionState {

@Injectable({ providedIn: 'root' })
export class ConfigService {
constructor(private http: HttpClient, private store: Store) {}
constructor(
private http: HttpClient,
private store: Store
) {}

loadVersion() {
return this.http.get<string>('/api/version').pipe(
Expand Down
5 changes: 4 additions & 1 deletion docs/advanced/sub-states.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ export interface CartStateModel {

export class SetCheckedoutAndItems {
static type = '[Cart] Set checkedout and items';
constructor(public checkedout: boolean, public items: CartItem[]) {}
constructor(
public checkedout: boolean,
public items: CartItem[]
) {}
}

@State<CartStateModel>({
Expand Down
5 changes: 4 additions & 1 deletion docs/concepts/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ Here we have an action that should trigger feeding a zebra with hay.
```ts
export class FeedZebra {
static readonly type = '[Zoo] Feed Zebra';
constructor(public name: string, public hayAmount: number) {}
constructor(
public name: string,
public hayAmount: number
) {}
}
```

Expand Down
5 changes: 4 additions & 1 deletion docs/plugins/websocket.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ look like:
```ts
export class AddMessage {
static type = '[Chat] Add message';
constructor(public from: string, public message: string) {}
constructor(
public from: string,
public message: string
) {}
}
```

Expand Down
5 changes: 4 additions & 1 deletion docs/recipes/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ the login page.
template: '..'
})
export class AppComponent implements OnInit {
constructor(private actions: Actions, private router: Router) {}
constructor(
private actions: Actions,
private router: Router
) {}

ngOnInit() {
this.actions.pipe(ofActionDispatched(Logout)).subscribe(() => {
Expand Down
5 changes: 4 additions & 1 deletion docs/recipes/component-events-from-ngxs.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ export class BooksComponent {
map((action: LoadBooks) => this.store.selectSnapshot(BooksState.getBooks(action.genre)))
);

constructor(private store: Store, private actions$: Actions) {}
constructor(
private store: Store,
private actions$: Actions
) {}
}
```

Expand Down
5 changes: 4 additions & 1 deletion docs/recipes/debouncing-actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export class NewsPortalComponent implements OnDestroy {

private destroy$ = new Subject<void>();

constructor(private store: Store, actions$: Actions) {
constructor(
private store: Store,
actions$: Actions
) {
actions$
.pipe(
ofActionDispatched(SearchNews),
Expand Down
5 changes: 4 additions & 1 deletion docs/recipes/immutability-helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ Let's imagine that we're faced with the task of changing the `dueDate` property:
```ts
export class UpdateDueDate {
static readonly type = '[Trello] Update due date';
constructor(public taskId: string, public dueDate: string) {}
constructor(
public taskId: string,
public dueDate: string
) {}
}
```

Expand Down
5 changes: 4 additions & 1 deletion docs/recipes/intregration-with-rxangular.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ export class HeroesComponent {
readonly add = new Subject<string>();
readonly delete = new Subject<Hero>();

constructor(private state: RxState<HeroesComponentState>, private store: Store) {
constructor(
private state: RxState<HeroesComponentState>,
private store: Store
) {
this.state.hold(
// <--- RxAngular hold will manage the subscription for us
this.add.pipe(switchMap(name => this.store.dispatch(new AddHero(name)))) // <--- dispatch action to NGXS
Expand Down
5 changes: 4 additions & 1 deletion docs/recipes/style-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ This also applies to the usage of data collections such as Set, Map, WeakMap, We

```ts
export class Todo {
constructor(public title: string, public isCompleted = false) {}
constructor(
public title: string,
public isCompleted = false
) {}
}

@State<Todo[]>({
Expand Down
5 changes: 4 additions & 1 deletion integration/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ export class AppComponent implements OnInit {
injected$: Observable<string> = this._store.select(TodosState.getInjected);
injected: Signal<string> = this._store.selectSignal(TodosState.getInjected);

constructor(private _store: Store, private _fb: FormBuilder) {}
constructor(
private _store: Store,
private _fb: FormBuilder
) {}

get extras(): FormControl[] {
const extras = this.pizzaForm.get('extras') as FormArray;
Expand Down
2 changes: 1 addition & 1 deletion integration/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
Expand Down
6 changes: 5 additions & 1 deletion integration/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ html {
height: 100%;
display: flex;
background: #f5f5f5;
font: 14px 'Helvetica Neue', Helvetica, Arial, sans-serif;
font:
14px 'Helvetica Neue',
Helvetica,
Arial,
sans-serif;
line-height: 1.4em;
color: #4d4d4d;
min-width: 230px;
Expand Down
2 changes: 1 addition & 1 deletion integrations/hello-world-ng16/src/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
Expand Down
2 changes: 1 addition & 1 deletion integrations/hello-world-ng17/src/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
Expand Down
4 changes: 2 additions & 2 deletions packages/form-plugin/src/form.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export class NgxsFormPlugin implements NgxsPlugin {
const payloadValue = Array.isArray(value)
? value.slice()
: isObjectLike(value)
? { ...value }
: value;
? { ...value }
: value;
const path = this.joinPathWithPropertyPath(event);
nextState = setValue(nextState, path, payloadValue);
}
Expand Down
6 changes: 5 additions & 1 deletion packages/logger-plugin/src/action-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { formatTime } from './internals';
import { LogWriter } from './log-writer';

export class ActionLogger {
constructor(private action: any, private store: Store, private logWriter: LogWriter) {}
constructor(
private action: any,
private store: Store,
private logWriter: LogWriter
) {}

dispatched(state: any) {
const actionName = getActionTypeFromInstance(this.action);
Expand Down
5 changes: 2 additions & 3 deletions packages/router-plugin/tests/issues/issue-1293.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ describe('#1293 issue', () => {
'should not infinitely redirect because of reverted snapshot',
freshPlatform(async () => {
// Assert
const { router, injector, ngZone } = await createNgxsRouterPluginTestingPlatform(
getTestModule()
);
const { router, injector, ngZone } =
await createNgxsRouterPluginTestingPlatform(getTestModule());

// Act
await ngZone.run(() => router.navigateByUrl('/'));
Expand Down
5 changes: 2 additions & 3 deletions packages/router-plugin/tests/router-cancel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ describe('RouterCancel', () => {
'should persist the previous state if the "RouterCancel" action is dispatched',
freshPlatform(async () => {
// Arrange
const { router, store, ngZone } = await createNgxsRouterPluginTestingPlatform(
getTestModule()
);
const { router, store, ngZone } =
await createNgxsRouterPluginTestingPlatform(getTestModule());

let navigationCancelEmittedTimes = 0;

Expand Down
29 changes: 16 additions & 13 deletions packages/storage-plugin/src/storage.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,22 @@ export class NgxsStoragePlugin implements NgxsPlugin {
// will rehydrate the entire state when the `RouterState` is registered.
// Consequently, the `counter` state will revert back to `10` instead of `999`.
if (storedValue && addedStates && Object.keys(addedStates).length > 0) {
storedValue = Object.keys(addedStates).reduce((accumulator, addedState) => {
// The `storedValue` can be equal to the entire state when the default
// state key is used. However, if `addedStates` only contains the `router` value,
// we only want to merge the state with the `router` value.
// Let's assume that the `storedValue` is an object:
// `{ counter: 10, router: {...} }`
// This will pick only the `router` object from the `storedValue` and `counter`
// state will not be rehydrated unnecessary.
if (storedValue.hasOwnProperty(addedState)) {
accumulator[addedState] = storedValue[addedState];
}
return accumulator;
}, <PlainObject>{});
storedValue = Object.keys(addedStates).reduce(
(accumulator, addedState) => {
// The `storedValue` can be equal to the entire state when the default
// state key is used. However, if `addedStates` only contains the `router` value,
// we only want to merge the state with the `router` value.
// Let's assume that the `storedValue` is an object:
// `{ counter: 10, router: {...} }`
// This will pick only the `router` object from the `storedValue` and `counter`
// state will not be rehydrated unnecessary.
if (storedValue.hasOwnProperty(addedState)) {
accumulator[addedState] = storedValue[addedState];
}
return accumulator;
},
<PlainObject>{}
);
}

state = { ...state, ...storedValue };
Expand Down
11 changes: 6 additions & 5 deletions packages/store/src/decorators/select/symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ export function removeDollarAtTheEnd(name: string): string {
return dollarAtTheEnd ? name.slice(0, lastCharIndex) : name;
}

export type PropertyType<T> = T extends StateToken<any>
? Observable<ExtractTokenType<T>>
: T extends (...args: any[]) => any
? Observable<ReturnType<T>>
: any;
export type PropertyType<T> =
T extends StateToken<any>
? Observable<ExtractTokenType<T>>
: T extends (...args: any[]) => any
? Observable<ReturnType<T>>
: any;
4 changes: 2 additions & 2 deletions packages/store/src/decorators/selector/symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { ExtractTokenType } from '../../state-token/symbols';
export type SelectorSpec<T, U> = [T] extends [never]
? (...states: any[]) => any
: T extends StateToken<any>
? (state: ExtractTokenType<T>) => U
: (...states: any[]) => any;
? (state: ExtractTokenType<T>) => U
: (...states: any[]) => any;

export type SelectorType<T> = <U>(
target: any,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import { getZoneWarningMessage } from '../configs/messages.config';

@Injectable({ providedIn: 'root' })
export class DispatchOutsideZoneNgxsExecutionStrategy implements NgxsExecutionStrategy {
constructor(private _ngZone: NgZone, @Inject(PLATFORM_ID) private _platformId: string) {
constructor(
private _ngZone: NgZone,
@Inject(PLATFORM_ID) private _platformId: string
) {
// Caretaker note: we have still left the `typeof` condition in order to avoid
// creating a breaking change for projects that still use the View Engine.
if (typeof ngDevMode === 'undefined' || ngDevMode) {
Expand Down
22 changes: 14 additions & 8 deletions packages/store/src/operators/of-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,21 @@ interface FilterMap {
}

function createAllowedActionTypesMap(types: ActionType[]): FilterMap {
return types.reduce((filterMap: FilterMap, klass: any) => {
filterMap[getActionTypeFromInstance(klass)!] = true;
return filterMap;
}, <FilterMap>{});
return types.reduce(
(filterMap: FilterMap, klass: any) => {
filterMap[getActionTypeFromInstance(klass)!] = true;
return filterMap;
},
<FilterMap>{}
);
}

function createAllowedStatusesMap(statuses: ActionStatus[]): FilterMap {
return statuses.reduce((filterMap: FilterMap, status: ActionStatus) => {
filterMap[status] = true;
return filterMap;
}, <FilterMap>{});
return statuses.reduce(
(filterMap: FilterMap, status: ActionStatus) => {
filterMap[status] = true;
return filterMap;
},
<FilterMap>{}
);
}
11 changes: 7 additions & 4 deletions packages/store/src/selectors/create-pick-selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ export function createPickSelector<TModel, Keys extends (keyof TModel)[]>(
const validKeys = keys.filter(Boolean);
const selectors = validKeys.map(key => createSelector([selector], (s: TModel) => s[key]));
return createSelector([...selectors], (...props: KeysToValues<TModel, Keys>) => {
return validKeys.reduce((acc, key, index) => {
acc[key] = props[index];
return acc;
}, {} as Pick<TModel, Keys[number]>);
return validKeys.reduce(
(acc, key, index) => {
acc[key] = props[index];
return acc;
},
{} as Pick<TModel, Keys[number]>
);
});
}
15 changes: 8 additions & 7 deletions packages/store/src/selectors/selector-types.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ export type StateSelector = ɵStateClass<any>;

export type SelectorDef<TModel> = StateSelector | TypedSelector<TModel>;

export type SelectorReturnType<T extends SelectorDef<any>> = T extends StateToken<infer R1>
? R1
: T extends SelectorFunc<infer R2>
? R2
: T extends ɵStateClass<any>
? any /* (Block comment to stop prettier breaking the comment below)
export type SelectorReturnType<T extends SelectorDef<any>> =
T extends StateToken<infer R1>
? R1
: T extends SelectorFunc<infer R2>
? R2
: T extends ɵStateClass<any>
? any /* (Block comment to stop prettier breaking the comment below)
// If the state selector is a class then we should infer its return type to `any`, and not to `unknown`.
// Since we'll get an error that `Type 'unknown' is not assignable to type 'AuthStateModel'.`
// The `unknown` type is not overridable when the strict mode is enabled:
Expand All @@ -26,4 +27,4 @@ export type SelectorReturnType<T extends SelectorDef<any>> = T extends StateToke
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Type 'unknown' is not assignable to type 'number'.
*/
: never;
: never;
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ describe('Actions stream causing ticks', () => {
template: '<button id="set-countries" (click)="setCountries()">Set countries</button>'
})
class TestComponent {
constructor(private _store: Store, actions$: Actions) {
constructor(
private _store: Store,
actions$: Actions
) {
// Create 10 subscriptions in a row.
Array.from({ length: 10 }).forEach(() => {
actions$.pipe(ofActionSuccessful(SetCountries)).subscribe();
Expand Down
Loading

0 comments on commit a836c51

Please sign in to comment.