Skip to content

Commit 1af10a0

Browse files
committed
chore: initial scaffolding for the project
1 parent 1b1f982 commit 1af10a0

15 files changed

+187
-74
lines changed

package-lock.json

Lines changed: 52 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
"@angular/platform-browser": "^18.2.0",
1919
"@angular/platform-browser-dynamic": "^18.2.0",
2020
"@angular/router": "^18.2.0",
21+
"@reduxjs/toolkit": "^2.2.7",
22+
"redux": "^5.0.1",
2123
"rxjs": "~7.8.0",
2224
"tslib": "^2.3.0",
2325
"zone.js": "~0.14.10"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Component } from '@angular/core';
2+
import {injectSelector, injectDispatch} from "angular-redux";
3+
import { decrement, increment } from './store/counter-slice'
4+
import { RootState } from './store'
5+
6+
@Component({
7+
selector: 'app-root',
8+
standalone: true,
9+
imports: [],
10+
template: `
11+
<div>
12+
<div>
13+
<button
14+
aria-label="Increment value"
15+
(click)="dispatch(increment())"
16+
>
17+
Increment
18+
</button>
19+
<span>{{ count }}</span>
20+
<button
21+
aria-label="Decrement value"
22+
(click)="dispatch(decrement())"
23+
>
24+
Decrement
25+
</button>
26+
</div>
27+
</div>
28+
`
29+
})
30+
export class AppComponent {
31+
count = injectSelector((state: RootState) => state.counter.value)
32+
dispatch = injectDispatch()
33+
increment = increment;
34+
decrement = decrement;
35+
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import { Component } from '@angular/core';
1+
import { Component, inject } from '@angular/core'
2+
import { ReduxProvider } from 'angular-redux'
23

34
@Component({
45
selector: 'app-root',
56
standalone: true,
67
imports: [],
78
template: `
8-
<h1>Welcome to {{title}}!</h1>
9-
10-
11-
`,
12-
styles: [],
9+
<div>
10+
{{data.message}}
11+
</div>
12+
`
1313
})
1414
export class AppComponent {
15-
title = 'angular-redux-demo';
15+
data = inject(ReduxProvider)
1616
}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
2+
import {provideRedux} from "angular-redux";
3+
import { store } from './store'
24

35
export const appConfig: ApplicationConfig = {
4-
providers: [provideZoneChangeDetection({ eventCoalescing: true })]
6+
providers: [
7+
provideZoneChangeDetection({ eventCoalescing: true }),
8+
provideRedux({ store })
9+
]
510
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { createSlice } from '@reduxjs/toolkit'
2+
import type { PayloadAction } from '@reduxjs/toolkit'
3+
4+
export interface CounterState {
5+
value: number
6+
}
7+
8+
const initialState: CounterState = {
9+
value: 0,
10+
}
11+
12+
export const counterSlice = createSlice({
13+
name: 'counter',
14+
initialState,
15+
reducers: {
16+
increment: (state) => {
17+
// Redux Toolkit allows us to write "mutating" logic in reducers. It
18+
// doesn't actually mutate the state because it uses the Immer library,
19+
// which detects changes to a "draft state" and produces a brand new
20+
// immutable state based off those changes
21+
state.value += 1
22+
},
23+
decrement: (state) => {
24+
state.value -= 1
25+
},
26+
incrementByAmount: (state, action: PayloadAction<number>) => {
27+
state.value += action.payload
28+
},
29+
},
30+
})
31+
32+
// Action creators are generated for each case reducer function
33+
export const { increment, decrement, incrementByAmount } = counterSlice.actions
34+
35+
export default counterSlice.reducer
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { configureStore } from '@reduxjs/toolkit'
2+
import counterReducer from './counter-slice'
3+
4+
export const store = configureStore({
5+
reducer: {
6+
counter: counterReducer,
7+
},
8+
})
9+
10+
// Infer the `RootState` and `AppDispatch` types from the store itself
11+
export type RootState = ReturnType<typeof store.getState>
12+
// Inferred type: {posts: PostsState, comments: CommentsState, users: UsersState}
13+
export type AppDispatch = typeof store.dispatch

projects/angular-redux/src/lib/angular-redux.component.spec.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

projects/angular-redux/src/lib/angular-redux.component.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

projects/angular-redux/src/lib/angular-redux.service.spec.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)