|
Dumb Lowtax posted:OH forgot it was bitwise and not boolean for a second, whoops What's wrong with code:
|
# ? Jul 14, 2019 20:34 |
|
|
# ? May 27, 2024 02:21 |
|
If you need -2 for whatever reason, feel free to use ~true.
|
# ? Jul 14, 2019 20:39 |
|
The Fool posted:What's wrong with With_a_long_enough_variable_name_that_becomes = !With_a_long_enough_variable_name_that_becomes
|
# ? Jul 14, 2019 20:49 |
|
I don't see the problem
|
# ? Jul 14, 2019 20:56 |
|
The Fool posted:I don't see the problem This. Don't be clever, be clear.
|
# ? Jul 14, 2019 20:59 |
|
Dumb Lowtax posted:With_a_long_enough_variable_name_that_becomes = !With_a_long_enough_variable_name_that_becomes If only there was some way to quickly type out a long string.
|
# ? Jul 14, 2019 21:16 |
|
Dumb Lowtax posted:Is everything like that considered too unreadable? Is it a horror to do code:
|
# ? Jul 14, 2019 21:21 |
|
Ola posted:If you need -2 for whatever reason, feel free to use ~true.
|
# ? Jul 14, 2019 21:23 |
|
roomforthetuna posted:// This is false but with actual toggling would be true. Yikes, I guess the only thing that's saved me from that is that I haven't been using === at all
|
# ? Jul 14, 2019 21:33 |
|
Dumb Lowtax posted:Yikes, I guess the only thing that's saved me from that is that I haven't been using === at all
|
# ? Jul 14, 2019 21:49 |
|
Ola posted:If you need -2 for whatever reason, feel free to use ~true. And if you need true you can write !!-2
|
# ? Jul 15, 2019 14:48 |
|
Cross posting from the web dev thread Sab669 posted:having some weird issue where a specific page in my software is loading scrolled half way down the page.
|
# ? Jul 15, 2019 16:21 |
|
Munkeymon posted:And if you need true you can write !!-2
|
# ? Jul 16, 2019 00:20 |
|
I need help doing something stupid for a silly, backend/Node side project. I want one main, parent Typescript project that uses one or more standalone sub-projects, also written in Typescript. I'm basically trying to roll my own plugin system, just for fun. As you might expect, I'm running into module errors. I'm not experienced enough to tell if this is a Node problem, a TSC/compiler problem, a VS Code task configuration problem, something I need to use a bundler for, something I need to code around, some combination of the above, or an impossible task. I think the problem involves separate, independent node_modules/ directories that are not getting picked up by TSC when it compiles .ts to .js files, but there are too many intersecting technologies for me to get much farther. Any ideas or useful search terms? code:
|
# ? Jul 18, 2019 05:23 |
|
you can start by posting the errors you're hitting, maybe
|
# ? Jul 18, 2019 13:51 |
|
Look at either yarn workspaces or the lerna tool. They are both tools to manage many related projects in one repo, and handles shared dependencies for you.
|
# ? Jul 18, 2019 17:12 |
|
Are you using TypeScript's relatively new Project Reference API? I haven't used it, but it sounds like what you're trying to achieve.
|
# ? Jul 18, 2019 17:22 |
Alternatively, just use separate repos for your submodules and then use yarn/npm link to do symlinked development without having to push all the time?
|
|
# ? Jul 18, 2019 17:26 |
|
I have a question about TypeScript. One of the benefits of a type system is making promises to the compiler for better performance, right? That sounds nice. With vanilla JS I run into performance issues with basic types that I make for math. Even declaring simple tuples of a few numbers (as a custom math vector type) in Vanilla JS is hard to do in a way that avoids an allocation, where it wouldn't end up on the heap and need garbage collection. Is TypeScript able to declare a small float tuple without allocating?
|
# ? Jul 18, 2019 17:59 |
|
Dumb Lowtax posted:I have a question about TypeScript. One of the benefits of a type system is making promises to the compiler for better performance, right? That sounds nice. With vanilla JS I run into performance issues with basic types that I make for math. Even declaring simple tuples of a few numbers (as a custom math vector type) in Vanilla JS is hard to do in a way that avoids an allocation, where it wouldn't end up on the heap and need garbage collection. Is TypeScript able to declare a small float tuple without allocating? TS just transpiles to JS, assuming all type constraints are satisfied, so it can do exactly what JS can do. I guess someday they might add the option to compile to Web Assembly or whatever they call it now, but right now it's a strict superset of JS.
|
# ? Jul 18, 2019 18:13 |
|
Dumb Lowtax posted:I have a question about TypeScript. One of the benefits of a type system is making promises to the compiler for better performance, right? That sounds nice. With vanilla JS I run into performance issues with basic types that I make for math. Even declaring simple tuples of a few numbers (as a custom math vector type) in Vanilla JS is hard to do in a way that avoids an allocation, where it wouldn't end up on the heap and need garbage collection. Is TypeScript able to declare a small float tuple without allocating? The only way to avoid garbage collection is to not make garbage. If you're having issues with GC pauses, the first step is to remove any unnecessary "new" calls you're making. If you've already done that, you're going to need to implement object pooling, and reuse the objects instead of calling new every time - e.g. instead of doing new Point() or whatever, make everything use PointPool.Alloc() and PointPool.Recycle(), and just hydrate the recycled points in the alloc. If calling new() on your type is expensive or creating GC pressure, this will avoid that.
|
# ? Jul 18, 2019 19:51 |
|
Setting up object pooling seems painful and bloated compared to how in C++ I can just say "Vector3 v;" in a function's scope and it will just harmlessly increase the size of that call stack frame and harmlessly disappear when the function ends. I assume it happens that way in JavaScript too when I declare something of type Number, but not much else because any other temp data object I make seems to depend on calling new(), even something as simple as "three floats". Is that one of the big compromises the language designers had to do to make JavaScript work? Designing it in a way that doesn't get to use the stack much?
|
# ? Jul 18, 2019 20:04 |
|
BTW currently my solution is to have a couple static functions for generating a vector of 3 floats: one safe, and one unsafe. The "unsafe" one has to be consumed immediately because it always aliases to the same vector object, but it avoids an allocation. My object "pool" size is therefore 1, and it helps a tiny bit while saving my small Vector class implementation from having to confuse students (who will mostly never find out about the unsafe one) with a big object pooling algorithm inside of it, but it comes at a cost that most of my other Vectors are slow. I also recently realized that my "in-fix" math operations like a.plus(b) require an allocation because they return a new Vector, so for inner loops I now provide alternative "pre-fix" math operations like a.add(b) that modify a vector in place. A little less readable for long math expressions, but it avoids the GC.
|
# ? Jul 18, 2019 20:10 |
|
Dumb Lowtax posted:Setting up object pooling seems painful and bloated compared to how in C++ I can just say "Vector3 v;" in a function's scope and it will just harmlessly increase the size of that call stack frame and harmlessly disappear when the function ends. I assume it happens that way in JavaScript too when I declare something of type Number, but not much else because any other temp data object I make seems to depend on calling new(), even something as simple as "three floats". Is that one of the big compromises the language designers had to do to make JavaScript work? Designing it in a way that doesn't get to use the stack much? Yeah, it sucks. It's not a unique constraint to javascript though - any garbage collected language (e.g. C# or Java) will have similar issues (e.g. witness the rise of ArrayPool<T> in C#.) Garbage collection has gotten better over time, but once you hit performance issues with GC you will have to take measures like Array pooling etc. In many real world cases though, a hundred millisecond hiccup every so often isn't that big a deal - if you' have a use case where it does matter, then either you use array pooling for everything, disable the GC and just keep terminating the process and restarting it every so often, or just write the thing in a non gc language.
|
# ? Jul 18, 2019 20:18 |
|
C# has struct types that can be allocated on the stack. In my own projects I just have globals for scratchpad storage, and then write everything in this style:JavaScript code:
What even more sucks is new-style java script: using for...of will create a new object every iteration. Katelyn Gadd (someone who is consistently ahead of me in finding about this and yelling about things) yelled about this in 2015, and nobody cared. "Engines will be optimized", they said. They still haven't, four years later. fuckin lmao i guess
|
# ? Jul 19, 2019 04:21 |
|
Suspicious Dish posted:What even more sucks is new-style java script: using for...of will create a new object every iteration. Katelyn Gadd (someone who is consistently ahead of me in finding about this and yelling about things) yelled about this in 2015, and nobody cared. "Engines will be optimized", they said. They still haven't, four years later. fuckin lmao i guess code:
code:
|
# ? Jul 19, 2019 04:37 |
|
the iterator protocol says that for...of is syntactic sugar for this expanded code:JavaScript code:
JavaScript code:
|
# ? Jul 19, 2019 04:43 |
|
Suspicious Dish posted:the iterator protocol says that for...of is syntactic sugar for this expanded code:
|
# ? Jul 19, 2019 05:00 |
|
roomforthetuna posted:Oh god. Can we just burn all the languages that aren't C++? I could talk non-stop for weeks about poo poo in C++ I hate, but hey, at least it doesn't have GC pauses.
|
# ? Jul 19, 2019 05:23 |
|
Suspicious Dish posted:C# has struct types that can be allocated on the stack. In my own projects I just have globals for scratchpad storage, and then write everything in this style: JavaScript [Questions Megathread]: It sucks, but it it what it is.
|
# ? Jul 19, 2019 14:44 |
|
Weird issue where I'm trying to just pass my form off to the server but 1 specific property isn't having its value set correctly for some unknown reason. cshtml defines a checkbox bound to a Model property like so: code:
JavaScript code:
If I try to manually add PAIIntFupAss.MiniFIM = $("#chkMiniFIMIntFup").val(); on the following line, the C# throws an error along the lines of "MiniFIM is already defined" or something to that effect? Sounds like this assignment is adding a second 'key' named "MiniFIM" to the dictionary somehow If I add a watch for $('#frmPAIIntFupAss') I can expand it, find my checkbox, and it has the value true / name is MiniFIM so ObjectToJSON should be working correctly? I have no idea what's going wrong. And that is the only control bound to that property Sab669 fucked around with this message at 21:12 on Jul 25, 2019 |
# ? Jul 25, 2019 21:06 |
|
What's the HTML output look like?
|
# ? Jul 26, 2019 13:51 |
|
Page Inspector gives me this: Checked <input checked="checked" class="k-checkbox" id="chkMiniFIMIntFup" name="MiniFIM" onclick="PAIValidateMiniFim()" tabindex="1" type="checkbox" value="true"> <label class="k-checkbox-label" for="chkMiniFIMIntFup">Perform PAC-CFI Assessment</label> <input name="MiniFIM" type="hidden" value="false"> Unchecked: <input checked="checked" class="k-checkbox" id="chkMiniFIMIntFup" name="MiniFIM" onclick="PAIValidateMiniFim()" tabindex="1" type="checkbox" value="true"> <label class="k-checkbox-label" for="chkMiniFIMIntFup">Perform PAC-CFI Assessment</label> <input name="MiniFIM" type="hidden" value="false"> So actually, that's really curious. I assume it's pulling the value from this hidden Input rather than the checkbox? But this checkbox is defined identically to another checkbox on a different form that basically does the same thing Literally the only difference is the ID and the onclick (which just shows a popup, then clears some textboxes if they click YES, does nothing / unchecks the checkbox if they click NO) Sab669 fucked around with this message at 14:16 on Jul 26, 2019 |
# ? Jul 26, 2019 14:12 |
|
The JS serializer is probably overwriting the first value with the false value it finds second. IIRC, ASP MVC goes with the first one it finds*, but it's strange that your input is checked when you're saying it's unchecked - are you looking at the live DOM or viewing the source? * When checked, both values are submitted and the deserializer would just go with the first one it sees for the value. When unchecked, only false is submitted. I'm not sure you need the hidden input if you use a form model since the property would default to false, but there are ~5 ways to turn form data into POCOs/values of various sorts (without even considering JSON!) so YMMV Munkeymon fucked around with this message at 14:29 on Jul 26, 2019 |
# ? Jul 26, 2019 14:27 |
|
Munkeymon posted:are you looking at the live DOM or viewing the source? Live, I guess? Run the software -> Hit F12 -> Inspector tab (Firefox) The hidden input must be some Telerik/Kendo nonsense. I definitely didn't manually define it myself. code:
|
# ? Jul 26, 2019 14:36 |
|
I love working in ASP.NET MVC as the Senior Front End at the company and being repeatedly told by the .NET devs that they're full stack because they know jQuery because it comes bundled with ASP.NET MVC 4 and therefore we really don't need anything else because they've got it covered
|
# ? Jul 26, 2019 16:15 |
|
I thought jQuery was only used today by people who don't know how to use anything else
|
# ? Jul 26, 2019 16:39 |
|
Sab669 posted:Live, I guess? Run the software -> Hit F12 -> Inspector tab (Firefox) Yeah, I'm saying that's a fairly normal way to do it so that there's always a value sent to the server on form submit. Left unstated was the fact that a checkbox input that's not checked is just omitted from the data sent by a browser POSTing a form. Frameworks that want to see some value no matter what do that checkbox+hidden trick and I think what's going on is that the serialization your JS is doing has the opposite behavior of that of MVC, so HTML output assuming MVC will consume the form data doesn't work right. You might have to crack open the JS serialization code and change the behavior such that it refuses to overwrite values when it sees the same name a second time. Of course I might be wrong about all of this if you're not seeing the DOM change when you uncheck that box. Kendo might be doing something silly in handlers that's supposed to be tracking all of these values.
|
# ? Jul 26, 2019 18:44 |
|
I have a UL with a couple of LI's with classes "fa-chevron-up/down". When the class is clicked, the function gets called. That is working when the page is loaded. I also dynamically create new LI's, but when I do this , the functions stop working. Currently I have my script as such. How do i make it so the new LI's will also call the .fa-chevron functions? the dynamically created Li's are exactly in the same structure as before in the UL <code> $(function () { var selected=0; var itemlist = $('#finalList'); var len=$(itemlist).children().length; $(".fa-chevron-up").click(function(e){ var selected= $(this).parents('li').index() e.preventDefault(); if(selected>0){ jQuery($(itemlist).children().eq(selected-1)).before(jQuery($(itemlist).children().eq(selected))); selected=selected-1; } }); $(".fa-chevron-down").click(function(e){ var selected= $(this).parents('li').index() e.preventDefault(); if(selected < len){ jQuery($(itemlist).children().eq(selected+1)).after(jQuery($(itemlist).children().eq(selected))); selected=selected+1; } }); }); </code>
|
# ? Jul 31, 2019 20:28 |
|
|
# ? May 27, 2024 02:21 |
|
Because your code only assigns event handlers to elements that exist on load. New elements don't get them. Looks like you are using jQuery, so you will want to .on to make it so the new ones also get the event. It's been a very, very long time since I did jQuery, but I think something like this: JavaScript code:
|
# ? Jul 31, 2019 20:35 |