-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: dispatch operations are now untracked
- Loading branch information
1 parent
233f9d8
commit 3496f3c
Showing
11 changed files
with
190 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
24 changes: 24 additions & 0 deletions
24
projects/angular-redux-auto-dispatch-demo/src/app/app.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Component, effect } from '@angular/core'; | ||
import { injectSelector, injectDispatch } from '@reduxjs/angular-redux'; | ||
import { decrement, increment } from './store/counter-slice'; | ||
import { RootState } from './store'; | ||
|
||
@Component({ | ||
selector: 'app-root', | ||
standalone: true, | ||
template: ` | ||
<button (click)="dispatch(increment())">Increment</button> | ||
<span>{{ count() }}</span> | ||
<button (click)="dispatch(decrement())">Decrement</button> | ||
`, | ||
}) | ||
export class AppComponent { | ||
count = injectSelector((state: RootState) => state.counter.value); | ||
dispatch = injectDispatch(); | ||
increment = increment; | ||
decrement = decrement; | ||
|
||
_auto_increment = effect(() => { | ||
this.dispatch(increment()); | ||
}); | ||
} |
10 changes: 10 additions & 0 deletions
10
projects/angular-redux-auto-dispatch-demo/src/app/app.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core'; | ||
import { provideRedux } from '@reduxjs/angular-redux'; | ||
import { store } from './store'; | ||
|
||
export const appConfig: ApplicationConfig = { | ||
providers: [ | ||
provideZoneChangeDetection({ eventCoalescing: true }), | ||
provideRedux({ store }), | ||
], | ||
}; |
35 changes: 35 additions & 0 deletions
35
projects/angular-redux-auto-dispatch-demo/src/app/store/counter-slice.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { createSlice } from '@reduxjs/toolkit'; | ||
import type { PayloadAction } from '@reduxjs/toolkit'; | ||
|
||
export interface CounterState { | ||
value: number; | ||
} | ||
|
||
const initialState: CounterState = { | ||
value: 0, | ||
}; | ||
|
||
export const counterSlice = createSlice({ | ||
name: 'counter', | ||
initialState, | ||
reducers: { | ||
increment: (state) => { | ||
// Redux Toolkit allows us to write "mutating" logic in reducers. It | ||
// doesn't actually mutate the state because it uses the Immer library, | ||
// which detects changes to a "draft state" and produces a brand new | ||
// immutable state based off those changes | ||
state.value += 1; | ||
}, | ||
decrement: (state) => { | ||
state.value -= 1; | ||
}, | ||
incrementByAmount: (state, action: PayloadAction<number>) => { | ||
state.value += action.payload; | ||
}, | ||
}, | ||
}); | ||
|
||
// Action creators are generated for each case reducer function | ||
export const { increment, decrement, incrementByAmount } = counterSlice.actions; | ||
|
||
export default counterSlice.reducer; |
13 changes: 13 additions & 0 deletions
13
projects/angular-redux-auto-dispatch-demo/src/app/store/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { configureStore } from '@reduxjs/toolkit'; | ||
import counterReducer from './counter-slice'; | ||
|
||
export const store = configureStore({ | ||
reducer: { | ||
counter: counterReducer, | ||
}, | ||
}); | ||
|
||
// Infer the `RootState` and `AppDispatch` types from the store itself | ||
export type RootState = ReturnType<typeof store.getState>; | ||
// Inferred type: {counter: CounterState} | ||
export type AppDispatch = typeof store.dispatch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>AngularReduxDemo</title> | ||
<base href="/" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<link rel="icon" type="image/x-icon" href="favicon.ico" /> | ||
</head> | ||
<body> | ||
<app-root></app-root> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { bootstrapApplication } from '@angular/platform-browser'; | ||
import { appConfig } from './app/app.config'; | ||
import { AppComponent } from './app/app.component'; | ||
|
||
bootstrapApplication(AppComponent, appConfig).catch((err) => | ||
console.error(err), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/* You can add global styles to this file, and also import other style files */ |
15 changes: 15 additions & 0 deletions
15
projects/angular-redux-auto-dispatch-demo/tsconfig.app.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */ | ||
/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../out-tsc/app", | ||
"types": [] | ||
}, | ||
"files": [ | ||
"src/main.ts" | ||
], | ||
"include": [ | ||
"src/**/*.d.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters