Skip to content
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

Replace angular.forEach with Utilities.forEach #10759

Merged
merged 4 commits into from
Aug 1, 2021

Conversation

bjarnef
Copy link
Contributor

@bjarnef bjarnef commented Jul 28, 2021

Prerequisites

  • I have added steps to test this contribution in the description below

If there's an existing issue for this PR then this fixes #7718

Description

Previous this PR #7928 was submitted to replace angular.forEach
However it seems not all references has been replaced or maybe because other PRs has been merged afterwards.

It can use vanilla JS array.forEach or Utilities.forEach.
Current both versions are used in core, but Utilities.forEach is a bit safer as it only iterate if array variable not is null or undefined.

@umbrabot
Copy link

umbrabot commented Jul 28, 2021

Hi there @bjarnef, thank you for this contribution! 👍

While we wait for one of the Core Collaborators team to have a look at your work, we wanted to let you know about that we have a checklist for some of the things we will consider during review:

  • It's clear what problem this is solving, there's a connected issue or a description of what the changes do and how to test them
  • The automated tests all pass (see "Checks" tab on this PR)
  • The level of security for this contribution is the same or improved
  • The level of performance for this contribution is the same or improved
  • Avoids creating breaking changes; note that behavioral changes might also be perceived as breaking
  • If this is a new feature, Umbraco HQ provided guidance on the implementation beforehand
  • The contribution looks original and the contributor is presumably allowed to share it

Don't worry if you got something wrong. We like to think of a pull request as the start of a conversation, we're happy to provide guidance on improving your contribution.

If you realize that you might want to make some changes then you can do that by adding new commits to the branch you created for this work and pushing new commits. They should then automatically show up as updates to this pull request.

Thanks, from your friendly Umbraco GitHub bot 🤖 🙂

Copy link
Contributor

@nathanwoulfe nathanwoulfe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @bjarnef, as always. Wonder if it's worth considering adding JS lint rules for the angular methods?

@nathanwoulfe nathanwoulfe merged commit 56790f7 into umbraco:v8/contrib Aug 1, 2021
@nathanwoulfe nathanwoulfe mentioned this pull request Aug 1, 2021
17 tasks
@bjarnef bjarnef deleted the v8/feature/angular-foreach branch August 2, 2021 00:00
@nul800sebastiaan
Copy link
Member

@bjarnef @nathanwoulfe - ehmmmm... not sure what's happening here?? Help!! 😁

This started happening with this commit, so something is not quite right here..

10759.mp4

@bjarnef
Copy link
Contributor Author

bjarnef commented Aug 5, 2021

@nul800sebastiaan strange. It should be the same just with a null and undefined check.

/**
* Not equivalent to angular.forEach. But like the angularJS method this does not fail on null or undefined.
*/
const forEach = (obj, iterator) => {
if (obj) {
return obj.forEach(iterator);
}
return obj;
};

It seems there's something failing in checkfocus in a directive/component.

Somewhere here I guess:

function checkFocus() {
var found = false;
// check if any element has focus
Utilities.forEach(listItems, (item, index) => {
if ($(item).is(":focus")) {
// if an element already has focus set the
// currentIndex so we navigate from that element
currentIndex = index;
focusSet = true;
found = true;
}
});
// If we don't find an element with focus we reset the currentIndex and the focusSet flag
// we do this because you can have navigated away from the list with tab and we want to reset it if you navigate back
if (!found) {
currentIndex = 0;
focusSet = false;
}
}

@bjarnef
Copy link
Contributor Author

bjarnef commented Aug 5, 2021

@nul800sebastiaan I think it fails here because obj passed in is an jQuery object and not and array. Maybe it would also be more correct naming the parameter name array/arr instead of obj.

image

image

@nul800sebastiaan
Copy link
Member

I'm not sure, currently I don't understand what this means! 😅 😊 I'd love some help here if you have a bit of time!

@bjarnef
Copy link
Contributor Author

bjarnef commented Aug 5, 2021

It seems element.find("li :tabbable");returns an empty array. Not sure if it previous returned something?
However the forEach() will iterate this:

const forEach = (arr, iterator) => {
    if (arr) {
        return arr.forEach(iterator);
    }
    return arr;
};

Also to clearify: https://stackoverflow.com/a/31096661/1693918

Object does not have forEach, it belongs to Array prototype.

@bjarnef
Copy link
Contributor Author

bjarnef commented Aug 5, 2021

I made some changes in utilities.js but it didn't seem these wasn't compiled using dev gulp task.
Also when clicking root node I get this error from PR #10762

image

I totally forgot the closeBackdrop only was as local/private function and thus not directly available via navigationService.
#10800

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

Successfully merging this pull request may close these issues.

Start decoupling from AngularJs
4 participants