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
Hard to say just by looking at it... probably not your random number generation, but could be your clockwise thing. Easy to test though, try iterating through your surroundingPixels from length-1 => 0 and see if it significantly changes things.

Adbot
ADBOT LOVES YOU

kedo
Nov 27, 2007

Skandranon posted:

Hard to say just by looking at it... probably not your random number generation, but could be your clockwise thing. Easy to test though, try iterating through your surroundingPixels from length-1 => 0 and see if it significantly changes things.

Good call... it definitely does. When I reverse the for loop the trend is down to the left instead of up to the right. Well what the heck. Guess I'll try shuffling the array...?

e: Shuffling the array worked. However this is still weird to me and I wonder if anyone can shed some light on why this would happen?

kedo fucked around with this message at 23:00 on Sep 30, 2015

Munkeymon
Aug 14, 2003

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



What happens if you check for the animating class on pixel at the top of trigger and return if it's there instead of animating it again?

kedo
Nov 27, 2007

Munkeymon posted:

What happens if you check for the animating class on pixel at the top of trigger and return if it's there instead of animating it again?

I tried that as well but it wasn't the problem. For some reason the for loop was hitting all of the items in the surroundingPixels array, but only one to two of the first four (top, top right, right, bottom right) ever seemed to meet the requirements to actually animate. Very rarely one of the last four (bottom, bottom left, left, top left) would animate. They all ran through the same function, so they all theoretically had the same chance of animating (ie. a random number up to 100, if less than 30 - animate).

Shuffling the array is a fine workaround, but it still seems weird to me. Why are items at the beginning of the array more likely to animate than others? I have zero clue.

Here's a jsfiddle with array shuffling disabled (commented out on line 88) if anyone wants to muck around with it. If you mouse over enough pixels you'll see that some pixels on the left do animate, they're just very, very rare.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
The problem is you've written for(i = 0... rather than for(var i = 0...

Every invocation of your trigger function is referencing a single (global) instance of i, which in effect means that each cell can only trigger one other cell - once a neighbour cell triggers, that messes up the loop index and prevents it from triggering any other cells.

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

Jabor posted:

The problem is you've written for(i = 0... rather than for(var i = 0...

Every invocation of your trigger function is referencing a single (global) instance of i, which in effect means that each cell can only trigger one other cell - once a neighbour cell triggers, that messes up the loop index and prevents it from triggering any other cells.

JAVASCRIPT :arghfist:

A good reason to use "use strict"; in your files.

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



use strict and JSHint are so useful that they really should just be counted as essential.

Munkeymon
Aug 14, 2003

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



kedo posted:

Here's a jsfiddle with array shuffling disabled (commented out on line 88) if anyone wants to muck around with it. If you mouse over enough pixels you'll see that some pixels on the left do animate, they're just very, very rare.

That absolutely murders Chrome on this machine. The browser freezes and by the time it's done 'animating' everything the timeouts have expired, everything is back to default and I'm lucky to see anything.

Now I'm going to spend all day wanting to performance tweak it until it runs well.

kedo
Nov 27, 2007

Jabor posted:

The problem is you've written for(i = 0... rather than for(var i = 0...

Every invocation of your trigger function is referencing a single (global) instance of i, which in effect means that each cell can only trigger one other cell - once a neighbour cell triggers, that messes up the loop index and prevents it from triggering any other cells.

Well poo poo. That seems to be the case because when I swap it to for(var i I'm getting stack overflows like a mofo. Guess I need to work on this a bit so I don't endlessly trigger pixels forever.

Skandranon posted:

A good reason to use "use strict"; in your files.


piratepilates posted:

use strict and JSHint are so useful that they really should just be counted as essential.

Also good points. :\

Munkeymon posted:

That absolutely murders Chrome on this machine. The browser freezes and by the time it's done 'animating' everything the timeouts have expired, everything is back to default and I'm lucky to see anything.

Now I'm going to spend all day wanting to performance tweak it until it runs well.

Yeah, it's just a proof of concept at this point. It works okay for me on my newish macbook but it chugs on the girlfriend's old PC. I need to do a ton of testing on it still. I'm wondering if generating a static array of random numbers and using that instead of generating one on every single trigger would help at all...

kedo fucked around with this message at 16:32 on Oct 1, 2015

Munkeymon
Aug 14, 2003

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



Not calling parseInt on the same numbers 18 times would probably help, for one :) Also, IDs would be faster for lookups than data attributes.

Checking for the animating class at the top of trigger prevents stack overflows, as would keeping a map of row/col values that have been visited and simply not visiting them, which would be much faster than checking for a class.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

kedo posted:

Well poo poo. That seems to be the case because when I swap it to for(var i I'm getting stack overflows like a mofo. Guess I need to work on this a bit so I don't endlessly trigger pixels forever.

All you should really need to do is decrease the trigger chance. Before your bug fix, each triggered pixel would be expected to trigger 0.96 other ones - since that's <1, we would expect it to terminate at some point.

After the fix, each pixel would be expected to trigger 2.4 other ones, meaning it probably won't ever stop. You want to get that expected value somewhere slightly below 1 if you want it to eventually terminate.

kedo
Nov 27, 2007

Jabor posted:

All you should really need to do is decrease the trigger chance. Before your bug fix, each triggered pixel would be expected to trigger 0.96 other ones - since that's <1, we would expect it to terminate at some point.

After the fix, each pixel would be expected to trigger 2.4 other ones, meaning it probably won't ever stop. You want to get that expected value somewhere slightly below 1 if you want it to eventually terminate.

Very good point. I reduced the spread chance to 10% and it doesn't cause stack overflows. However this has me thinking that I need to change how spread chances are calculated. My goal is to have the at least half of the pixels close to the origin animate, and then maybe a quarter of their child pixels animate, and then less for the following generations. Sort of like a spray paint brush in paint. So I think I need to track what generation a pixel is from the origin and adjust its spread chance accordingly.


Munkeymon posted:

Not calling parseInt on the same numbers 18 times would probably help, for one :)

:downs: Yeah this had a huge impact. I'm going to look into creating a map as well... that's not something I've played with much before.

my effigy burns
Aug 23, 2015

IF I'M NOT SHITPOSTING ABOUT HOW I, A JUNIOR DEVELOPER IN JAVASCRIPT KNOW EVERYTHING THERE IS TO KNOW, PLEASE CHECK TO BE SURE MY ACCOUNT WAS NOT COMPROMISED BY A CLIENT-SIDE BOTNET, TIA
So for the whole MEAN stack there's a rarely-updated node thread that seems to mostly involve people who don't know much about node (or had bad experiences with earlier versions) making GBS threads on it, and then there's no thread for MongoDB, Express, or Angular. Coincidence... or conspiracy? Or possibly people not liking javascript on the backend still, in 2015.

Asking because I'd like to get a MEAN stack thread going, but if those questions are already getting answered well here, there's not much reason for it.

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

my effigy burns posted:

So for the whole MEAN stack there's a rarely-updated node thread that seems to mostly involve people who don't know much about node (or had bad experiences with earlier versions) making GBS threads on it, and then there's no thread for MongoDB, Express, or Angular. Coincidence... or conspiracy? Or possibly people not liking javascript on the backend still, in 2015.

Asking because I'd like to get a MEAN stack thread going, but if those questions are already getting answered well here, there's not much reason for it.

I'd be interested in that (but not enough to get off my rear end and actually make an OP).

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.
There was a MongoDB thread but it corrupted itself during a network partition

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.
There was an Angular thread but it got to be too slow with more than a few posts so now it's a thread about React

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
There was a node thread, but the title was too long for the forums to handle it.

three
Aug 9, 2007

i fantasize about ndamukong suh licking my doodoo hole
So wasn't sure whether to put this in this thread or the Web Dev thread (which seems to be mostly JS), but... I've been trying to learn JavaScript, and I have a few thoughts. Was hoping to bounce them off you JS Gurus.

  • Are Frameworks like Angular/React/Ember/Backbone competitors to jQuery?
  • React's style of putting so much code together and using JSX seems really ugly to me. Seems like the lack of separation is bad. Angular seems much more visually appealing, but I've read on the forums some folks aren't a fan of it.
  • Why so much love for MongoDB in the JS community?
  • All the tutorials I've seen for Express involve using it to create an API (which is awesome), but are there any other reasons for it?
  • I've been using Atom and I like it (but I'm ignorant of anything better), but I rarely see it used in videos. Should I be using Sublime or something else?

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

three posted:

So wasn't sure whether to put this in this thread or the Web Dev thread (which seems to be mostly JS), but... I've been trying to learn JavaScript, and I have a few thoughts. Was hoping to bounce them off you JS Gurus.

  • Are Frameworks like Angular/React/Ember/Backbone competitors to jQuery?
  • React's style of putting so much code together and using JSX seems really ugly to me. Seems like the lack of separation is bad. Angular seems much more visually appealing, but I've read on the forums some folks aren't a fan of it.
  • Why so much love for MongoDB in the JS community?
  • All the tutorials I've seen for Express involve using it to create an API (which is awesome), but are there any other reasons for it?
  • I've been using Atom and I like it (but I'm ignorant of anything better), but I rarely see it used in videos. Should I be using Sublime or something else?

They aren't exactly competitors, but they provide a better way of writing front end JavaScript applications that doesn't end up in a mess of JQuery.

I like Angular, but it has a lot of baggage from it's early versions. If you use TypeScript and focus on using classes similar to how is described in Angular 2.0, a lot of that can be avoided. Angular has a specific way it wants you to do things, and if it clicks with you, you'll like it. If it doesn't, and you try to use it another way, it'll just make your life hard and you'll hate it.

Because JS developers don't want to learn about relational databases.

Don't have anything to say about Express.

Take a look at VSCode, it is based on Electron and has a lot of added features (Intellisense for TypeScript & JavaScript). Unless you are already attached to Sublime and 100 addons for it, no, you don't need to use it.

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



three posted:

So wasn't sure whether to put this in this thread or the Web Dev thread (which seems to be mostly JS), but... I've been trying to learn JavaScript, and I have a few thoughts. Was hoping to bounce them off you JS Gurus.

  • Are Frameworks like Angular/React/Ember/Backbone competitors to jQuery?
  • React's style of putting so much code together and using JSX seems really ugly to me. Seems like the lack of separation is bad. Angular seems much more visually appealing, but I've read on the forums some folks aren't a fan of it.
  • Why so much love for MongoDB in the JS community?
  • All the tutorials I've seen for Express involve using it to create an API (which is awesome), but are there any other reasons for it?
  • I've been using Atom and I like it (but I'm ignorant of anything better), but I rarely see it used in videos. Should I be using Sublime or something else?

quote:

Are Frameworks like Angular/React/Ember/Backbone competitors to jQuery?

Yes and No, mostly no. jQuery is more of a wrapper around the DOM that made things less painful. Then people started adding a whole bunch of weird poo poo and plugins and started doing jQuery conferences and it's all bizarre.

Ember actually still uses jQuery for manipulating DOM stuff and you'll end up using parts of jQuery if you use Ember.

Angular 1.x has a dependency on a small subset of jQuery that they provide, and you can peacefully use the full jQuery too.

The frameworks are more about structuring front end code, while jQuery is providing a different interface to the DOM of the webpage.

quote:

React's style of putting so much code together and using JSX seems really ugly to me. Seems like the lack of separation is bad. Angular seems much more visually appealing, but I've read on the forums some folks aren't a fan of it.

gently caress separation, Ember separates code and templates and all you end up doing is introducing ugly template helpers to do the things you want to do in code anyway, then you need to have the helpers have their own documentation and tests and asserts and everything and it's just a pain in the rear end.

Not everyone likes JSX (those fools) but it's not a bad way of doing things to have your code go right there with your template. If you really want to separate the two just think of every piece of JSX that's straight up HTML as being in a variable, and the code just using the variable instead of having the template inside the code.

quote:

Why so much love for MongoDB in the JS community?

That sounds like a question from 2009 when everyone still loved MongoDB, the tides have turned and now everyone hates it.

The only real benefit is that it stores data in a way very very similar to JSON and a bunch of early evangelists (why is this a term people like to be associated with?) promoted the MEAN stack of a bunch of JS stuff that made sense, and also MongoDB because why not.

quote:

All the tutorials I've seen for Express involve using it to create an API (which is awesome), but are there any other reasons for it?

It's the style now that everyone is moving towards having the back-end just be a REST API and having the front-end be entirely static HTML along with a javascript front-end that just sends AJAX requests to the REST API.

You can still do the traditional style server side rendering, I've definitely done it with Jade and Express out of the box but I'm not sure where the docs were and this was a major version back so you may have to look at the older docs.

quote:

I've been using Atom and I like it (but I'm ignorant of anything better), but I rarely see it used in videos. Should I be using Sublime or something else?
Try Atom, Sublime Text, Webstorm, and choose whichever one you like best. They all have pros and cons (for Atom that's probably mostly cons still but people like to use it) and it doesn't really matter in the long-run, you'll be dead in a few decades anyway.

Thermopyle
Jul 1, 2003

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

three posted:

So wasn't sure whether to put this in this thread or the Web Dev thread (which seems to be mostly JS), but... I've been trying to learn JavaScript, and I have a few thoughts. Was hoping to bounce them off you JS Gurus.

  • Are Frameworks like Angular/React/Ember/Backbone competitors to jQuery?
  • React's style of putting so much code together and using JSX seems really ugly to me. Seems like the lack of separation is bad. Angular seems much more visually appealing, but I've read on the forums some folks aren't a fan of it.
  • Why so much love for MongoDB in the JS community?
  • All the tutorials I've seen for Express involve using it to create an API (which is awesome), but are there any other reasons for it?
  • I've been using Atom and I like it (but I'm ignorant of anything better), but I rarely see it used in videos. Should I be using Sublime or something else?

  • Maybe. Some developers have smashed jQuery into doing some of the things these frameworks do, but it's not...good. You can use jQuery along with the those frameworks to ease some parts of JS without any problems.
  • You don't have to use JSX, you can also use React.createElement. I prefer JSX because, I personally get some benefit out of the close correspondence between JSX and HTML. However, I do know there's a not-insignifcant number of people using React.createElement.
  • Relational databases are hard! (no they aren't)
  • Like Mongo, I think a lot of this stuff is driven by people who have this real aversion to using more than one programming language. I don't get that at all, but whatever...I don't have any experience with Express other than using it to serve stuff locally while developing.
  • Text editors and IDEs are a contentious issue. I like Jetbrains stuff...look into Webstorm.

three
Aug 9, 2007

i fantasize about ndamukong suh licking my doodoo hole
Thanks dudes. I really love JavaScript so far. :)

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

three posted:

Thanks dudes. I really love JavaScript so far. :)

Try not to go too far off the deep end. It's an extremely poorly planned out language that has succeeded largely due to the friction between web browsers. But, if you want to do stuff in browsers, there isn't really another option.

"If you can't be with the one you love, love the one you're with".

fantastic in plastic
Jun 15, 2007

The Socialist Workers Party's newspaper proved to be a tough sell to downtown businessmen.

three posted:

Thanks dudes. I really love JavaScript so far. :)

wat

my effigy burns
Aug 23, 2015

IF I'M NOT SHITPOSTING ABOUT HOW I, A JUNIOR DEVELOPER IN JAVASCRIPT KNOW EVERYTHING THERE IS TO KNOW, PLEASE CHECK TO BE SURE MY ACCOUNT WAS NOT COMPROMISED BY A CLIENT-SIDE BOTNET, TIA

That was legitimately hilarious because of his delivery, but none of that's particularly magical if you understand how the + operator works in Javascript. Still, is it stupid that the + operator has special properties the others don't? Yes, yes it is.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.
One reason that people like MongoDB is that in most relational databases, schema updates in large-scale production applications are really, really expensive to do. In MySQL doing something as simple as deleting a column can take your application down for hours or days, and while Postgres handles this much better because of MVCC, you basically never see it run at large scale because of a historical attachment to really janky, bad clustering mechanisms prior to the 9.0 release. In Mongo, gently caress it, there's no schema, so there's no downtime for schema updates.

Your downtime comes when, without warning, important records randomly go missing from your database instead.

Odette
Mar 19, 2011

Vulture Culture posted:

Your downtime comes when, without warning, important records randomly go missing from your database instead.

I had this happen when I was learning how to use Mongo. Was updating password/salt and a whole bunch of fields just went missing. I don't even know how it happened, but I'm very wary of using Mongo now.

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



Vulture Culture posted:

In Mongo, gently caress it, there's no schema, so there's no downtime for schema updates.


I know it's not what you meant but for anyone reading who wants to use MongoDB: there's still a schema, it's just hidden from your view and derived from your application at different stages of time.

qntm
Jun 17, 2009
"Doctor, doctor, it hurts when I add things together that aren't numbers or strings."

"Then don't do that."

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Or compare, while you're at it.

Impotence
Nov 8, 2010
Lipstick Apathy

Vulture Culture posted:

One reason that people like MongoDB is that in most relational databases, schema updates in large-scale production applications are really, really expensive to do. In MySQL doing something as simple as deleting a column can take your application down for hours or days, and while Postgres handles this much better because of MVCC, you basically never see it run at large scale because of a historical attachment to really janky, bad clustering mechanisms prior to the 9.0 release. In Mongo, gently caress it, there's no schema, so there's no downtime for schema updates.

Your downtime comes when, without warning, important records randomly go missing from your database instead.

just use postgresql with a single primary key column and a json column

:v:

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Biowarfare posted:

just use postgresql with a single primary key column and a json column

:v:
With the JSONB support in 9.4 and corresponding perf improvements to Generalized Inverted Indexes, this is not an altogether awful idea anymore

Impotence
Nov 8, 2010
Lipstick Apathy

Vulture Culture posted:

With the JSONB support in 9.4 and corresponding perf improvements to Generalized Inverted Indexes, this is not an altogether awful idea anymore

i am doing this in production with 9.4 and jsonb
like right now
for a new project started a week ago

fantastic in plastic
Jun 15, 2007

The Socialist Workers Party's newspaper proved to be a tough sell to downtown businessmen.
Angular question:

My app has a collection, foo, which generates a variety of pages (/foo/1, /foo/2, /foo/3, etc). Foo has a "type" property that can be bar, baz, whatever.

If a user is on a foo page and then navigates to a qaz page, I want qaz to know what "type" the user was looking at before they navigated. But if the user goes from foo to some non-qaz page and then on to qaz, I don't want qaz to know.

My naive idea is to make some kind of fooSharedDataService with a lastFooSeen variable, have fooController set lastFooSeen when it activates, have qazController check the lastFooSeen, and have the other controllers set lastFooSeen to null. But what I really want (because mandating that every controller ever must interact with fooSharedDataService seems dumb) is some kind of global state thing which I don't know if Angular provides.

Is there an Angular tool that can handle a global state thing like this, or alternately is there a better way to solve the problem?

geeves
Sep 16, 2004

Tao Jones posted:

Angular question:

My app has a collection, foo, which generates a variety of pages (/foo/1, /foo/2, /foo/3, etc). Foo has a "type" property that can be bar, baz, whatever.

If a user is on a foo page and then navigates to a qaz page, I want qaz to know what "type" the user was looking at before they navigated. But if the user goes from foo to some non-qaz page and then on to qaz, I don't want qaz to know.

My naive idea is to make some kind of fooSharedDataService with a lastFooSeen variable, have fooController set lastFooSeen when it activates, have qazController check the lastFooSeen, and have the other controllers set lastFooSeen to null. But what I really want (because mandating that every controller ever must interact with fooSharedDataService seems dumb) is some kind of global state thing which I don't know if Angular provides.

Is there an Angular tool that can handle a global state thing like this, or alternately is there a better way to solve the problem?

Is it something you can track in $rootScope? It may or may not be the perfect place for it, but it's a start. In the old days of JS i would track this via cookies or browser cookies/session depending on the need. It might not be pretty but it worked.

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

geeves posted:

Is it something you can track in $rootScope? It may or may not be the perfect place for it, but it's a start. In the old days of JS i would track this via cookies or browser cookies/session depending on the need. It might not be pretty but it worked.

Using $rootScope is almost always a bad idea.

You have the right idea, create a breadCrumbsService to track this. A service is a singleton, so in effect, it IS a single, globally accessible variable. Anyone that is concerned with knowing about where a user has last been, can inject the service.

To elaborate, it's not silly, and not ALL controllers. You may have components in your app which don't care, and thus, don't need it. There is no reason you can't just create var x on the global scope, but it's not the Angular way of doing it.

Also, by creating a service, you can put methods in the service which will manage the logic on how the variables get changed, so every controller just needs to call Service.SetActivePage when they get switched to, and the Service can manage the backlog.

Where do you store the collection of pages? That should probably be in a Service too, and you can probably merge these things into the same service, since you are tracking the page history.

Skandranon fucked around with this message at 02:15 on Oct 7, 2015

geeves
Sep 16, 2004

Skandranon posted:

Using $rootScope is almost always a bad idea.

You have the right idea, create a breadCrumbsService to track this. A service is a singleton, so in effect, it IS a single, globally accessible variable. Anyone that is concerned with knowing about where a user has last been, can inject the service.

To elaborate, it's not silly, and not ALL controllers. You may have components in your app which don't care, and thus, don't need it. There is no reason you can't just create var x on the global scope, but it's not the Angular way of doing it.

Also, by creating a service, you can put methods in the service which will manage the logic on how the variables get changed, so every controller just needs to call Service.SetActivePage when they get switched to, and the Service can manage the backlog.

Where do you store the collection of pages? That should probably be in a Service too, and you can probably merge these things into the same service, since you are tracking the page history.

I hate the idea of rootScope, like I said, it's not pretty. But it can be useful in the worst situations. It's the first thing that came to mind, but I should have suggested a factory. It's more natural to Java devs like me. If you're goal is you still have to track state somehow, root or or a factory object would be a good choice.

I'm letting the fact that I hate the implementation of angular that a couple of devs did for my company's app. I wasn't involved in the decision (or dev) and I really wish I was. Because I would have veto'd it (or at least the way that they did it).

I'm not against angular at all. I like it actually. But the web devs that we had wrapped our entire app AND javascript within controllers causing major pain and conflicts with new controllers, etc. that we've had to write. That and we still have a heavy reliance on jQuery which just adds to the mess.

Those two devs are gone now (they were good, just not wise in the way they implemented angular) and I've moved all the rootscope methods to a factory where they should have been. But we have 1 module they defined and everything conficts if I want to use more than one controller on a page. :argh: I want to hire them back so I can fire them because gently caress they put us in a bad position that I can't easily fix / refactor.

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

geeves posted:

I hate the idea of rootScope, like I said, it's not pretty. But it can be useful in the worst situations. It's the first thing that came to mind, but I should have suggested a factory. It's more natural to Java devs like me. If you're goal is you still have to track state somehow, root or or a factory object would be a good choice.

I'm letting the fact that I hate the implementation of angular that a couple of devs did for my company's app. I wasn't involved in the decision (or dev) and I really wish I was. Because I would have veto'd it (or at least the way that they did it).

I'm not against angular at all. I like it actually. But the web devs that we had wrapped our entire app AND javascript within controllers causing major pain and conflicts with new controllers, etc. that we've had to write. That and we still have a heavy reliance on jQuery which just adds to the mess.

Those two devs are gone now (they were good, just not wise in the way they implemented angular) and I've moved all the rootscope methods to a factory where they should have been. But we have 1 module they defined and everything conficts if I want to use more than one controller on a page. :argh: I want to hire them back so I can fire them because gently caress they put us in a bad position that I can't easily fix / refactor.

For the last month I've been working on refactoring a similarly poorly implemented Angular app. They used controllers like services, spawning up 10 of the same controller when they thought they were accessing the same one. However, it all magically worked because they ALSO created a hast table based global variable service that everything got put in, so the controllers ended up accessing the same variables from there, though I suspect this was more a coincidence.

How can you not use more than 1 controller per page? Do you mean you can't nest any other controllers in it?

geeves
Sep 16, 2004

Skandranon posted:

For the last month I've been working on refactoring a similarly poorly implemented Angular app. They used controllers like services, spawning up 10 of the same controller when they thought they were accessing the same one. However, it all magically worked because they ALSO created a hast table based global variable service that everything got put in, so the controllers ended up accessing the same variables from there, though I suspect this was more a coincidence.

How can you not use more than 1 controller per page? Do you mean you can't nest any other controllers in it?

I don't understand it yet because I'm still figuring things out.... but they made every page its own controller.

so:

<body data-ng-controller="${actionName}"> (we're based in struts) wraps everything else. The controllers interfere with each other causing a major JS error (what I don't have a complete understanding of), yet. The embedded controller doesn't "fire" or "init" at all and I have no idea why. If I use directives,it works,, but it doesn't answer why the controllers don't. And perhaps that's one of the shortcomings of the 1.x branch that may be better addressed in 2.x

Adbot
ADBOT LOVES YOU

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

geeves posted:

I don't understand it yet because I'm still figuring things out.... but they made every page its own controller.

so:

<body data-ng-controller="${actionName}"> (we're based in struts) wraps everything else. The controllers interfere with each other causing a major JS error (what I don't have a complete understanding of), yet. The embedded controller doesn't "fire" or "init" at all and I have no idea why. If I use directives,it works,, but it doesn't answer why the controllers don't. And perhaps that's one of the shortcomings of the 1.x branch that may be better addressed in 2.x

Might be because the controller is attached to the <body> element and you can't have more than 1 of those at a time. I'd just move everything to use directives, it's a much better way to break your app down into components than using ng-controller, and it's much closer to how Angular 2 does things.

There should be nothing wrong with having other directives nested within those 'super controllers', and if I was trying to refactor it away, I'd break everything down into smaller parts until the 'super controller' had no actual code left in it.

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