angular-ui / ui-router

The de-facto solution to flexible routing with nested views in AngularJS
http://ui-router.github.io/
MIT License
13.56k stars 3.01k forks source link

tail function returns undefined when an object is expected #3620

Closed NgMomentum closed 4 years ago

NgMomentum commented 6 years ago

This issue tracker is for Bug Reports and Feature Requests only.

Please direct requests for help to StackOverflow. See http://bit.ly/UIR-SOF for details.

This is a (check one box):

My version of UI-Router is: v1.0.12

Feature Request

The current version of UI-Router has the function tail() being called in places that expect an object to be returned. Apparently, this doesn't happen very often (ever?) since this hasn't been raised before. Anyway, my solution was to add this function:

` function tail_state(arr) { var output;

    if (arr && arr.length) {
        output = arr[arr.length - 1];

        if (isObject(output) && output.state) {
            return output;
        }
    } else {
        console.warn('ui.router - tail_state -> no or empty input array.');
    }

    return { state: {} };
}`

Now, all calls to "tail" that were expecting an object with a "state", will get one. Not sure this is a good way to clean this up, but it does fix the inconsistency currently in the code.

christopherthielen commented 6 years ago

tail is general purpose, and doesn't always return an object with a state property. I'd prefer to fix the code that is calling tail on a 0-length array. Can you provide details on when this scenario happens?

NgMomentum commented 6 years ago

Hi Chris. Not really able to help much with "when" this occurs, as I'm using a modified version of AngularJS. I do lots of "on demand" loading of scripts, templates, css and the like, so it is probably just a timing issue on my side that isn't necessarily std to AngularJS. In some parts of my code execution, my version is faster, which has revealed problems with other third party scripts as well. Anyway, at least its documented.

Cheer.

On Tue, Jan 30, 2018 at 4:54 PM, Chris Thielen notifications@github.com wrote:

tail is general purpose, and doesn't always return an object with a state property. I'd prefer to fix the code that is calling tail on a 0-length array. Can you provide details on when this scenario happens?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/angular-ui/ui-router/issues/3620#issuecomment-361747141, or mute the thread https://github.com/notifications/unsubscribe-auth/ARDUTUcF1tNWSDFg_AisHLyuAOuvUIeEks5tP4-MgaJpZM4RuhaE .

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

This does not mean that the issue is invalid. Valid issues may be reopened.

Thank you for your contributions.