|
Strong Sauce posted:Why? Raskolnikov2089 posted:this guy lints with airbnb
|
# ? Dec 22, 2018 13:32 |
|
|
# ? Jun 5, 2024 06:13 |
|
Why does eslint "recommend" 2 space tabbing? Eslint's rules are insane based on that.
|
# ? Dec 23, 2018 19:23 |
|
Nolgthorn posted:Why does eslint "recommend" 2 space tabbing? Eslint's rules are insane based on that. I've recently learned that bitbucket is a giant pile of poo poo and has trouble with spaces and tabs.
|
# ? Dec 23, 2018 20:58 |
|
Nolgthorn posted:Why does eslint "recommend" 2 space tabbing? Eslint's rules are insane based on that. Of course you can change the default rules but what’s the problem with it?
|
# ? Dec 24, 2018 14:01 |
|
4 space tabbing makes the depth and thus scope generally clearer. 2 spaces is one tiny char different from an actual space. 4 spaces helps disincentivise callback hell and thus promotes generally cleaner coding practices. It's easier to read. 4 spaces instead of two isn't best for all languages but I'd say it's dominant in Javascript for good reason. Why isn't it the default?
|
# ? Dec 25, 2018 00:36 |
Nolgthorn posted:4 spaces instead of two isn't best for all languages but I'd say it's dominant in Javascript for good reason. I really need a citation for that. I have always seen two spaces as the dominant one and a lot of the most popular styleguides (airbnb, standardjs, google) have it as the default. This guy even analyzed a lot of npm packages and the majority uses 2 spaces.
|
|
# ? Dec 25, 2018 00:45 |
|
Well I'll be damned.
|
# ? Dec 25, 2018 01:50 |
|
Here is what my screen looks like with a new file open that I'm working on for about 15 minutes. I have placed my first indented line, it's 4 spaces and it already looks practically cramped. I'm not sure how people can stand it being two spaces. https://imgur.com/a/gN1D7Ld
|
# ? Dec 25, 2018 02:00 |
|
Check this out: newline, one space, your open brace, newline, two more spaces, start typing the definition
|
# ? Dec 25, 2018 02:32 |
|
Thank god for insignificant whitespace so things like that are possible.
|
# ? Dec 25, 2018 03:31 |
|
At work we use 4 spaces for Python and 2 for JS, and it's fine. Prior to that I used to use 4 for everything for ages. These days if I'm free to choose on my own, I'd probably be more inclined to use 2 for everything; it's easy enough to read once you get used to it and it wastes less space. If you use 4 you definitely need to allow longer lines than you otherwise would, though - our Python linting uses the default PEP8 80 column limit because nobody has gotten around to changing that, and a lot of poo poo that really shouldn't have to be multiple lines ends up having to be wrapped, which hurts readability quite a bit. Also if you're using any kind of frontend JS that mixes HTML into your JS components in some way (be it Vue components or React JSX or whatever) you really want to be using 2 spaces.
|
# ? Dec 30, 2018 04:36 |
|
This is driving me nuts. It's so simple in jQuery, but I can't find a solution in vanilla JS. I have a menu like this:code:
code:
code:
|
# ? Dec 31, 2018 22:27 |
|
That selector doesn't appear to be in your markup
|
# ? Jan 1, 2019 00:01 |
|
LifeLynx posted:This is driving me nuts. It's so simple in jQuery, but I can't find a solution in vanilla JS. I have a menu like this: https://jsfiddle.net/0wrnov5d/
|
# ? Jan 1, 2019 00:03 |
|
Happy New Year!
|
# ? Jan 1, 2019 00:21 |
|
You're gonna be glad in the long run, you can get a much more complete understanding the vanilla way, and be sure there's nothing lurking under the hood to demystify later if there's a problem
|
# ? Jan 1, 2019 01:26 |
|
I (unpopularly) believe 4 spaces are better than 2 but I also think jQuery is stupid and much more complicated than vanilla js. It comes from a time when something was needed to enforce compatibility between browsers and has been obsolete for nearly a decade.
|
# ? Jan 1, 2019 03:53 |
|
Nolgthorn posted:I (unpopularly) believe 4 spaces are better than 2 but I also think jQuery is stupid and much more complicated than vanilla js. It comes from a time when something was needed to enforce compatibility between browsers and has been obsolete for nearly a decade.
|
# ? Jan 1, 2019 04:09 |
|
Typescript question - if I have a type defined as a list of specific strings, is there a way to create an interface that has optional keys for each possible value in that type? Examplecode:
|
# ? Jan 1, 2019 06:28 |
|
Cugel the Clever posted:jQuery being unnecessary has been the popular consensus for a few years now. It does have some legitimate use case if you need to support older browsers, but the remaining proponents of it are mainly curmudgeonly devs who have deliberately and vociferously avoided learning anything new in the last six years (like a former coworker of mine!). I haven't written anything in jQuery for a while now, but I still used it in the form of scripts I was already comfortable with. For a while it was hard to find answers to how to do things that weren't written in jQuery, but it's getting easier. Finding the proper way to reference an element is one thing jQuery does simpler - just a dollar sign and then write the #id or .class in parentheses and then call a function or whatever - but there's probably reasons for why there's different ways to find different things in vanilla JS.
|
# ? Jan 1, 2019 07:05 |
|
It's not hard to find how to do things in vanilla JS, there's the docs and language specification for that. JQuery-specific answers on the web are a plague and it only makes it worse when more people choose to adopt it because of that
|
# ? Jan 1, 2019 07:07 |
|
porksmash posted:Typescript question - if I have a type defined as a list of specific strings, is there a way to create an interface that has optional keys for each possible value in that type? Example how about : code:
|
# ? Jan 1, 2019 10:42 |
|
porksmash posted:Typescript question - if I have a type defined as a list of specific strings, is there a way to create an interface that has optional keys for each possible value in that type? https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/Advanced%20Types.md#mapped-types
|
# ? Jan 1, 2019 11:02 |
|
Emergency Mittens posted:https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/Advanced%20Types.md#mapped-types Yeah, mapped types is what you want. I ran into this at work recently and found a few good resources, I could dig them up if this doesn't cut it for ya.
|
# ? Jan 1, 2019 14:49 |
|
I was happy with this script I wrote (maybe not entirely from an efficiency standpoint) until I realized it doesn't work in any iOS browser. It doesn't work in IE11 either, but I don't mind that too much.code:
|
# ? Jan 2, 2019 00:03 |
|
LifeLynx posted:I was happy with this script I wrote (maybe not entirely from an efficiency standpoint) until I realized it doesn't work in any iOS browser. It doesn't work in IE11 either, but I don't mind that too much.
|
# ? Jan 2, 2019 00:18 |
|
Cugel the Clever posted:Probably best to just go with the polyfill. The IntersectionObserver API is a massive improvement performance-wise of the same functionality in plain JS. I don't know what polyfill is but apparently it's coded in some kind of magic runes that make old browsers behave like modern ones? It worked like a charm, thank you!
|
# ? Jan 2, 2019 00:28 |
|
LifeLynx posted:I don't know what polyfill is but apparently it's coded in some kind of magic runes that make old browsers behave like modern ones? It worked like a charm, thank you! That said, it comes with the tradeoffs of having none of the performance benefits of the fancy new thing and being ___kb of extra code shipped to users that already support the original implementation.
|
# ? Jan 2, 2019 00:42 |
|
Emergency Mittens posted:https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/Advanced%20Types.md#mapped-types That was exactly what I couldn't find myself - thank you!
|
# ? Jan 2, 2019 17:00 |
|
Argh I have spent two days trying to make this poo poo work. How do you set up two typescript modules, one of which depends on the other, without going through a full publish and import rigmarole every time you change the dependency one? The internet is all "use yarn link or npm link but it won't work lol" which is true, it doesn't work. Today I found yarn workspaces that sounded good but the instructions for that are like "here's how you create a workspace, ha ha that is all, good luck actually using it". So I've got a yarn workspace that as expected includes symlinks to my local modules and installs of all the other dependencies, but now what, how do I actually build a thing here, the tsconfig.json file is now inside a symlink inside node_modules which presumably is not how you're supposed to use that, and I have no loving idea how this is going to eventually tie in with webpack. Is my main project's package.json supposed to *be* the workspace-defining one? Also something about typescript project references and "tsc --build" maybe? Maybe it can perform the build inside the node_modules folder?
|
# ? Jan 4, 2019 07:45 |
|
roomforthetuna posted:Argh I have spent two days trying to make this poo poo work. How do you set up two typescript modules, one of which depends on the other, without going through a full publish and import rigmarole every time you change the dependency one? I think I've used something like npm link + "tsc --build --watch" or maybe "webpack --watch" Setting up a project is the worst thing about TypeScript
|
# ? Jan 4, 2019 16:28 |
|
Aha, I found a sort-of answer to my question, which is that evidently webpack is doing something a bit different from the way package.json people think you'll be building stuff. As such, having code:
The one remaining difficulty I was having was that for some reason a 'package' in that path that was only exporting one function (a debug-log function that's basically just a wrapper around console.log whose purpose is to be stripped out in a production build) was simultaneously "not found" and capable of whining about syntax errors or the function from it not being found if I changed its name. I just moved that file arbitrarily into one of the other packages and from there it worked fine. Mysterious. So obviously I'm not super comfortable with what I have going on, but it does build now, and doesn't require any extra command-line operations to pick up on dependencies being updated, so the setup finally meets pretty much all the criteria I had. Relatedly, has anyone here done anything with WebRTC? That's nearly as much of a clusterfuck to get going as webpack+typescript+npm. I got that working too, finally, and all it requires is like 14 messages through two server connections in order to establish one peer-to-peer connection.
|
# ? Jan 6, 2019 06:18 |
|
Are you sure you're designing something that needs webpack+typescript+npm? I imagine you are hitting yourself in the foot with a hammer because of all that tooling. WebRTC is just one of those things, the spec is designed by committee and so even though it's P2P you need like 2-5 intermediary or ancillary servers that do whatever. I'm not convinced any of it is necessary, if I needed to do something with it I'd probably just pay for some service that provides it.
|
# ? Jan 6, 2019 21:59 |
|
roomforthetuna posted:Relatedly, has anyone here done anything with WebRTC? That's nearly as much of a clusterfuck to get going as webpack+typescript+npm. I got that working too, finally, and all it requires is like 14 messages through two server connections in order to establish one peer-to-peer connection. That's disheartening, I'm about to start work on some new features that I planned to use WebRTC for... Maybe I'll just do it the old fashioned way instead. I just spent forever fighting with the Web Audio API, which is a giant piece of poo poo with all kinds of weird limitations placed on it for no reason. Like, yeah, you can encode mp3s, but only in real time. And yeah, the api has most of the standard audio effects and filters, but it doesn't specify their implementation, so you get different results in every browser.
|
# ? Jan 6, 2019 22:22 |
|
Tip posted:That's disheartening, I'm about to start work on some new features that I planned to use WebRTC for... Maybe I'll just do it the old fashioned way instead. You sound like you're doing something I tried to do a while ago. I was streaming audio from the user to a server where the recording was saved. At that time the only thing you could reliably capture was WAV-like gigantic amounts of data. So then I needed to include a several mb js-compiled version of an Opus encoder on the page. Then with the audio streaming into a compressed format I eventually gave up on WebRTC and decided on using websockets, breaking the audio up into chunks encoded as base64. None of it was ideal at all. But in the end it felt reasonably as good as I was going to get it.
|
# ? Jan 6, 2019 22:32 |
|
Tip posted:That's disheartening, I'm about to start work on some new features that I planned to use WebRTC for... Maybe I'll just do it the old fashioned way instead. Nolgthorn posted:Are you sure you're designing something that needs webpack+typescript+npm? I imagine you are hitting yourself in the foot with a hammer because of all that tooling. WebRTC is just one of those things, the spec is designed by committee and so even though it's P2P you need like 2-5 intermediary or ancillary servers that do whatever. I have reduced it to not using npm to control my own libraries - I was going to open-source my WebRTC wrapping library and its server sibling, but npm being a pain in the rear end has persuaded me not to (which is funny because I got the feeling npm is to some extent designed as "you open-source or you pay!" but somehow it became so annoying that I'm not even going to open-source the thing I was intending to.)
|
# ? Jan 6, 2019 22:58 |
|
Nolgthorn posted:You sound like you're doing something I tried to do a while ago. I was streaming audio from the user to a server where the recording was saved. At that time the only thing you could reliably capture was WAV-like gigantic amounts of data. So then I needed to include a several mb js-compiled version of an Opus encoder on the page. My use case was basically, simultaneously playing a track and recording a microphone input, and then being able to change the mix on the fly client side and save as an mp3. I tried a ton of js libraries that claim to handle this kinda thing, and they were all hosed in one way or another. I did finally find a js lame mp3 encoder that's only like 100kb minified and gzipped, and I turned that into a web worker so I can encode on a separate thread. The things that still really suck are that you have to load the song from the server twice, once as a normal stream and then again as an audioBuffer. Also, the mp3 encoding with the js webworker is slower than real time on some devices.
|
# ? Jan 6, 2019 23:15 |
|
roomforthetuna posted:If it's not important to you to go peer-to-peer, I strongly recommend not even thinking about WebRTC. Websockets are pretty good and not at all a giant pain in the rear end, comparatively. You basically have to implement your own peer-to-peer connection through your server to communicate how to form a peer-to-peer connection not through your server, so for probably 95% of use-cases you might as well just carry on communicating through your server since you already set that up. I'm going to be using web sockets anyways for other features, but I wanted to go peer-to-peer for this because it involves a lot of users exchanging large amounts of audio data, and I don't want to pay for that data. I'll probably still tool around with WebRTC a bit before I decide whether it's worth fighting with for the saved bandwidth.
|
# ? Jan 6, 2019 23:19 |
|
roomforthetuna posted:Well no, it doesn't need all the things, but webpack doesn't work without some amount of npm, and typescript for a large project would suck without some sort of package wrapper, and webpack seems to be the only one that supports dynamic module loading which I want because my project is intended to be extensible, and I don't want it to have to load everything before anything works. Not to tell you how to do it but I'd just compile separate js files as needed, then use the `async` html tag. Bingo bongo and it's done. The only thing typescript's compiler is bizarrely still missing is iife, so I use something lightweight like buble when I need it if I'm using typescript. Webpack is like trying to land a rocket on mars, when all you really want is a little fin that's on the rocket. It has like 8 billion dependencies, it's a bloody mess.
|
# ? Jan 7, 2019 00:30 |
|
|
# ? Jun 5, 2024 06:13 |
|
What method do you recommend for causing a long calculation to not block the main thread? I'm attempting to use async, but am likely doing it wrong. Case: Have some long validations that once complete, trigger a Redux update. What currently happens is the app hangs until they're done. Is there a way I can make the GUI run smoothly while the calc is being performed, and update the Redux state once complete? From what I've read, it appears that prepending the long funcs with 'async' should accomplish this. Don't need to return anything, just let Redux update the state once complete.
|
# ? Jan 7, 2019 02:06 |