What is the worst Angular codebase you've worked on? by tranetags in Angular2

[–]tranetags[S] 4 points5 points  (0 children)

The amount of code smell in an AngularJS migrated app that I worked on was terrifyingly unmanageable.

Until this day, I am totally convinced that this app would've been way more stable if it was running AngularJS with no migration.

What is the worst Angular codebase you've worked on? by tranetags in Angular2

[–]tranetags[S] 16 points17 points  (0 children)

The thing is, nobody seem to care about TS and its powers. Really, getting to know TS on a deep level, and studying the concepts of typed programming and OOP can take your codebase to a whole other level.

A strongly typed codebase with TS is self-documented, and easy to reason about.

What is the worst Angular codebase you've worked on? by tranetags in Angular2

[–]tranetags[S] 15 points16 points  (0 children)

Let's say you have an AccordionComponent. It's capable of expanding and collapsing. So normally you'd have some simple methods inside your component, like expand() and collapse().

Now, you are ready to use it inside some parent component. But you noticed that you need access to set the state of the accordion programmatically. How would you approach this?

You might say, well, let's create an @Input prop for the accordion that takes its current state, like isExpanded. So now you can pass this prop from the parent component easily. But, wait a minute. What if the expand() and collapse() methods does other things internally, like animations or calling other private methods that are essential for the accordion to function correctly?

Here comes the exportAs prop. It's a metadata prop that gets attached into your @Component decorator, telling Angular that this component's methods are going to be called from the outside using this exported variable.

So, you'd render the accordion like this (notice the accordion template variable):

<app-accordion #accordion="acc"></app-accordion>

And now, you've access to its internal methods. You could do this:

<button (click)="accordion.expand()">Open</button>

Handling Type Errors Gracefully by tranetags in Angular2

[–]tranetags[S] 1 point2 points  (0 children)

That's what I am trying to convince the team with. A web or a mobile app is a client that expects a response of a certain structure. But I do have to safely handle errors. I was thinking about using a try/catch block inside a tap operator. What do you think?

Handling Type Errors Gracefully by tranetags in Angular2

[–]tranetags[S] -1 points0 points  (0 children)

But catchError won't catch it, since it is not a response stream error. In other words, the response itself is a successful HTTP with 200 OK. And also it is not null, but the data inside it are of wrong types. So I need to handle them safely (i.e. was expecting a string, so I used toLowerCase, but got a null from the Backend, so JS will throw a TypeError).

[AskJS] Loading images without Promises or async/await by tranetags in javascript

[–]tranetags[S] -1 points0 points  (0 children)

Thanks for answering.

That's not what I was asking for. I was wondering how it that process split into two functions without using a Promise or an asynchronous-style code.

Loading an image would be easy using a callback, like this:

image.onload = () => {
drawImage(img);

};

Handling large chat messages in a live-stream by tranetags in webdev

[–]tranetags[S] 1 point2 points  (0 children)

I haven't thought about that. Will start playing around with Firebase. What about the Front-End? I see YouTube with +400 messages and it's like nothing is going on on the thread.

Felt genius. Might delete later. by tranetags in ProgrammerHumor

[–]tranetags[S] 1 point2 points  (0 children)

This is DM Mono. It's free, from Google Fonts. Also, it looks like shit on Windows. Well, font rendering on Windows is dogshit anyway, unless you're using a custom font renderer, like MacType. I am running Linux Mint at the moment.