-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
83bf37f
commit 8e870c7
Showing
1 changed file
with
42 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Moving from Angular Pipes to Computed Signals | ||
|
||
With Angular Signals and computed(), I've found compelling reasons to move away from Angular pipes in favor of utility functions. Here's why: | ||
|
||
## Key Benefits | ||
- **Pure Utility Functions**: Instead of pipes, we can use simple TypeScript functions that are easier to understand and maintain | ||
- **Simplified Testing**: Unit tests become more straightforward without pipe-specific testing logic | ||
- **Better Component Integration**: Functions integrate more naturally with components and computed signals | ||
|
||
## Real-World Example | ||
|
||
Let's look at a practical example of converting names to acronyms: | ||
``` | ||
// title-to-acronym.ts | ||
export function titleToAcronym(title: string): string { | ||
return title | ||
.split(' ') | ||
.filter(word => word.length > 0) | ||
.map(word => word[0]?.toUpperCase() || '') | ||
.join(''); | ||
} | ||
// title-to-acronym.spec.ts | ||
// super simple unit testing | ||
describe('titleToAcronym', () => { | ||
it('should convert title to acronym', () => { | ||
expect(titleToAcronym('Hello World')).toBe('HW'); | ||
expect(titleToAcronym('Test Driven Development')).toBe('TDD'); | ||
expect(titleToAcronym('Single Word')).toBe('SW'); | ||
}); | ||
}); | ||
// test.component.ts | ||
export class TicketsDataTableComponent { | ||
// .. | ||
workspaceAcronym = computed(() => { | ||
const userFullName = this.user()?.fullName; | ||
return titleToAcronym(userFullName); | ||
}); | ||
//.. | ||
} | ||
``` |