Skip to content

Commit 91c6585

Browse files
committed
chore: add prettier and format files
1 parent 117cbb1 commit 91c6585

Some content is hidden

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

63 files changed

+1012
-1046
lines changed

.github/workflows/test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ jobs:
1010
- uses: actions/checkout@v4
1111
- uses: actions/setup-node@v4
1212
with:
13-
node-version: '20.x'
14-
cache: 'yarn'
13+
node-version: "20.x"
14+
cache: "yarn"
1515

1616
- name: Install packages
1717
run: yarn install

angular.json

+4-13
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,9 @@
2727
"test": {
2828
"builder": "@angular-devkit/build-angular:jest",
2929
"options": {
30-
"exclude": [
31-
"**/schematics/ng-add/*.spec.ts"
32-
],
30+
"exclude": ["**/schematics/ng-add/*.spec.ts"],
3331
"tsConfig": "projects/angular-redux/tsconfig.spec.json",
34-
"polyfills": [
35-
"zone.js",
36-
"zone.js/testing"
37-
]
32+
"polyfills": ["zone.js", "zone.js/testing"]
3833
}
3934
}
4035
}
@@ -79,19 +74,15 @@
7974
"outputPath": "dist/angular-redux-demo",
8075
"index": "projects/angular-redux-demo/src/index.html",
8176
"browser": "projects/angular-redux-demo/src/main.ts",
82-
"polyfills": [
83-
"zone.js"
84-
],
77+
"polyfills": ["zone.js"],
8578
"tsConfig": "projects/angular-redux-demo/tsconfig.app.json",
8679
"assets": [
8780
{
8881
"glob": "**/*",
8982
"input": "projects/angular-redux-demo/public"
9083
}
9184
],
92-
"styles": [
93-
"projects/angular-redux-demo/src/styles.css"
94-
],
85+
"styles": ["projects/angular-redux-demo/src/styles.css"],
9586
"scripts": []
9687
},
9788
"configurations": {

docs/introduction/getting-started.md

+20-27
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ id: getting-started
33
title: Getting Started with Angular Redux
44
hide_title: true
55
sidebar_label: Getting Started
6-
description: 'Introduction > Getting Started: First steps with Angular Redux'
6+
description: "Introduction > Getting Started: First steps with Angular Redux"
77
---
88

99
# Getting Started with Angular Redux
@@ -25,9 +25,9 @@ ng add @reduxjs/angular-redux@latest
2525
#### Optional `ng add` flags
2626

2727
| flag | description | value type | default value |
28-
|---------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------|---------------|
29-
| `--path` | Path to the module that you wish to add the import for the `provideRedux` to. | `string` ||
30-
| `--project` | Name of the project defined in your `angular.json` to help locating the module to add the `provideRedux` to. | `string` ||
28+
| ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | ------------- |
29+
| `--path` | Path to the module that you wish to add the import for the `provideRedux` to. | `string` | |
30+
| `--project` | Name of the project defined in your `angular.json` to help locating the module to add the `provideRedux` to. | `string` | |
3131
| `--module` | Name of file containing the module that you wish to add the import for the `provideRedux` to. Can also include the relative path to the file. For example, `src/app/app.module.ts`. | `string` | `app` |
3232
| `--storePath` | The file path to create the state in. | `string` | `store` |
3333

@@ -50,7 +50,6 @@ npm install @reduxjs/angular-redux
5050
yarn add @reduxjs/angular-redux
5151
```
5252

53-
5453
You'll also need to [install Redux](https://redux.js.org/introduction/installation) and [set up a Redux store](https://redux.js.org/recipes/configuring-your-store/) in your app.
5554

5655
Angular-Redux is written in TypeScript, so all types are automatically included.
@@ -62,15 +61,13 @@ Angular-Redux is written in TypeScript, so all types are automatically included.
6261
Angular Redux includes a `provideRedux` provider factory, which makes the Redux store available to the rest of your app:
6362

6463
```typescript
65-
import { bootstrapApplication } from '@angular/platform-browser';
64+
import { bootstrapApplication } from "@angular/platform-browser";
6665
import { provideRedux } from "angular-redux";
67-
import { AppComponent } from './app/app.component';
68-
import { store } from './store'
66+
import { AppComponent } from "./app/app.component";
67+
import { store } from "./store";
6968

7069
bootstrapApplication(AppComponent, {
71-
providers: [
72-
provideRedux({ store })
73-
]
70+
providers: [provideRedux({ store })],
7471
});
7572
```
7673

@@ -81,29 +78,25 @@ Angular Redux provides a pair of custom Angular injectable functions that allow
8178
`injectSelector` reads a value from the store state and subscribes to updates, while `injectDispatch` returns the store's `dispatch` method to let you dispatch actions.
8279

8380
```typescript
84-
import { Component } from '@angular/core'
81+
import { Component } from "@angular/core";
8582
import { injectSelector, injectDispatch } from "@reduxjs/angular-redux";
86-
import { decrement, increment } from './store/counter-slice'
87-
import { RootState } from './store'
83+
import { decrement, increment } from "./store/counter-slice";
84+
import { RootState } from "./store";
8885

8986
@Component({
90-
selector: 'app-root',
87+
selector: "app-root",
9188
standalone: true,
9289
template: `
93-
<button (click)="dispatch(increment())">
94-
Increment
95-
</button>
96-
<span>{{ count() }}</span>
97-
<button (click)="dispatch(decrement())">
98-
Decrement
99-
</button>
100-
`
90+
<button (click)="dispatch(increment())">Increment</button>
91+
<span>{{ count() }}</span>
92+
<button (click)="dispatch(decrement())">Decrement</button>
93+
`,
10194
})
10295
export class AppComponent {
103-
count = injectSelector((state: RootState) => state.counter.value)
104-
dispatch = injectDispatch()
105-
increment = increment
106-
decrement = decrement
96+
count = injectSelector((state: RootState) => state.counter.value);
97+
dispatch = injectDispatch();
98+
increment = increment;
99+
decrement = decrement;
107100
}
108101
```
109102

docs/tutorials/quick-start.md

+30-35
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ npm install @reduxjs/toolkit angular-redux
4848
Create a file named `src/app/store.ts`. Import the `configureStore` API from Redux Toolkit. We'll start by creating an empty Redux store, and exporting it:
4949

5050
```typescript title="app/store.ts"
51-
import { configureStore } from '@reduxjs/toolkit'
51+
import { configureStore } from "@reduxjs/toolkit";
5252

5353
export default configureStore({
5454
reducer: {},
55-
})
55+
});
5656
```
5757

5858
This creates a Redux store, and also automatically configure the Redux DevTools extension so that you can inspect the store while developing.
@@ -62,19 +62,18 @@ This creates a Redux store, and also automatically configure the Redux DevTools
6262
Once the store is created, we can make it available to our Angular components by putting an Angular Redux `provideRedux` in our application's `providers` array in `src/main.ts`. Import the Redux store we just created, put a `provideRedux` in your application's `providers` array, and pass the store as a prop:
6363

6464
```typescript title="main.ts"
65-
66-
import { bootstrapApplication } from '@angular/platform-browser';
67-
import { AppComponent } from './app/app.component';
65+
import { bootstrapApplication } from "@angular/platform-browser";
66+
import { AppComponent } from "./app/app.component";
6867
// highlight-start
6968
import { provideRedux } from "angular-redux";
70-
import { store } from './store'
69+
import { store } from "./store";
7170
// highlight-end
7271

7372
bootstrapApplication(AppComponent, {
7473
providers: [
7574
// highlight-next-line
76-
provideRedux({ store })
77-
]
75+
provideRedux({ store }),
76+
],
7877
});
7978
```
8079

@@ -87,10 +86,10 @@ Creating a slice requires a string name to identify the slice, an initial state
8786
Redux requires that [we write all state updates immutably, by making copies of data and updating the copies](https://redux.js.org/tutorials/fundamentals/part-2-concepts-data-flow#immutability). However, Redux Toolkit's `createSlice` and `createReducer` APIs use [Immer](https://immerjs.github.io/immer/) inside to allow us to [write "mutating" update logic that becomes correct immutable updates](https://redux.js.org/tutorials/fundamentals/part-8-modern-redux#immutable-updates-with-immer).
8887

8988
```js title="features/counter/counterSlice.ts"
90-
import { createSlice } from '@reduxjs/toolkit'
89+
import { createSlice } from "@reduxjs/toolkit";
9190

9291
export const counterSlice = createSlice({
93-
name: 'counter',
92+
name: "counter",
9493
initialState: {
9594
value: 0,
9695
},
@@ -101,68 +100,64 @@ export const counterSlice = createSlice({
101100
// which detects changes to a "draft state" and produces a brand new
102101
// immutable state based off those changes.
103102
// Also, no return statement is required from these functions.
104-
state.value += 1
103+
state.value += 1;
105104
},
106105
decrement: (state) => {
107-
state.value -= 1
106+
state.value -= 1;
108107
},
109108
incrementByAmount: (state, action) => {
110-
state.value += action.payload
109+
state.value += action.payload;
111110
},
112111
},
113-
})
112+
});
114113

115114
// Action creators are generated for each case reducer function
116-
export const { increment, decrement, incrementByAmount } = counterSlice.actions
115+
export const { increment, decrement, incrementByAmount } = counterSlice.actions;
117116

118-
export default counterSlice.reducer
117+
export default counterSlice.reducer;
119118
```
120119

121120
### Add Slice Reducers to the Store
122121

123122
Next, we need to import the reducer function from the counter slice and add it to our store. By defining a field inside the `reducer` parameter, we tell the store to use this slice reducer function to handle all updates to that state.
124123

125124
```js title="app/store.ts"
126-
import { configureStore } from '@reduxjs/toolkit'
125+
import { configureStore } from "@reduxjs/toolkit";
127126
// highlight-next-line
128-
import counterReducer from '../features/counter/counterSlice'
127+
import counterReducer from "../features/counter/counterSlice";
129128

130129
export default configureStore({
131130
reducer: {
132131
// highlight-next-line
133132
counter: counterReducer,
134133
},
135-
})
134+
});
136135
```
137136

138137
### Use Redux State and Actions in Angular Components
139138

140139
Now we can use the Angular Redux inject functions to let Angular components interact with the Redux store. We can read data from the store with `useSelector`, and dispatch actions using `useDispatch`. Create a `src/features/counter/counter.component.ts` file with a `<app-counter>` component inside, then import that component into `app.component.ts` and render it inside of `<app-root>`.
141140

142141
```typescript title="features/counter/counter.component.ts"
143-
import { Component } from '@angular/core'
142+
import { Component } from "@angular/core";
144143
import { injectSelector, injectDispatch } from "@reduxjs/angular-redux";
145-
import { decrement, increment } from './store/counter-slice'
146-
import { RootState } from './store'
144+
import { decrement, increment } from "./store/counter-slice";
145+
import { RootState } from "./store";
147146

148147
@Component({
149-
selector: 'app-counter',
148+
selector: "app-counter",
150149
standalone: true,
151150
template: `
152-
<button (click)="dispatch(increment())">
153-
Increment
154-
</button>
155-
<span>{{ count() }}</span>
156-
<button (click)="dispatch(decrement())">
157-
Decrement
158-
</button>
159-
`
151+
<button (click)="dispatch(increment())">Increment</button>
152+
<span>{{ count() }}</span>
153+
<button (click)="dispatch(decrement())">Decrement</button>
154+
`,
160155
})
161156
export class CounterComponent {
162-
count = injectSelector((state: RootState) => state.counter.value)
163-
dispatch = injectDispatch()
164-
increment = increment
165-
decrement = decrement
157+
count = injectSelector((state: RootState) => state.counter.value);
158+
dispatch = injectDispatch();
159+
increment = increment;
160+
decrement = decrement;
166161
}
167162
```
168163

0 commit comments

Comments
 (0)