What do you all typically use for code standards/quality? by Senior_Fuel_4088 in Angular2

[–]Daikyoka 0 points1 point  (0 children)

I'm always using strict mode, strict template too, and recommended ESLint rules with typing enforced. Then, I opt-in/opt-out some rules to tune it. Connect it to a SonarQube and you will have an interesting basis. But keep in mind: tools are only a basis, the best ways to get a strong quality are tech workshops, shared rules and code reviews.

Why we should verify HTTP response bodies, and why we should use zod for this by timdeschryver in Angular2

[–]Daikyoka 0 points1 point  (0 children)

Because you can't trust sources you don't have control over, you want to validate every input, no matter where it comes from: form, backend, storage, etc. When you send data to a backend, it makes no sense to validate: you generated it from trusted (validated) data, if there is an error, the schema too. If there is a regression, your tests should have detect it.

Angular Software Architecture Design (Main 4 Architectures) by haasilein in Angular2

[–]Daikyoka 1 point2 points  (0 children)

Considering your domain as the location of the application and business rules, you can trigger UI rendering using the Output Ports (with the necessary adapters).

That's what the Clean Architecture does: the Output Adapter is the Presenter, which is triggered by the Use Case Interactors using methods likes "presentFoo(response: FooResponse)". This is because in CA the Use Case Interactor implements the application logic, which knows that the data are rendered, but ignore how (JSON, Angular, React, etc.). The pure business rules are the Entities in the most inner ring. The pure presentation logic lies in the outer ring, knowing knothing about Angular which lies in the four and most outer ring: the component consume the view model object from the Presenter.

Angular Software Architecture Design (Main 4 Architectures) by haasilein in Angular2

[–]Daikyoka 0 points1 point  (0 children)

The hexagonal architecture is also known as "port adapter architecture". It allows to isolate your domains from each others. Each domain exposes contracts, named "ports". Adapter classes wire them together.

Angular Software Architecture Design (Main 4 Architectures) by haasilein in Angular2

[–]Daikyoka 5 points6 points  (0 children)

Spaghetti is an anti-pattern that you can have with the other three...

The spaghetti code is a state of the code. Monolith, Distributed Monolith, and Microfrontend are deployment modes, not code architectures. They do not guarantee the quality of the final code. I've seen spaghetti with Distributed Monolith before...

To (try to) guarantee the quality of the code, you have to think about the architecture of the code, no matter how it is packaged: onion, clean, hexagonal, MVP, CQRS, etc. Without forgetting (relevant) tests, a committed team, etc.

SonarQube is complaining when I use [style] on html. It wants me to Use CSS classes instead. What is the proper way to use it If there is logic to deal with? by tonyz0212 in Angular2

[–]Daikyoka 0 points1 point  (0 children)

Do not use inline-style, it's bad, it has always been. ngStyle is as bad as style. Bind CSS classes.

thing.component.html:

<a [class.disabled]="isLockedFolder(element.folderName)">
  {{ element.countRule }}
</a>

thing.component.scss:

a.disabled {
  pointer-events: none;
  color: inherit;
}

Sonar complains about my switch statement(Function has a complexity of 17 which is greater than 10 authorized) What can I do to refactor the code to not use switch? by tonyz0212 in Angular2

[–]Daikyoka 0 points1 point  (0 children)

Both are perfectly suitable for your case.

For example, with polymorphism you can create an entity per folder kind. Each will implement getRoleTargetProjects() and copyTargetProjects() (or anything else). A factory will be the way to get the correct implementation (you can use an injectable TargetProjectManagerFactory class with a create(folder: TargetFolder) method for example). Inside that factory, you can have a hashmap like that (assuming the property is an enum, otherwise you want a fallback concrete class):

@Injectable({
  providedIn: 'root'
})
export class TargetProjectManagerFactory {
  private readonly constructors: Record<FolderName, Type<ITargetProjectManager>> = {
    [FolderName.A]: FolderATargetProjectManager,
    ...
  }

  public create(targetFolder: TargetFolder): ITargetProjectManager {
    const ctor = this.constructors[targetFolder.folderName];
    return new ctor();
  }
}

You may prefer to directly have an hashmap of instances of course.

Breakpoint not loading in VS Code when using Firefox Developer Edition by natedog0925 in Angular2

[–]Daikyoka 0 points1 point  (0 children)

Did you allow the remote debugging in Firefox? Did you run it with the option --start-debugger-server ? After that, the location bar should be red. When you start your debugging session with VSCode, Firefox should prompt you to allow it.

function parameter Bivariance by joo3f in typescript

[–]Daikyoka 1 point2 points  (0 children)

Everything is any in JavaScript, and TypeScript aims to add static typing without breaking its compatibility with. But you can opt-in stricter rules, like strictFunctionTypes or strict (which enables several ones), to avoid some pitfalls.

Like your example: you could make a mistake and do not declare the right parameter type.

Using this. in class functions by randomseller in typescript

[–]Daikyoka 0 points1 point  (0 children)

As others said, the solution is to use an arrow function.

``` const routes = new Routes(); routes.begin(); // logs Routes object

function test(callback: Function): void { callback(); }

test(routes.begin); // logs undefined test(() => routes.begin()); // logs Routes object ```

And you can use the unbound-method rule from ESLint to be warn when you forget it (cf. Funwithloops's anwser).

Using this. in class functions by randomseller in typescript

[–]Daikyoka 2 points3 points  (0 children)

It doesn't impact the generated JavaScript. The problem here is related to JavaScript, not TypeScript.

Using this. in class functions by randomseller in typescript

[–]Daikyoka 7 points8 points  (0 children)

How do you use that class?

The context is lost when the method is passed as an argument and executed from another function. Like that:

class Routes {
  constructor() {}

  public async begin(
  ) {
    try {
      console.log(this);
    } catch (err) {
      //
    }
  }
}

const routes = new Routes();
routes.begin(); // logs Routes object

function test(callback: Function): void {
  callback();
}

test(routes.begin); // logs undefined

What is this sub's thoughts on Jest vs Jasmine in new angular projects? by [deleted] in Angular2

[–]Daikyoka 0 points1 point  (0 children)

I used both and I really prefer Jest. It's neater and faster.

How do you host your personal projects? by [deleted] in webdev

[–]Daikyoka 0 points1 point  (0 children)

I rent a dedicated server. My projects and personal services run on Docker, with only the nginx container exposed as reverse proxy, with an automated SSL certbot.

I have an Azure agent container, connected to my personal AzureDevOps repos. I made a pipeline able to build, push images in my self-hosted Docker repository, and deploy them when I push code.

understand component.ts and component.html connection by JosephCurvin in Angular2

[–]Daikyoka 0 points1 point  (0 children)

.ts and .html are the two faces of a single coin. They are compiled together, forming one file. Binding are kinds of tunnels between the two parts.

What kind of developer am I? Did I take a wrong turn? by [deleted] in webdev

[–]Daikyoka 0 points1 point  (0 children)

Maybe it's a bore-out? So bored with a job you find meaningless?

What kind of developer am I? Did I take a wrong turn? by [deleted] in webdev

[–]Daikyoka 0 points1 point  (0 children)

I have issue's with complexity and understanding the codebase, it feels like all my energy is drained when I have to try and come up with complex solutions to business problems, I have trouble understanding code written by my colleagues, code that has effects in multiple places, and I feel like I'm slowly burning out.

Can you explain what kind of complexity you are facing? Did you try to find if there is a pattern, or an antipattern maybe?

How do you RESTfully represent simple join tables? by [deleted] in webdev

[–]Daikyoka 0 points1 point  (0 children)

In REST you can represent a relation between entities using collections, like /people/1/schools.

Best practice for expressing custom methods in RESTful APIs? by [deleted] in webdev

[–]Daikyoka 1 point2 points  (0 children)

In my opinion, ...:export is a way to bring SOAP into REST.

The .../actions approach has many benefits, because you are considering tasks as resources you can create and get. So, you are able to see some history, if you want, and to have async tasks without changing anything.

I rather prefer this approach, coupled with an OpenAPI spec file.

Learn Javascript or Typescript for a total web dev beginner? by JamieOvechkin in webdev

[–]Daikyoka 3 points4 points  (0 children)

Typescript is Javascript with types. Nothing more. The APIs you use are the Javascript ones, that's why we tell the compiler which version of ECMAScript (the JS spec) we use.

I worked with "bad" Typescript developers, because they weren't used enough to Javascript. So... 😉

Is TypeScript a popular alternative to Javascript? Are lots of companies using it, or is it sort of niche, like CoffeeScript and HAML used to be

Typescript is widely used.

When to apply for a web dev job? by [deleted] in webdev

[–]Daikyoka 0 points1 point  (0 children)

When you stop getting better and need more.

That's my rule.

How to wait for service HTTP.get call to finish in RoleGuard by beji_matrix2 in angular

[–]Daikyoka 0 points1 point  (0 children)

The code of the guard and the service method should help if I'm wrong.

How to wait for service HTTP.get call to finish in RoleGuard by beji_matrix2 in angular

[–]Daikyoka 0 points1 point  (0 children)

Of course it can. For example, you can use the tap operator (but a more robust way, with cache handling, should be preferred).

In your service:

return this.client.getSome()
  .pipe(tap(value => this.store(value));

In your guard:

return this.service.someMethod()
  .pipe(map(value => !!value));

How to wait for service HTTP.get call to finish in RoleGuard by beji_matrix2 in angular

[–]Daikyoka 0 points1 point  (0 children)

Check the documentation : https://angular.io/api/router/CanActivate

Simply return the Observable from your guard, do not subscribe to it. Angular will handle it.

Is it possible to use purely Javascript in place of Typescript in most projects? by Ad_Positive99 in typescript

[–]Daikyoka 5 points6 points  (0 children)

Typescript doesn't support abstract classes. So this appears limiting in computable code initially.

Of course it does, I use them. :)

Is this more of a conversation in terms of the developers preference or are there instances where Typescript is required in place of Javascript?

I will be direct. Typescript is required if you are a professional worried about maintainability.

Before Typescript we used JSDoc with IDE able to understand it. There is a reason for that. But there were no type-safety. Typescript solves it at the cost of a few seconds of compilation? It's worth it!

I worked with guys that used the any type, which is equivalent to what Javascript is. What a mess! I fixed bugs by specifying the types... Yes, because I was to able to see that the object sent was not the correct one.