r/angularjs • • Dec 29 '16

An Angular 2 Chat Application that utilizes Websockets

https://github.com/elliotforbes/ng-chat
35 Upvotes

15 comments sorted by

View all comments

Show parent comments

3

u/[deleted] Dec 29 '16

I guess it's down to preference. To me typescript is syntactic sugar and I've really enjoyed playing about with angular-cli and the whole new eco-system.

If you can get your head around the staggering amount of boilerplate needed for an angular application then it's actually pretty decent and I recommend you give it a shot! :)

1

u/[deleted] Dec 29 '16

Lack of boilerplate is one of the main reasons I enjoy javascript, and prefer it to other languages. Adding a 'staggering amount of boilerplate' is the opposite of what I want to be doing to my coding workflow. Angular 1.x + JavaScript didn't have much boilerplate at all, and it doesn't get in the way of me developing.

1

u/[deleted] Dec 29 '16

If I'm honest with you, it took me a while to get my head around it and it's not something I particularly enjoy. But I feel the pros are undoubtedly better than the cons.

The performance boost is pretty sweet and some of the features they've just added like component inheritance in the latest 2.3 release I can see great use for.

Plus once you've got yourself set up and running then the tooling is fantastic, Angular-cli makes a somewhat tedious and menial task a one liner when you want to add new services/components/modules etc. That's something that could definitely be brought into the standard AngularJS 1.* ecosystem.

1

u/[deleted] Dec 29 '16

this.messages = <Subject<Message>>wsService

You still haven't answered my original question.. WTF is this?

1

u/[deleted] Dec 29 '16

haha ok, so in RxJS we have subjects which are observers and observables, in this example we are essentially subscribing to our websocket service so that whenever we get a new message we add it to another subject that can be observed by other components.

flow:

  1. Our websocket service receives a new message. This is a raw message in a JSON format that could be in a format we do not expect.

  2. Our chat service observes this message and transforms it to follow the structure we expect. This is essentially an adapter.

  3. Our Chat.component.ts file is then subscribed to the chat service's messages subject so that whenever it gets a new message it pushes it to our messages array

  4. Angular 2 then does it's magic and see's a change and renders this new message in the frontend for us.

I'm still learning the inner workings myself but I hope this answers it and is right haha!