Skip to content

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

Closed
wants to merge 5 commits into from
Closed

Allow is, includes and get to work on relative stateOrName #636

wants to merge 5 commits into from

Conversation

pdanpdan
Copy link
Contributor

@pdanpdan pdanpdan commented Dec 5, 2013

No description provided.

@nateabele
Copy link
Contributor

Looks good. I'll merge this as soon as I have a chance to write some tests for it.

@timkindberg
Copy link
Contributor

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?

@nateabele
Copy link
Contributor

@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.

@timkindberg
Copy link
Contributor

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

@timkindberg
Copy link
Contributor

Is this going in? I was just about to write the docs for it... but realized its not merged.

@nateabele
Copy link
Contributor

Not until someone writes tests for it, which is a pretty low priority for me right now.

@dlukez
Copy link
Contributor

dlukez commented Dec 16, 2013

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.

@nateabele
Copy link
Contributor

@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 base = findState(base) inside of findState().

Regarding the Path '^' not valid example, I'd double-check that. I think it works correctly, but if not, I wouldn't worry about it for now, since we still need to handle resolving state parents in a consistent way, which is still a big outstanding item on the to-do list before ui.router's API is totally stable.

@dlukez
Copy link
Contributor

dlukez commented Jan 8, 2014

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
@timkindberg
Copy link
Contributor

Can we squash all those commits?

@christopherthielen
Copy link
Contributor

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.

@christopherthielen
Copy link
Contributor

Also, before we merge anything, the docs will need updating.

@nateabele
Copy link
Contributor

@christopherthielen Made one comment with an alternate implementation that shouldn't break BC.

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

Successfully merging this pull request may close these issues.

6 participants