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

When would you getTasks() #12

Closed
Closed
@marcfallows

Description

@marcfallows

Given you hit the individual project state, which resolves a project to be injected into to the ProjectController.

Say you want to display the tasks for the project immediately for that state. At what point would you call the getTasks()? Would you do this right away in the ProjectController?

module.controller 'Project', ($scope, project) ->
    $scope.project = project
    $scope.project.getTasks()

Or, would you make it part of the resolve?

resolve:
    project: (AppObject, $stateParams) ->
        AppObject.getProject($stateParams.projectId).then (project) =>
            project.getTasks().then() =>
                project

Or maybe you were thinking something completely different?

The resolve works quite well with states, but once there aren't states I'm a little unsure on how to fetch the children.

Thanks for any help.

Activity

ProLoser

ProLoser commented on Jul 31, 2014

@ProLoser
Member

One of the awesome parts about ui-router's resolve chaining is you can make them siblings:

resolve:
  project: (AppObject, $stateParams) ->
    AppObject.getProject($stateParams.projectId)
  tasks: (project) ->
    project.getTasks()

Of course this will chain the queries and perhaps slow down the loading of the page. It just occurred to me that if ui-router doesn't load children states async then you can get a performance boost by placing the project's tasks into a substate, but this may not necessarily make sense for your navigation which is why the above solution should work too.

marcfallows

marcfallows commented on Jul 31, 2014

@marcfallows
Author

Amazingly quick response. I didn't know ui-router would chain those resolves, very cool.

Substates is more what I had in mind, but I'm not sure how you would load the tasks into a substate of the project by default. The ui-router setup in that case isn't very clear to me so I'll need to dig into the docs a bit more.

ProLoser

ProLoser commented on Jul 31, 2014

@ProLoser
Member

Yeah that SPECIFIC scenario has been sorta tricky for me in the past. Like lets say you get sent to project but really the default is always project.tasks. What I've had to resort to doing is essentially putting a check to see if you were going to a specific substate already and if not, redirecting you to project.tasks in the controller of project. It does cause the project state to finish loading and give the user more UI sooner, but it's been a bit annoying to code (you have to put a watcher on the routechange event and if someone goes from project.whatever to project you push them back into tasks) but perhaps this is something worth requesting on ui-router.

It's similar to the concept of an abstract state, like project essentially IS an abstract state, but if you DO navigate to it, you get pushed into a substate. In fact... angular-ui/ui-router#1235

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ProLoser@marcfallows

        Issue actions

          When would you getTasks() · Issue #12 · angular-ui/AngularJS-StyleGuide