-
Notifications
You must be signed in to change notification settings - Fork 3k
Add optional parameter matching to $state.is and $state.includes #446
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
Can you just add your tests, rather than removing existing tests? Also, please squash your commits when done. Thanks. |
I had to change two existing tests because of the method contract change from |
I feel like there was a reason for returning |
@roryf Since we're talking about adding an extra method parameter, it should be easy to implement without a contract change. If you don't pass any parameters, the results should be identical to the preexisting behavior. @timkindberg Yes, the return values do indeed have different semantic meanings: |
@nateabele I agree it shouldn't break existing behaviour, so I'll change it back, but this seems like a big code smell to me. |
@roryf How so? |
Perhaps "big" was an exaggeration 😄 A boolean method shouldn't return 3 possible states, by it's very nature of being boolean. The current behaviour muddies the water between two separate use cases: is This could be discussed in a separate issue, it doesn't need to affect the changes here. |
Then maybe the doc comment needs an update? This is JavaScript, not Java. 😉 Both values evaluate falsy, and the previous behavior was to simply throw an error, which everyone decided this was a much better alternative to. |
Add optional parameter matching to $state.is and $state.includes
I may actually agree with @roryf here. The methods are asking of the state "is?" or if it "includes?", these are yes/no questions. I'm not sure returning I'm also fine with the way it was, returning However, I still have this feeling like there is some very specific reason why we need it to return |
Either way, it's merged, so nvm. |
Maybe you're thinking of when I've referenced the Single Responsibility Principle? I don't think I would have said anything that general, because it's not consistent with what I think. Consider
That was the agreed-upon alternative to |
Can someone please add support for the $ne operator for the JSON in Angular 1.x please?
I have a situation where it needs to be active when it does not match a particular value. |
Fixes #413.
Allows passing a second parameter to
$state.is
and$state.includes
with parameters for the state.is
will do a strictangular.equals
on the passed parameters with the current$stateParams
, whileincludes
will only attempt to match the parameters given.Examples:
I also changed the method contract so it won't return
undefined
when a state doesn't exist. This didn't make sense to me that a function could return a boolean value, orundefined
, especially when the docs state it will return a boolean.