Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

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.

Adbot
ADBOT LOVES YOU

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



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.

Capri Sun Tzu
Oct 24, 2017

by Reene

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?
Assuming as it's a function declaration e.g.
code:
function foo(){
    function bar(){
        //do something
    }
}
then you should be fine as long as you aren't doing a huge amount of things inside the function. A lot of modern engines like V8 will compile it once and invoke it with a different context for each invocation of foo. A use case for this is when you have a lot of locally scoped variables in foo() you want to work with in bar().

Capri Sun Tzu fucked around with this message at 19:14 on Dec 13, 2017

Knifegrab
Jul 30, 2014

Gadzooks! I'm terrified of this little child who is going to stab me with a knife. I must wrest the knife away from his control and therefore gain the upperhand.
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:
       if (this._form.validate()) {
                $.ajax({
                    url: '/createThing',
                    method: 'POST',
                    contentType: 'application/json',
                    data: JSON.stringify(this._form.data)
                })
      }
I quite think the solution is elegant, and flexible and half my coworkers agree but the other half are screeching.

Thoughts?

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

Knifegrab posted:

I quite think the solution is elegant, and flexible and half my coworkers agree but the other half are screeching.

Thoughts?

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.

Knifegrab
Jul 30, 2014

Gadzooks! I'm terrified of this little child who is going to stab me with a knife. I must wrest the knife away from his control and therefore gain the upperhand.

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.

With your solution that is a big pain, because you have re-written HTML.

Just omit that field from the form component and add it at the parent level?

code:

onSubmit() {
      if (this._form.validate() && this.state.myExtraForm !== '') { //or whatever validation you want for your extra piece here
                $.ajax({
                    url: '/createThing',
                    method: 'POST',
                    contentType: 'application/json',
                    data: JSON.stringify(Object.assign({}, this._form.data, this.state.myExtraForm))
                })
      }
}

render() {

   return (
       ....
       <FormGenerator />
       <MyExtraForm value={this.state.myExtraForm} onChange={(e) => this.updateExtraForm(e)} />
       ....
   );
}
I'm not really sure why that would be so terrible?

Also I am not super sure how elevating state out of the form component would alleviate that issue? Can you elaborate?

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
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?

Knifegrab
Jul 30, 2014

Gadzooks! I'm terrified of this little child who is going to stab me with a knife. I must wrest the knife away from his control and therefore gain the upperhand.

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.

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?

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.

geeves
Sep 16, 2004

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.

necrotic
Aug 2, 2005
I owe my brother big time for this!
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.

teen phone cutie
Jun 18, 2012

last year i rewrote something awful from scratch because i hate myself
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:
	function runPDF() {
		$(document).on('submit', '#productDetailsAddToCartForm', function (e) { //on the add to cart submit
			e.preventDefault();
			$('#AjaxLoading').show();
			$.ajax({
				url: '/cart.php',
				type: 'POST',
				data: new FormData(this),
				processData: false,
				contentType: false,
				success: function () {
					console.log('success!');
				}
			}).done(function () {
				location.reload(); //reload the page, which in this case is the checkout page.
			});
		});
	}
It should be requesting https://domain.com/productname.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

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:

Here's what my call looks like

JavaScript code:
	function runPDF() {
		$(document).on('submit', '#productDetailsAddToCartForm', function (e) { //on the add to cart submit
			e.preventDefault();
			$('#AjaxLoading').show();
			$.ajax({
				url: '/cart.php',
				type: 'POST',
				data: new FormData(this),
				processData: false,
				contentType: false,
				success: function () {
					console.log('success!');
				}
			}).done(function () {
				location.reload(); //reload the page, which in this case is the checkout page.
			});
		});
	}
It should be requesting https://domain.com/productname.

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?

Kobayashi
Aug 13, 2004

by Nyc_Tattoo
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.

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop

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.

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

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.

Kobayashi
Aug 13, 2004

by Nyc_Tattoo

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.

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.

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.

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop
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

Dogcow
Jun 21, 2005

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:

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 )".

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.

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop

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?

Dogcow
Jun 21, 2005

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?

Cirofren
Jun 13, 2005


Pillbug

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)

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop

Dogcow posted:

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?

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.

Dogcow
Jun 21, 2005

Dumb Lowtax posted:

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.

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?

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop

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

You don't get any errors using the inspector/debugger on a remote debugging session?

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

geeves
Sep 16, 2004

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

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop
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?

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

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.

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?

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!

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Thermopyle posted:

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!

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.

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop

Thermopyle posted:

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!

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!

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Munkeymon posted:

iOS Safari (especially the iPhone version) has more quirks and nonstandard behavior than Android Chrome IME.

Agreed.

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop
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?

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Dumb Lowtax posted:

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?

Wherever Safari bug reports go. IIRC, Chrome just uses Safari under the hood on iOS devices.

necrotic
Aug 2, 2005
I owe my brother big time for this!
Yeah iOS forces every browser to actually be Safari as the renderer.

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop

necrotic posted:

Yeah iOS forces every browser to actually be Safari as the renderer.

holy poo poo :lol:


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 :toot:

Happy Thread fucked around with this message at 01:47 on Dec 20, 2017

three
Aug 9, 2007

i fantasize about ndamukong suh licking my doodoo hole
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.

Dogcow
Jun 21, 2005

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) {...});

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.

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:
const foo = ‘bar’;

workspaces.describeTags(params, function(err, data) {
  console.log(foo);
});

peepsalot
Apr 24, 2007

        PEEP THIS...
           BITCH!

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.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



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

smackfu
Jun 7, 2004

If I have an ES6 class, is there any difference between:

method(param) {
}

And

method = (param) => {
}

Adbot
ADBOT LOVES YOU

necrotic
Aug 2, 2005
I owe my brother big time for this!
Yes, the latter binds this differently (and forcefully).

https://javascriptweblog.wordpress.com/2015/11/02/of-classes-and-arrow-functions-a-cautionary-tale/

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply