DEV Community

Rens Jaspers
Rens Jaspers

Posted on

Ever Realized You've Been Doing Things the Hard Way? What Simple Tricks Did You Miss?

Every now and then, I discover I've been tackling a problem the hard way for years, only to find out there was a simple trick all along that could have made my life so much easier.

Surely I'm not the only one?! :'-)

Have you had a similar experience? What simple thing did you discover late that could have made your work easier? It doesn't have to be about web development or even coding.

I'd love to hear about your stories!

Top comments (3)

Collapse
 
syeo66 profile image
Red Ochsenbein (he/him)

In general we tend to not leverage the browsers capabilities. Native form handling is one example, or just using the url to track state, or using tons of Javascript for things that can (mostly) be done in CSS.

Collapse
 
rensjaspers profile image
Rens Jaspers

I'll start.

For years, whenever I needed to handle an error in an RxJS stream with a side effect, I would catch the error and then rethrow it using catchError and throwError. Instead, I could have simply used tap:

stream$.pipe(
  tap( { error: (e) => { alert(e.message); } } )
)
Enter fullscreen mode Exit fullscreen mode
Collapse
 
rensjaspers profile image
Rens Jaspers

Another RxJS one:

I often combine streams with forkJoin or combineLatest and want the output as an object with stream names as keys. Before, I did it like this:

combineLatest([firstStream$, secondStream$]).pipe(
  map(([first, second]) => ({first, second}))
)
// output: { first: 'some value', second: 'some other value' }
Enter fullscreen mode Exit fullscreen mode

But, you can directly do:

combineLatest({ first: firstStream$, second: secondStream$ })
Enter fullscreen mode Exit fullscreen mode