Earlier quoted context omitted.
The way I handle situations like this is to only put the catches where I need them to serve some purpose. Generally, I don't catch errors at the start of the chain because I can't know what to do with them at that point. If I do catch them, it's only for logging or similar purposes and I still let the error propagate further. One pattern I use is to rethrow the error: return service.fetchData().then((data) => {}).cat…
> return service.fetchData().then((data) => {}).catch((err) => {console.log(err); throw err;}); Yes - but this kind of code requires that you know that something else chains the promise and handles 'err' - which is my entire complaint, a higher level function shouldn't need to know whether it has children or if they do error handling. Otherwise it's back to the same kind of callback style where you have to go into an…
jQuery 3.0 Released
101–110 of 164 posts
Re: jQuery 3.0 Released
#102Earlier quoted context omitted.
> return service.fetchData().then((data) => {}).catch((err) => {console.log(err); throw err;}); Yes - but this kind of code requires that you know that something else chains the promise and handles 'err' - which is my entire complaint, a higher level function shouldn't need to know whether it has children or if they do error handling. Otherwise it's back to the same kind of callback style where you have to go into an…
You're returning a promise. At that point you've already assumed that something else is going to expect a promise, and a promise can either succeed or fail.
Re: jQuery 3.0 Released
#103Earlier quoted context omitted.
You aren't recreating jQuery by using basic JavaScript syntax.
isn't JavaScript what jQuery is written with?
Yes use jQuery if it's really providing benefit, but if you're only using it for a few things, you may be better off just doing in in plain javascript, even if it's a bit longer.
Every library you add has an overhead cost on the end user as they have to fetch it and process it. It's easy to lose track of that when you're developing and testing against local webservers or on computers vs mobile, but there is strong value in keeping things small and with as few unnecessary dependencies as possible :)
Re: jQuery 3.0 Released
#104Re: jQuery 3.0 Released
#105Is anybody in the HN crowd still using jQuery for new projects? If yes, why not use "vanilla" js?
Yup. > If yes, why not use "vanilla" js? I can't answer that, but I can answer "Why not use $Framework?" My current project (a large admin system) is crying out for the more complex parts of the admin UI to be built in React, Angular etc. The problem is it's an all-or-nothing situation. When picking up a new technology I want to add a little bit to the current project, a bit more to the next, and so on. Progressive E…
Re: jQuery 3.0 Released
#106Is anybody in the HN crowd still using jQuery for new projects? If yes, why not use "vanilla" js?
I started using "vanilla" js, then created a method as a name for the huge `[].prototype.slice.call(document.querySelectorAll(selector))` Then as I continued adding useful methods such as ajax() (no, in vanilla js it's not "solved") and turning events off (also non-trivial) I ended up with a jquery alternative: > http://umbrellajs.com/ It's not exactly the same, but most methods are the same or highly compatible. For…
Re: jQuery 3.0 Released
#107Earlier quoted context omitted.
Yup. > If yes, why not use "vanilla" js? I can't answer that, but I can answer "Why not use $Framework?" My current project (a large admin system) is crying out for the more complex parts of the admin UI to be built in React, Angular etc. The problem is it's an all-or-nothing situation. When picking up a new technology I want to add a little bit to the current project, a bit more to the next, and so on. Progressive E…
Why is it all or nothing? We've been replacing certain parts of our vanilla js application with small React apps and it's worked brilliantly. There is a really good talk by Ryan Florence where he replaces backbone components (i think) with React components.
Re: jQuery 3.0 Released
#108Is anybody in the HN crowd still using jQuery for new projects? If yes, why not use "vanilla" js?
Why does anybody use a library? Because it has some good pre-writen code you can reuse. Vanilla js is verbose, full of extra control sequences and easy to get wrong.
Re: jQuery 3.0 Released
#109Earlier quoted context omitted.
Yup. > If yes, why not use "vanilla" js? I can't answer that, but I can answer "Why not use $Framework?" My current project (a large admin system) is crying out for the more complex parts of the admin UI to be built in React, Angular etc. The problem is it's an all-or-nothing situation. When picking up a new technology I want to add a little bit to the current project, a bit more to the next, and so on. Progressive E…
Why is it all or nothing? We've been replacing certain parts of our vanilla js application with small React apps and it's worked brilliantly. There is a really good talk by Ryan Florence where he replaces backbone components (i think) with React components.
Re: jQuery 3.0 Released
#110I've complained a few times about what seems to me, to be a less-friendly way of handling Promise rejections in es6. Consider the relatively common use-case - there is a service object which proxies requests, format's the call to the backend (or fetches from cache) and format's the returned response for the caller of the object. So the pattern looks something like: ServiceObject.fetchData(query).then((data) => { / *…
If you're not handling the error in the first promise, then throw it again.
You are handling the error (e.g. providing the user with a flash message telling them their was an error) - but if you don't re-throw it you will end up in the 'success' callback-chain - without a result obviously. Therefore whether you re-throw the error or squash it depends on whether another 'reject' function will be there to squash it further down the chain etc.