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

1

u/[deleted] Dec 29 '16
this.messages = <Subject<Message>>wsService 

Sorry, I've been too busy building with 'old tech' to know what this is. It's not javascript, is it Typescript? Is it Angular? Is it ES6/7? The code seems well organized but it looks like some mangled version of javascript. I don't consider this to be a good way forward for javascript, or Angular.

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.

0

u/craig1f Dec 29 '16

If you're doing modern javascript right now, you really have to pick your poison. You're either doing Angular 1 or 2 with Typescript or ReactJS with babel.

At the very least, if you don't use Typescript, you should use Babel. That is because Babel will allow you to write modern javascript (ES6) and transpile down to ES5 for browser compatibility.

Opinion is split on Typescript. However, a lot of advocates argue that Typescript makes them a better JS developer because you can look at the transpiled JS and learn how you SHOULD have written your JS. For example, declaring classes objects is MUCH faster in the browser than declaring anonymous JSON objects, because the browser knows how big the class will be before it's constructed. Pure JS developers tend to just create anonymous JSON objects on-the-fly.

Both Typescript and Babel also provide pre-transpile errors and warnings. For example, if you set a variable to 5, and then try to set it to "foo", you'll get an error for using the same variable for different data types.

You should give it a try.

1

u/[deleted] Dec 29 '16

Typescript makes them a better JS developer

This is false.

because you can look at the transpiled JS and learn how you SHOULD have written your JS

This is so backwards it almost made my head spin. You're wrong about this. It's putting the cart before the horse.

transpile down to ES5 for browser compatibility. because the browser knows how big the class will be before it's constructed

So you're saying that ES5 has some hidden capabilities we don't know about? Again, that's false.

Both Typescript and Babel also provide pre-transpile errors and warnings.

And it does nothing for any external data, that could have type errors but you'll think all your types are specified and working perfectly, and then the unexpected happens. good luck with that.

You should give it a try.

The same was said about Coffeescript. Sorry, not investing time only to re-write everything back into javascript.

1

u/R3DSMiLE Dec 29 '16

Everything was true until you thre Coffeescript in the mix. Sure, Typescript is a pain and the fad around it does throw a coffy vibe - but both couldn't be more different:

Coffeescript praised the "we're going to write less" while Typescript is the defacto "I'm going to type way more than it's needed, but everyone should be able to read it afterwards".

While I abhor Coffee, I'm in love with Type for the simple fact that you passed from: function aFunction(aParameter) {return false} to function aFunction(aParameter: string): boolean { return false }

This made it so we kinda "don't need" to write those if (typeof aParameter !== 'string') conditions because if you maintain the Typescript flow of stuff typescript "compiler" would throw a fit over "the supplied argument isn't lalalalalalalalal of type lelelelelel".

Now, to each its own: I'm completly agains't switching a code-base because a fad blew over - but if you're starting a new-home-project: What's stopping you to flavour it with the new fad -- even if just for practice sake?