|
Is there an ES6-to-uglified-javascript compilation process that isn't a giant pain in the rear end to set up? I want to be able to do it from a command line, I don't want to install Java, and I want to have an easy path to debugging. The only thing I really want from ES6 is modules/namespaces/exports, which unfortunately seems to make running unmodified scripts in Chrome for debugging purposes not work. I tried google-closure-compiler-js; the command line interface seems to ignore the flags it's described as using so it only ever removes whitespace and doesn't really uglify or do module wrangling, and npm installing a bunch of garbage to support its use another way ends up complaining about undeclared variables that are clearly declared and aren't mentioned at the places the errors are claimed to be at (with its webpack support), and then trying to run it complains $jscomp is not defined (which is supposed to be a polyfill), and the 'gulp' wrapper just doesn't work as described at all. Before that I got about a hundredth of the way through the giant loving mess of hoops installing a Babel command line seems to require, and with the expectation that it's going to fail to mention a bunch of steps since right from the getgo it started out just assuming I had npm installed already. Oh, I also tried typescript briefly, and foolishly made a copy of my original js file with a ts extension, ran the typescript compiler on it, didn't like what it was doing so I deleted the .ts file, not realizing the compiler had silently overwritten my original modern js file with an ugly backward-compatible version, so I had to spend half an hour undoing that poo poo. I disliked typescript because apparently by design it hates this: code:
Should I just give up on the idea of moduling my code? I've done modules, but only in a context where all the build tools are already set up, I'm just not convinced it's worth the effort of figuring out all the build tools for my little home projects. roomforthetuna fucked around with this message at 07:10 on May 19, 2018 |
# ¿ May 19, 2018 07:08 |
|
|
# ¿ Apr 29, 2024 13:34 |
|
Tanners posted:Typescript here wants you to indicate that those parameters are optional. You can add a ? To the end of the parameter names and that should compile fine.
|
# ¿ May 20, 2018 03:01 |
|
Roadie posted:You need to explicitly define a tuple type for bar, as otherwise it will infer an array of indeterminate length.
|
# ¿ May 20, 2018 21:48 |
|
Hm, I just noticed scrolling back up that I never actually posted my reply where I said thanks for the parcel suggestion, it is hugely less frustrating than trying to set anything else up, and the results aren't bad at all. I think I started elaborating on "thanks" then went looking for an example of something, and got distracted. So, thanks! Aha, I found the tab with the unposted post in it. quote:Thanks! Working in minutes, and helpful errors ("x is readOnly" where I tried to set an imported value, rather than "x is not defined" that I was getting with google-closure-js).
|
# ¿ May 20, 2018 21:53 |
|
prisoner of waffles posted:Thoughts? (prayers?) And I hope you can transition to something less grotesque.
|
# ¿ May 22, 2018 00:55 |
|
LifeLynx posted:I want to do something incredibly simple and commonplace, but I can't find an answer for it. I want to animate (fade-in and up) when an element would scroll into view. I can't find a vanilla JS or even jQuery answer for this, but maybe I'm trying to reinvent the wheel here? Is there a script anyone can recommend to do this fancy animate when scroll into view stuff with minimal bloat? https://www.w3schools.com/css/css3_animations.asp
|
# ¿ Jun 6, 2018 15:00 |
|
Is there a WebRTC guide suitable for games somewhere (ie. I don't need to know about streaming video or media bits, I just want peer-to-peer data channels as simply as possible without having to use any particular framework; a small standalone library is fine). I recognize that I have to do something server side, which seems to be just "transmit a single JSON object from the WebRTC host to the WebRTC client" if I understand things correctly(?). And it also seems to be recommended to run a STUN and/or TURN server to avoid an external dependency on those things, maybe? And I recognize that it's going to be horrible, because network communication is always horrible. It's just this initial connection-forming bit that is unfamiliar and all the "simple instructions" I find go immediately to "here's how to stream a video" and then "now you're done, yay!" which is not really very similar to what I want. I'm sure I could figure it out from the API documentation but it seems likely there's something better out there and I'm just missing it in my searches, like I was missing parceljs.
|
# ¿ Jun 11, 2018 06:36 |
|
Chenghiz posted:Put a link to site A on site B and check its style using getComputedStyle to see if it's been visited or not. Or go nuts and encode your information into the colors of a png-encoded image, since those are allowed cross-site by default. Edit: later realized the suggestion I'm replying to was not to load something from the other site but to literally just put a link and interpret whether the browser styles it :visited or not. roomforthetuna fucked around with this message at 00:56 on Jun 20, 2018 |
# ¿ Jun 19, 2018 05:21 |
|
IAmKale posted:roomforthetuna is talking about CORS. It's something configured server-side as a security measure to limit which websites can make requests to that server. For example it can be used to restrict code in a .js file loaded in http://bar.com from making requests to API endpoints at http://foo.com. Anyway, my point here is that the server-side CORS configuration (which is headers you send with the page) is not so much used to restrict a script from making requests of foreign endpoints, but rather is used to tell the browser to not restrict those requests like it normally would.
|
# ¿ Jun 20, 2018 00:54 |
|
I just learned async/await. It makes regular Promises look stupid (except for those edge things where you have to put a Promise around some old callback-type function to make it async-able.) But for like 95% of asynchronous things it's great. And especially for unit tests, where promises are loving terrible.
|
# ¿ Jul 13, 2018 04:05 |
|
Lumpy posted:Async uses Promises under the hood. Makes you think. code:
|
# ¿ Jul 14, 2018 00:41 |
|
FSMC posted:*What does the "=>" mean is mostly equivalent to function (aaa, bbb) {some stuff} Except the arrow version doesn't have its own "this" and "arguments" bindings, it inherits those from its scope, where the "function" version has its own. 90% of the time it doesn't matter, and 90% of the *rest* of the time, the arrow version is more likely to be what you expected than the "function" version. (There are some other differences you almost certainly don't care about at this level.) Edit: also the thing to search for if you want to learn more about it is "arrow functions". roomforthetuna fucked around with this message at 04:19 on Jul 15, 2018 |
# ¿ Jul 15, 2018 04:16 |
|
geeves posted:Careful with forEach on a NodeList it's not exactly the same as an array. Babel probably takes care of this, but just in case, you probably are safer with: forEach is horrible to debug and horrible to reason about.
|
# ¿ Jul 18, 2018 06:44 |
|
Suspicious Dish posted:The performance of for...of is terrible, since it requires an allocation on each loop, and next() has not been optimized in most engines. forEach and for loops don't have that issue. I've gotten multi-FPS speedups by changing for...of to forEach in some of my work. for (let a of list) { ... } should be equivalent to for (let i = 0; i < list.length; i++) {let a = list[i]; ... } except for not taking up any namespace for i. (Edit: if the 'a' is the allocation then I would think forEach would require the same allocation for the 'a' in list.forEach((a) => { ... }).) (Edit2: are you think of it as it applies to key-values rather than arrays, where you have to do Object.keys(map) and *that's* the allocation? I do see the value in forEach for key-value situations.) roomforthetuna fucked around with this message at 22:30 on Jul 18, 2018 |
# ¿ Jul 18, 2018 22:26 |
|
Aha, thanks for the explanation. And that makes me sad.
|
# ¿ Jul 18, 2018 22:43 |
|
I'm trying to get my head around the behavior of node_modules (with typescript). It seems like the standard way of installing your module dependencies is "npm install whatever" in your project path, which makes a node_modules folder, which seems like ... a heap of crap. I don't want all the dependencies of a project in the same path as that project. But it seems that "npm install -g whatever" to install things in the global space doesn't make them available for imports? What's the non-stupid way of doing this? I must be missing something. People do this with git, and surely don't have all their dependencies in their git repositories - do they just put node_modules in their .gitignore? If so, are the dependencies captured somewhere else so there's a record of what your module needs somewhere? Or are you supposed to set it up so you do npm install somewhere *above* your project path? Everything I find saying how to do things just seems to manually mash the node_modules dependencies right into the middle of your project, surely that can't really be the way?
|
# ¿ Jul 26, 2018 03:19 |
|
Aha, thanks guys. So I was close to guessing right, it just seems weird, having the same module installed in multiple places if you work on multiple things. Oh well. And thanks for the --save tip, that seems less irritating than having to do the install and modify the file manually. (Though as you say, does seem weird that it's not the default.)
|
# ¿ Jul 26, 2018 04:05 |
|
Joda posted:I put them in global and link to projects. Is that bad?
|
# ¿ Jul 26, 2018 15:51 |
|
evilfunkyogi posted:Or work on multiple projects that might need different versions of the same package.
|
# ¿ Jul 27, 2018 01:35 |
|
Also, if you hate bundled JS for potentially being a horrifying giant file most of which isn't used, there is dynamic importing, but it's significantly more of a pain. (Dynamic importing, code splitting) (I'm using this because I'm trying to make multiple minigames through one interface operating with persistent WebRTC connections - loading the minigames only on demand makes sense.)
|
# ¿ Aug 25, 2018 21:21 |
|
Speaking of which, now I have a problem. (Or "you have a problem, so you decided to use webpack, now you have two problems.") I'm trying to do a webpack config that can build two things. At the moment I've disabled one of them while I work on the other, but webpack keeps trying to build files it should have no reference to. ie. with the following webpack.config.js I get ERROR in [...]\client\somefile.ts When as far as I can tell it shouldn't be looking in /client/ at all, no files in there are referenced by any of the files in /server/. What am I misunderstanding? It it just trying to build all ts files below the current path just in case I might want them at some point? code:
roomforthetuna fucked around with this message at 21:05 on Aug 26, 2018 |
# ¿ Aug 26, 2018 18:27 |
|
I found the answer to my own question - a missing option with a surprising default:code:
|
# ¿ Aug 27, 2018 04:01 |
|
roomforthetuna posted:I found the answer to my own question - a missing option with a surprising default: These defaults loving suck, this build system loving sucks, and so do all the others, argh, I should have just used makefiles. Edit: also tsconfig-paths-webpack-plugin sigh. Edit2: vvvv Yeah, fair enough, getting the ONE external dependency I want to use to work with makefiles would probably have been as much hassle as all this stupid poo poo. roomforthetuna fucked around with this message at 04:24 on Aug 29, 2018 |
# ¿ Aug 29, 2018 01:13 |
|
Joda posted:Busy waiting (which is what that is,) and sleeping aren't the same thing, and pure busy waiting is bad concurrency practice regardless of language. Edit: if you're going to busy-wait, at least mine a bitcoin or something with those 'idle' cycles.
|
# ¿ Sep 5, 2018 03:16 |
|
Generally, you want to use arrow functions when you're using them as functions to pass around, and function() functions when you're defining members or scoped standalone real functions. In the majority of cases doing this will give you the intuitive behavior rather than the confusing behavior. Doom Mathematic gave the example where arrow functions in the wrong place gives you confusing behavior. The example where function() functions in the wrong place gives you confusing behavior is something like: code:
|
# ¿ Sep 8, 2018 18:26 |
|
Is there a typescript+webpack solution for debug logging that gets completely elided from final distributed code? I want to log to the console while I'm developing, because I have a fairly complicated websocket thing going on that I'd like to easily see what communication is happening, but in a release version I'd like that logging code not just uncalled but removed. I found libraries but they don't seem to do elision. I found you can get uglify to elide useless code, define DEBUG, and then do DEBUG && console.log(...) every time, but that seems verbose. I found grunt-strip, that does what I want with grunt and js, but I don't know how I'd apply that in webpack+ts. I found webpack-strip-debug, which again seems to be applying to js not ts, maybe it could be chained after the ts compile step? Not even edit, answered my own question, but sharing because someone else might be interested: code:
code:
code:
(I could more easily just strip all console.log, by doing WebpackStripLoader.loader('console.log') instead of 'debug' but sometimes I want to leave a console.log in.)
|
# ¿ Sep 14, 2018 07:22 |
|
Hypnobeard posted:I'm just starting out in Javascript/ES6, so this is confusing the heck out of me. What am I missing, either in my file or in the test spec? You either want code:
code:
Or a different syntax of export.
|
# ¿ Sep 15, 2018 15:26 |
|
Hypnobeard posted:Removing the braces fixed it. (ESLint was complaining if I tried to shift to export const.. without a default.) So many ways of doing modules, each just different enough to be confusing. I'm using typescript now so everything is slightly different another different way.
|
# ¿ Sep 15, 2018 15:48 |
|
Suspicious Dish posted:import * as Foo from './foo'; is what I use but they chose the ugliest import syntax for a really good idea code:
code:
|
# ¿ Sep 15, 2018 20:13 |
|
I've changed my mind, I do dislike import * as Foo from '...' because I want the syntax for that to be just import Foo from '...' Having a default and individual exports is weird, I expect individual exports to just be combined into the single default exported object, and import {a, b, c} from '...' to be essentially interpreted as destructuring that single exported object.
|
# ¿ Sep 15, 2018 21:07 |
|
Hypnobeard posted:Thinking about it, my question is more "how do I get the error in an Array?"--because the ways I know about don't seem to produce what the test is looking for. (Especially since you showed the test code and it wasn't saying expect it to throw an array.) It is a bit poo poo of the framework not to use the same delimeters for the "what you got" output though.
|
# ¿ Sep 21, 2018 01:01 |
|
If you use yarn link / npm link, and then modify the dependency package, what behavior should you expect? 1. Like makefiles the change magically resolves and your final dist just works with the new files. 2. You have to do some sort of build operation to a dist folder on the dependency package, but then the new files will work. 3. You have to do some sort of build operation to a dist folder and then also do the whole link process again. (Asking rather than trying because right now I just have modules from relative paths, and converting those paths to packages is a moderate amount of work that's not worth doing if it's just going to make my workflow worse. I'm only considering it because for some reason the remote-linked modules are complaining about missing tslib if I try to write async/await things, even though their closest tsconfig.json is essentially identical to the one near the non-remote-linked modules which can do async/await things just fine.) Edit: my current workaround is just writing async functions in the form of functions that return promises and do all that awkward loving around with .then(), which I can keep doing if it's not worth the effort of packaging things properly while they're in parallel development. roomforthetuna fucked around with this message at 06:08 on Sep 21, 2018 |
# ¿ Sep 21, 2018 06:04 |
|
Joda posted:E2: Found the issue. I was calling the function from another component, and the function inherited the scope I guess. code:
You can instead do this kind of thing like code:
|
# ¿ Nov 10, 2018 17:00 |
|
Bruegels Fuckbooks posted:[prefer bind] it's a little terser The "more explicit" thing is an okay reason though. I prefer the lambda because I use it elsewhere too - not using bind means one fewer thing I have to remember how it works. Edit: oh wait, someObj.someFunc.bind(this) would do the thing that you probably *don't* want, anyway. someObj.someFunc.bind(someObj) would be the thing you more likely want to do. roomforthetuna fucked around with this message at 02:10 on Nov 11, 2018 |
# ¿ Nov 10, 2018 19:17 |
|
Munkeymon posted:It's still prototype-based and you still have to bind methods that care about having the class's this available. Any language that *doesn't* require you to do it is still just doing it for you in secret. The difference with Javascript is that it won't tell you you're doing it wrong, it'll just do the wrong thing.
|
# ¿ Nov 13, 2018 01:19 |
|
Munkeymon posted:Is it that common to call members functions/class methods as function pointers from other methods in the same class in C++? But before lambdas, yeah, maybe not common, but not uncommon. Edit: common enough that "member function pointer" is a thing at all. It's not like they have much other purpose.
|
# ¿ Nov 13, 2018 22:04 |
|
huhu posted:1. Is it worth it to learn "Vanilla JavaScript"? I feel like at this point I know a solid amount of stuff about JS. In the Electron tutorial I understand selectors and such but I'd much rather work with JSX and JS than deal with the actual intersection of HTML and JS. I know other people who mostly use React and find it a relief when they're allowed to just use vanilla JS. A strong benefit of not using some framework is that vanilla JS seems much less likely to get changed out from under you and force you to rewrite a bunch of stuff. But maybe I've just been super unlucky with being burned that way literally every time I use any kind of framework for anything.
|
# ¿ Nov 23, 2018 06:30 |
|
necrotic posted:No, I mean literally the value at array.length. Not some code analysis.
|
# ¿ Dec 3, 2018 16:20 |
|
Munkeymon posted:After doing i++ for years just because that's how all the examples I learned from do it, I thought about it for a minute and realized that ++i is the operation I actually wanted/needed, so started doing it that way instead. Like if you have two equivalent functions that mutate a thing but one returns a value that you just don't use, I stop and wonder why. i = 5; i += 5; i.update(); i = someSortOfOperation(i); The only other thing that comes to mind where the mutated thing is at the tail is functions with output parameters, which tended to be a workaround for functions only returning one thing, which is increasingly not true these days (C++ returning tuples, Javascript returning objects or arrays and deconstructing at the call site, etc.)
|
# ¿ Dec 5, 2018 16:45 |
|
|
# ¿ Apr 29, 2024 13:34 |
|
Lumpy posted:"I have 3 days to write this, and I don't think learning typescript and getting the tooling all set up will fit in that."
|
# ¿ Dec 12, 2018 05:54 |