reduxjs / angular-redux

Official Angular bindings for Redux
MIT License
61 stars 6 forks source link

refactor: simplify example component #3

Closed ptu14 closed 2 weeks ago

ptu14 commented 3 weeks ago

Simplify and Improve Angular Counter Component

Overview

This PR simplifies the Angular counter component, improving its readability and code formatting while maintaining its core functionality.

Changes Made

  1. Component Structure Simplification

    • Removed unnecessary properties and methods
    • Streamlined the component class structure
  2. Template Cleanup

    • Simplified the component's template
  3. Code Formatting

    • Improved overall code formatting for better readability
    • Standardized import statements

Example of Updated Component

import { Component } 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
}

I apologize for any confusion caused by the previous PR. Due to a force push, the earlier PR has been closed, and this new PR replaces it with a simplified version of the Angular counter component.