|
Pollyanna posted:Is defining functions in a function expensive in any way? I had the idea to compartmentalize the logic of a complicated function by breaking its logic into functions defined within its scope, I.e. nested constantly and poo poo, so that those functions don’t clutter up wherever the parent function is used. Is there a reason not to define a function inside another function, even if it’s only used in that parent function? You are creating a closure when doing that... which isn't nothing, but it's not expensive. Don't do it in a loop, but otherwise no, it's not a big deal. You should be mainly concerned with how it affects readability.
|
# ? Dec 13, 2017 18:24 |
|
|
# ? Jun 5, 2024 07:46 |
|
Pollyanna posted:Is defining functions in a function expensive in any way? I had the idea to compartmentalize the logic of a complicated function by breaking its logic into functions defined within its scope, I.e. nested constantly and poo poo, so that those functions don’t clutter up wherever the parent function is used. Is there a reason not to define a function inside another function, even if it’s only used in that parent function? There's really no point doing that now that let is a keyword.
|
# ? Dec 13, 2017 19:04 |
|
Pollyanna posted:Is defining functions in a function expensive in any way? I had the idea to compartmentalize the logic of a complicated function by breaking its logic into functions defined within its scope, I.e. nested constantly and poo poo, so that those functions don’t clutter up wherever the parent function is used. Is there a reason not to define a function inside another function, even if it’s only used in that parent function? code:
Capri Sun Tzu fucked around with this message at 19:14 on Dec 13, 2017 |
# ? Dec 13, 2017 19:11 |
|
So I am curious, I created a component in a product that generates dynamic forms from data it receives from the server. Because of the dynamic nature of the data, state is a PITA to manage. I came up with a clever solution but seem to be shouted down a bit, and I am curious if you guys would also hate this. I understand that typically we want to elevate state but honestly sometimes it just seems to dogmatic practice as opposed to good practice. I created a parent <Form> component, that recieves a prop that contains the dynamic data about the form, and then dynamically creates a ton of children components that are various types of input fields. All of these input fields manage their own state, they receive properties about validation, labelling and styling but they are their own boss when it comes to validity and value. Then I added two exposed functions on the parent Form component: -validate() -> which cycles through all of the children inputs, asks them to validate, while recieving this validity value, and then returns true if the whole form is valid or false if at least one value is false. -get data() -> which cycles through all the children inputs and creates a dynamic object of values. The reason being, when you need to submit the form the logic is as simple as: code:
Thoughts?
|
# ? Dec 13, 2017 20:33 |
|
Knifegrab posted:I quite think the solution is elegant, and flexible and half my coworkers agree but the other half are screeching. It is elegant now. But it's also incredibly annoying that any time you want new behaviour from a form field, or a new type of form field, you have to go in and hack someone's API. For example what if you wanted a specific form field that had a specialised popover that's only relevant to one page of the application? Hopefully that is happening fairly often. With your solution that is a big pain, because you have re-written HTML.
|
# ? Dec 14, 2017 17:15 |
|
Nolgthorn posted:It is elegant now. But it's also incredibly annoying that any time you want new behaviour from a form field, or a new type of form field, you have to go in and hack someone's API. For example what if you wanted a specific form field that had a specialised popover that's only relevant to one page of the application? Hopefully that is happening fairly often. Just omit that field from the form component and add it at the parent level? code:
Also I am not super sure how elevating state out of the form component would alleviate that issue? Can you elaborate?
|
# ? Dec 14, 2017 17:48 |
|
In my experience in general it's a good idea to leverage existing tools, especially at the lowest levels such as HTML CSS and JavaScript. I see way too often these days new solutions which completely replace those base toolsets. It forces developers then to have to choose between the in house version or another custom thing. Or combine them. My solution would be more along the lines of something that eliminates duplicated code, but not a replacement for basic tooling. For example, a function that takes a reference to a form and a set of validation criteria. Or a function that takes a reference to a form and returns the data from that form as you like it. Doesn't your answer to my question place that new field outside the `form` element?
|
# ? Dec 14, 2017 17:58 |
|
Nolgthorn posted:In my experience in general it's a good idea to leverage existing tools, especially at the lowest levels such as HTML CSS and JavaScript. I see way too often these days new solutions which completely replace those base toolsets. It forces developers then to have to choose between the in house version or another custom thing. No, it places it adjacent to the form, they are siblings. The form generator is only responsible for generating a series of inputs, not the controls for the form or anything so you can inline it with however many additional bells and whistles you'd like.
|
# ? Dec 14, 2017 18:16 |
|
I'm stuck on Jest / react snapshots - I get this error: "TypeError: Cannot read property 'ReactCurrentOwner' of undefined" Snapshots are a nice to have, I have pretty good coverage without them I've reduced my package.json dev/dependencies down to the bare minimum to run the tests (babel, jest and react) and continue to get this error. I see this up on github as a bug and very few mentioned on SO, but none that are just it's flatout not working.
|
# ? Dec 14, 2017 23:25 |
|
Sounds like a possible issue with a test library.https://github.com/chenglou/react-motion/issues/447#issuecomment-341429948 posted:I also had the problem with React 15 and jest, but updating to 16 was not an option. Downgrading react-test-renderer to ^15 worked though. But you definitely didn't give enough context if that isn't it. It's almost definitely a version mismatch, though.
|
# ? Dec 14, 2017 23:43 |
|
I've got this weird problem that I can't figure out for the life of me. I'm trying to make an ajax request to get content from another page, but for some reason, it's requesting it as http, rather than https: Here's what my call looks like JavaScript code:
|
# ? Dec 15, 2017 15:54 |
|
Grump posted:I've got this weird problem that I can't figure out for the life of me. I'm trying to make an ajax request to get content from another page, but for some reason, it's requesting it as http, rather than https: Is the URL the script is running from http or https? What happens if you explicitly put the full URL including the 'https://' in your request options? Why would it request `/productname` when they URL you have '/cart.php' as the URL?
|
# ? Dec 15, 2017 16:50 |
|
More of a conceptual question, but how should I think about extensibility? I've got a hobby project that is basically a static site generator, but I'd like to be able to bolt on essentially any silly project that I want in a way that doesn't tightly couple the code with the larger project. I know this is more convoluted than it needs to be, but I'm treating it as a learning opportunity. Essentially I'd like to put silly other projects into a separate repo. I'm not sure what concepts or patterns I should think about though.
|
# ? Dec 16, 2017 22:47 |
|
Kobayashi posted:More of a conceptual question, but how should I think about extensibility? I've got a hobby project that is basically a static site generator, but I'd like to be able to bolt on essentially any silly project that I want in a way that doesn't tightly couple the code with the larger project. I know this is more convoluted than it needs to be, but I'm treating it as a learning opportunity. Essentially I'd like to put silly other projects into a separate repo. I'm not sure what concepts or patterns I should think about though. Consider using glitch.com, by the makers of stackoverflow. It's like pastebin, but for web servers. You get your own webserver with a front end, back end, and permanent URL just by visiting glitch.com and hitting go. Your current static site could be served from the first thing you make on there, and then you can just hit "remix project" to generate a new similar project whenever you feel like. It's how I generated a hurricaine irma cams website with its own URL, within like 30 seconds of someone posting the HTML code that loaded them all -- because I already had other things on glitch.com and it was simply a matter of hitting the remix button on one of them to generate a new branch. In some inception level poo poo, my main project on glitch is its own service like pastebin, where visitors can edit a WebGL animation and get their own permanent URL showing their custom animation.
|
# ? Dec 16, 2017 23:22 |
|
Kobayashi posted:More of a conceptual question, but how should I think about extensibility? I've got a hobby project that is basically a static site generator, but I'd like to be able to bolt on essentially any silly project that I want in a way that doesn't tightly couple the code with the larger project. I know this is more convoluted than it needs to be, but I'm treating it as a learning opportunity. Essentially I'd like to put silly other projects into a separate repo. I'm not sure what concepts or patterns I should think about though. You shouldn't really think too much about extensibility as an end unto itself, as it's easy to go too far. You have to be thinking about it in relation to a real problem you have, so you can decide on the appropriate level of abstraction is, and even then, maybe you don't need it? I've found it best to do simple things, even if it's been done before, and as commonalities become more apparent, refactoring into a more abstract form. This helps keep you from going off the rails and inventing a new language to make changing the color of a button easier.
|
# ? Dec 17, 2017 00:54 |
|
Dumb Lowtax posted:Consider using glitch.com, by the makers of stackoverflow. It's like pastebin, but for web servers. You get your own webserver with a front end, back end, and permanent URL just by visiting glitch.com and hitting go. Skandranon posted:You shouldn't really think too much about extensibility as an end unto itself, as it's easy to go too far. You have to be thinking about it in relation to a real problem you have, so you can decide on the appropriate level of abstraction is, and even then, maybe you don't need it? I've found it best to do simple things, even if it's been done before, and as commonalities become more apparent, refactoring into a more abstract form. This helps keep you from going off the rails and inventing a new language to make changing the color of a button easier. Thanks, but I specifically want to get into the weeds on this one. I want to dabble in some of the architectural issues that I imagine come with a project like this. It's all about the learning experience. By comparison, I'm already implementing my little static site generator as a REST API, even though it would be quicker and easier to build the frontend and backend together as a monolith. The site generator is just a vague north star, the real value for me is getting a bit of practical experience with API design. Similarly, I'm interested in writing modular, extensible code. I suspect this involves concepts like dependency injection and class design and lifecycle hooks but all I know about that stuff is basically what I just typed. I'm not sure what to search for, or what projects to use as a blueprint. That's why I'm asking. E: I should say that I'm not a professional engineer and I don't plan to become one. This is just a hobby for me.
|
# ? Dec 18, 2017 01:58 |
|
I made a JavaScript class called "Vec" that extends the built-in Float32Array. I generate an array of a few floats, using the built-in of() function from ES2015 like this: Vec.of( 1,2,3 ) This makes a Vec. I pass the result into a function, and then try to call Vec methods on it. This crashes on phones. Just phones. The code mentioned above isn't part of some new program I'm testing that might be buggy. It's part of a larger library - unmodified from a version that I oversaw over a hundred people using this month without incident on desktop and laptop computers in various browsers. But when I run it in iOS with Safari web inspector, that's the part it says it's getting tripped up on -- (argument name).(method name) is undefined. I hover the mouse over the argument and sure enough, the type of it shows up as Float32Array instead of Vec. Does anyone have any clue of what might cause this? Are there any known issues with subclassing typed arrays on phones??? It wouldn't be the first time I've experienced weirdness with subclassing the typed arrays and suddenly getting bugs in code that worked fine back when it only used regular arrays. Said weirdness already is the reason I'm having to use .of() at all, instead of just saying "new Vec( 1,2,3 )". Happy Thread fucked around with this message at 06:01 on Dec 18, 2017 |
# ? Dec 18, 2017 05:57 |
|
Dumb Lowtax posted:I made a JavaScript class called "Vec" that extends the built-in Float32Array. I generate an array of a few floats, using the built-in of() function from ES2015 like this: Test it on a bunch of phones/OS versions? Seems like specific browser/device/version bug so I'm not sure what you mean by 'phones' cause there's a lot of those if you count browser versions plus devices. I don't know why a given JVM would be unable to extend a 'class' via protopyal inheritance so maybe some actual smart people know why that could be a thing.
|
# ? Dec 18, 2017 06:17 |
|
Dogcow posted:Test it on a bunch of phones/OS versions? Seems like specific browser/device/version bug so I'm not sure what you mean by 'phones' cause there's a lot of those if you count browser versions plus devices. I don't know why a given JVM would be unable to extend a 'class' via protopyal inheritance so maybe some actual smart people know why that could be a thing. Ok in case it's not all phones, does anyone have a phone (besides an iPhone7+ running iOS 10)? Can you point it to http://encyclopediaofcode.glitch.me/ and tell me if the 3D animation shows up or not?
|
# ? Dec 18, 2017 06:29 |
|
Dumb Lowtax posted:Ok in case it's not all phones, does anyone have a phone (besides an iPhone7+ running iOS 10)? Can you point it to http://encyclopediaofcode.glitch.me/ and tell me if the 3D animation shows up or not? Doesn't show up but the browser doesn't crash, iPhone X iOS 11.1.2. Does anyone like this new LIVE DEBUGGING feature of the forums?
|
# ? Dec 18, 2017 06:36 |
|
Dumb Lowtax posted:Ok in case it's not all phones, does anyone have a phone (besides an iPhone7+ running iOS 10)? Can you point it to http://encyclopediaofcode.glitch.me/ and tell me if the 3D animation shows up or not? There is a 3D animation below the text and above the code on Chrome for Android (Sony F8331 running Android 7.1.1)
|
# ? Dec 18, 2017 06:46 |
|
Dogcow posted:Doesn't show up but the browser doesn't crash, iPhone X iOS 11.1.2. Hey, if we can find one phone that it works on, that would prove your hunch is right. By "crash" I mean doesn't show up, yes. A couple buttons might, but no 3D spinning animation, and empty dropdowns for those buttons.
|
# ? Dec 18, 2017 06:49 |
|
Dumb Lowtax posted:Hey, if we can find one phone that it works on, that would prove your hunch is right. Yup it's an iOS bug, support seems.. unknown, basic support is iOS 4.2: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array You don't get any errors using the inspector/debugger on a remote debugging session?
|
# ? Dec 18, 2017 07:02 |
|
Dogcow posted:Yup it's an iOS bug, support seems.. unknown, basic support is iOS 4.2: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array No my bad, I do indeed get errors on remote debugging (the method of Vec was undefined because it was a Float32Array and not a Vec), I was just assuming you had a different definition of "crash" since it sounded like you did not get any debugger errors when you said nothing showed up? What was it that you just found out? Did you find something in that link about these sorts of subclasses not returning their correct type from .of()? Or did you actually get it working on a different phone? edit: D'oh, just noticed the "mobile" tab on there under compatibility. I see what you're looking at now. Maybe I'm not reading the same thing into it. Happy Thread fucked around with this message at 08:15 on Dec 18, 2017 |
# ? Dec 18, 2017 07:48 |
|
Dumb Lowtax posted:Ok in case it's not all phones, does anyone have a phone (besides an iPhone7+ running iOS 10)? Can you point it to http://encyclopediaofcode.glitch.me/ and tell me if the 3D animation shows up or not? Doesn’t appear on 6s 11.2 w/ chrome
|
# ? Dec 18, 2017 23:26 |
|
Ok I had someone with an Android phone visit the page and it *worked*. WebGL animation spinning around with no JavaScript-stopping problems like undefined methods of my custom Vec class. So .of() is really creating a Vec and not a Float32Array. You were right, it's not all phones. It's iOS that does it. Should I report it to Apple? Is there any chance of it getting fixed? I'd love for my WebGL library to run on the most common phone. If my code works on everything but iOS then there's no way I'm just mis-using .of() or Float32Array right?
|
# ? Dec 19, 2017 05:41 |
|
Dumb Lowtax posted:Ok I had someone with an Android phone visit the page and it *worked*. WebGL animation spinning around with no JavaScript-stopping problems like undefined methods of my custom Vec class. So .of() is really creating a Vec and not a Float32Array. FWIW, Android is far more common than iOS. Apple has a decentish track record of fixing Safari bugs, but you've got to make it a good bug report!
|
# ? Dec 19, 2017 16:46 |
|
Thermopyle posted:FWIW, Android is far more common than iOS. iOS Safari (especially the iPhone version) has more quirks and nonstandard behavior than Android Chrome IME. All bets are off when using the Android browser, though. It is/was like you get a new Internet Explorer version per SKU. Thankfully, I think it's only on old phones that didn't get updated past 5 or 6.
|
# ? Dec 19, 2017 17:51 |
|
Thermopyle posted:FWIW, Android is far more common than iOS. Hmmm... ok, I'll try to make a minimal executable with the bug and host it online so I can also point an iPhone at it to verify. Then I'll have the report point to that. Thanks!
|
# ? Dec 19, 2017 20:08 |
|
Munkeymon posted:iOS Safari (especially the iPhone version) has more quirks and nonstandard behavior than Android Chrome IME. Agreed.
|
# ? Dec 19, 2017 21:03 |
|
OK, I think demonstrated the bug minimally. I have never used JSFiddle before but it seems to work: https://jsfiddle.net/dumb_lowtax/4pfn6e6L/ That short snippet tries to multiply a vector of floats by a scalar. It outputs a different result on iPhones and iPads than everywhere else. It helpfully logs "v instanceof Vec" where Vec extends a typed array and v was created with .of(). That too shows different results only on those devices, exposing the root problem. Is this a good bug report? Also where should I report it, since it affects not just Safari but also Chrome on those devices?
|
# ? Dec 19, 2017 21:54 |
|
Dumb Lowtax posted:OK, I think demonstrated the bug minimally. I have never used JSFiddle before but it seems to work: Wherever Safari bug reports go. IIRC, Chrome just uses Safari under the hood on iOS devices.
|
# ? Dec 19, 2017 21:56 |
|
Yeah iOS forces every browser to actually be Safari as the renderer.
|
# ? Dec 19, 2017 22:31 |
|
necrotic posted:Yeah iOS forces every browser to actually be Safari as the renderer. holy poo poo edit: I did it. Is this how one is supposed to write a bug report? https://bugs.webkit.org/show_bug.cgi?id=181011 Hope they fix it soon so my library can work on phones Happy Thread fucked around with this message at 01:47 on Dec 20, 2017 |
# ? Dec 19, 2017 23:00 |
|
How can I pass additional variables into an SDK function callback (e.g. this AWS SDK call)? I can't seem to just add workspaces.describeTags(params, function(err, data, anotherVariable) {...}); I'm guessing this is a pretty simple question but I can't seem to put together the right wording into Google for it to interpret what I'm trying to do.
|
# ? Dec 20, 2017 03:31 |
|
three posted:How can I pass additional variables into an SDK function callback (e.g. this AWS SDK call)? I can't seem to just add workspaces.describeTags(params, function(err, data, anotherVariable) {...}); You can’t because the SDK code would have to call the callback function with that extra variable which it doesn’t have and doesn’t know about. You can just create a closure that contains the variable you need outside the callback definition and SDK call and use it inside the callback: JavaScript code:
|
# ? Dec 20, 2017 05:43 |
|
I want to write an app in Electron, but I'm having a hard time choosing libraries etc to work with to get started. The overall idea is to make a sort of visual scripting environment, where everything is shown as these blocks or nodes that have inputs and outputs that can be wired up in different ways, basically like this UE4 screenshot for example (caveat: i have no experience with UE4) First of all I'm not really sure if there's any specific term for this sort of interface, besides flowchart? Is there any library you would recommend for these kind of features: draggable "nodes" with connection points, connected by curvy autorouting arrows, on a pannable, zoomable "workspace" Can D3 do something like this? Also it seems like React would work well with this sort of thing, but I don't know React beyond watching a couple bad youtube tutorials. Many years ago I worked in web development doing a lot of JS work, so I feel like I have a firm grasp on old school vanilla js, the DOM, jQuery, HTML/CSS,etc. But haven't kept up with the latest es6 or es2015 whatever is going on with that, and haven't touched any kinda of framework outside of jQuery. I get kinda paralyzed by choice of all the libraries and frameworks when I want to start a new project now. Please help unfrozen caveman web dev from 2010.
|
# ? Dec 21, 2017 20:26 |
|
http://twinery.org/ has a UI like that but AFAIK you'd have to pull it out of their code, it's not a library you could just use
|
# ? Dec 21, 2017 20:35 |
|
If I have an ES6 class, is there any difference between: method(param) { } And method = (param) => { }
|
# ? Dec 22, 2017 00:08 |
|
|
# ? Jun 5, 2024 07:46 |
|
Yes, the latter binds this differently (and forcefully). https://javascriptweblog.wordpress.com/2015/11/02/of-classes-and-arrow-functions-a-cautionary-tale/
|
# ? Dec 22, 2017 00:16 |