-
Notifications
You must be signed in to change notification settings - Fork 3k
Allow is, includes and get to work on relative stateOrName #636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Looks good. I'll merge this as soon as I have a chance to write some tests for it. |
I could see this one being a little tricky like sref was at first, where if you use it in ng-class for example the dev will have to know its based off the state that loaded the template containing the element with the ng-class. Does this complicate things? |
@timkindberg This is for the service, so it doesn't directly affect anything that happens in a template. That said, developers still have to know what they're doing if they're gonna use it in a template with relative state references. |
Ah yes, seeing as people use these services directly in templates quite often, I'll wager that we'll see this problem crop up eventually... I guess I'll just add a blurb in the docs... |
Conflicts: src/state.js
Is this going in? I was just about to write the docs for it... but realized its not merged. |
Not until someone writes tests for it, which is a pretty low priority for me right now. |
I can write some tests for this. How is it meant to be used? Like so? // state is 'about.person'
var about = $state.get('about'); // could keep state object from declaration?
$state.is('.person', undefined, { relative: about }); // true Although I believe the above approach would fail in findState() if I was searching a parent using '^', because as I understand it there won't be a 'parent' property on the state config, which would lead to an error thrown at https://github.com/angular-ui/ui-router/blob/master/src/state.js#L151. E.g. // state is 'about'
var person = $state.get('about.person');
$state.is('^', undefined, { relative: person }); // Path '^' not valid... Or perhaps would it be stored from a previous $stateChangeSuccess event? This should work with the case above. |
@dlukez Your usage is correct, but I think we should also allow something like: $state.is('.person', undefined, { relative: "about" }); ...to be equivalent. This should just be a matter of calling Regarding the |
I created a PR with the tests against pdanpdan's fork. Let me know if I should PR them against this repo instead. |
test($state): test relative states for is, includes and get
Can we squash all those commits? |
I rebased this and merged it into https://github.com/christopherthielen/ui-router/commit/693ba51b66b4db1057ded3921db26a0f73395c8c However, I think there may be a breaking change here. @nateabele please have a look at https://github.com/christopherthielen/ui-router/commit/693ba51b66b4db1057ded3921db26a0f73395c8c#diff-230fff7c0b3ed8f0d4f2443a246fc76aR1146 and let me know before I move further on this PR. |
Also, before we merge anything, the docs will need updating. |
@christopherthielen Made one comment with an alternate implementation that shouldn't break BC. |
No description provided.