-
Notifications
You must be signed in to change notification settings - Fork 3k
Add children
option to state configs
#953
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
Comments
This is quite a large size item. I'm so not sure how I envision "pluggable modules" to work yet. Maybe this way, maybe some other way. This idea doesn't feel so bad. We'll definitely have to let it stew though, at least I will. |
Actually when I was poking around the code, it appeared that the way states and their relationships are resolves is that child states are pushed into a children array that's a property of the parent state. So theoretically it'd be fairly straight-forwards to add support for a children property. Especially since the newest version (supposedly) resolves routes just-in-time, then I would imagine the logic that resolves the relationships and where the relationships are defined is completely isolated from one another. |
I would definitely like this! One use case is "modal" states, which can be child states of multiple modules. Might want to consider multiple inheritance too. |
Sounds amazing. |
I was thinking about this yesterday and it would actually be awesome. So I think it would need to be a merge of auto added children (states that were added based on the dot-syntax naming scheme) and children pushed into the array manually (regardless of their name). |
@marklagendijk was gonna work on adding this property based on naming schemes (which is related but not exactly what this story is going for). See #903. |
So after reading @marklagendijk I realized that the one flaw with this design is duplicate state names in your tree. I am very reserved about modifying explicitly state names because I use a combination of parent.child and parent:parent to keep state names short and concise. We COULD do what he proposed and convert all names to long form, and even go so far as to allow you to specify the end of a name for conciseness, but this would be unreliable, and easily break. Instead what I have been doing is declaring a state object and reusing the object in multiple state() calls where I still explicitly defined the name myself. Although this works for now, perhaps to better decouple the code we can do state aliasing. Let's say I define an 'edit' edit modal state in my edit module. In my person module I define my 'person' state but I could also define a state like this: $stateProvider.state('person.edit', 'edit') This way I define a new, explicit and unique name and the original state definition for edit is simply looked up and copied over. All states defined in this manner would have to be deferred however until after all normal states are finished being defined. Alternatively the children property could be an object of alias to original names. |
yeah, I like your psuedo code there Either way this is technically a duplicate issue, because we've talked about state "modules" a long time ago. But we can leave this open because if we close it as a dupe, it will surely kill it. |
I don't want to define reusable ones differently. Could do children: {
|
So I realized that my attempts to reuse the same state object were actually causing problems. Doing this: var state = {
templateUrl: 'modules/projects/project/dataset/history/history.html',
controller: 'History'
};
$stateProvider.state('project.dataset.history', state);
$stateProvider.state('project.master.history', state); Is causing the state to always be the last one defined |
If we implement this, we'll also need to think about how we could handle dynamic view targeting. For instance, if I have more than two levels of heirarchy, child states will need to be able traverse their ancestors to find the appropriate Currently, a child state cannot access a (And yes, this is definitely a feature that I would make heavy use of.) |
I am pretty sure you can use the ^ syntax, no?
|
I don't believe that you can target states using the |
@schmod true. You can only use |
Can this be closed or is it still needed? |
Would be an array of states (strings/objects). This would allow us to attach a child to multiple parents, thereby allowing amazing code reuse (and opening up the opportunity for truly pluggable modules).
If you create a path-relative (agnostic) implementation of an 'edit' module, you could attach it to both a person and project and task module and get some excellent code reuse across the board.
The text was updated successfully, but these errors were encountered: