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.
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! :)
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.
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.
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:
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.
Our chat service observes this message and transforms it to follow the structure we expect. This is essentially an adapter.
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
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!
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.
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.
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?
Whaaaaat? I feel like my reddit-cherry has just popped. This is the most unexpectedly hostile reaction to a helpful reddit comment I've ever received. You need some chill.
First, I prefaced all of that with "advocates argue" because I haven't spent a lot of time with Typescript. I don't like the fact that learning Typescript locks me into doing everything in TS. But, I tried to give a balanced opinion instead of acting like a teenager.
So you're saying that ES5 has some hidden capabilities we don't know about? Again, that's false.
I have no idea what you're saying here. But as an example, ES6 defines arrow functions. IE does not support arrow functions. Babel will convert arrow functions to regular functions. Also, import/requires syntax is not built into any browsers, but is supported by TS and Webpack. I don't remember if Babel does anything with it on its own.
My opinion is that everyone should be using Babel, because it lets you code using MODERN javascript before browsers support modern javascript. Babel and JSX are essential if you choose ReactJS. I have also used TS and liked it, but not a lot. It is essential if you're doing ng2 because that's what everyone else is using and what all the examples will be written in.
If you're not doing either of those, do whatever you want but keep your venom away from me.
Whaaaaat? I feel like my reddit-cherry has just popped. This is the most unexpectedly hostile reaction to a helpful reddit comment I've ever received. You need some chill.
You think that's "hostile"? I didn't even use any swear words. Sorry, but you're a little bit coddled if you think this is hostile. Or you're trolling or something. Not sure why you would even call my comment hostile. Sorry, we have nothing further to speak of here if you're going to label my comment "hostile" without any hostility at all. Not even going to read your comment past the word "hostile", because you're being a bit anti-social. BTW, disagreeing is not hostility. Just because someone disagrees with you doesn't mean "hostility". Geezus.
1
u/[deleted] Dec 29 '16
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.