Skip to content
This repository has been archived by the owner on Sep 20, 2020. It is now read-only.

Move all module-level variables to the core provider. #222

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lambdafu
Copy link

Hi Chris,
this should be a fun one for you :) I am developing a state-heavy app in angular, and of course I make heavy use of ui-router and ui-router-extras (thanks a lot for this!). However, I was missing a "view stack" (like a deck of cards) similar to the Onsen UI navigator. I hacked up my own version by bootstrapping one angular app for each "card" in the "deck" and only making the top app visible. This must happen outside angular, because angular apps can't be nested in the DOM tree, but apart from that cosmetic wart things fell into place nicely. Of course, I have to carefully manage the location to match the active app, but ui-router has all the necessary plunging for that.
What didn't work was ui-router-extra's sticky flag. The errors are difficult to describe: After pushing and popping a "card", the remaining cards got "out of sync" so to speak and lost their stickiness. After banging my head against my code for a while, I found out that ui-router-extra uses module-level state variables a lot. Ouch! This prevents multiple angular apps using ui-router-extra from running in parallel on a single website.
That's a real shame, because angular is so well modularized. So I moved the module-level variables to the core provider, and things work out fine for me now. However, I am ready to admit that I don't get all nuances of the provider initialization, and the way you access the run time instance of a provider in the functions defined in config() (which usually only has access to the provider factory!). However, a couple of $get invocations seemed to do the trick. Maybe that's a bit dirty, but not worse than before.
The other problem is that a test fails now:

  PhantomJS 1.9.8 (Linux 0.0.0) futureState futureState should lazy load futurestates that have parent futurestates2 FAILED
    Expected '' to be 'hwat'.
        at /home/marcus/semantics/projects/tablet/angular/ui-router-extras/test/futureSpec.js:141
LOG: 'failed to lazy load state ', 'doesntwork'
LOG: 'failed to lazy load state ', 'doesntwork'

I wish I could help you out with that, but frankly, there is an app to write and I don't need the future state feature. Maybe someone else wants to help clean this up, or maybe it's something easy for you to look at? Otherwise I might look at it later, but it would be weeks rather than days, so I wanted to get the patch out there right now. Happy hacking!
BTW, here is a test: Working Broken

@tilwinjoy
Copy link

I hacked up my own version by bootstrapping one angular app for each "card" in the "deck"

Sounds heavy. Why not just a directive per card?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants