Closed (fixed)
Project:
Drupal core
Version:
8.6.x-dev
Component:
javascript
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
19 Oct 2017 at 00:10 UTC
Updated:
5 Mar 2018 at 18:34 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
dawehnerComment #3
dawehnerNote: not all of them are converted yet.
Comment #4
GrandmaGlassesRopeManSome more cleanup.
Comment #6
GrandmaGlassesRopeManOh, so it looks like the first patch did not contain the transpiled code. This might explain some of the errors.
Comment #7
dawehnerThis could be a
.map, do we care? I guess it would no longer be the minimal change? ... Note: Given that this is inside a foreach the for rule still kinda applies. Can we extract the function above first?I guess we could get rid of the if here?
This is wrong. You need to check the return value to be able to return false
Note: The patch I'm uploading is #3 with actual JS build. Sorry, for missing that.
Comment #9
GrandmaGlassesRopeManI think this may fix some of the issues. @dawehner, sorry, I didn't fix anything
Comment #10
GrandmaGlassesRopeManComment #12
dawehnerThis is particularly awful.
Comment #13
GrandmaGlassesRopeManStore the length outside the for loop so we don't have to compute it each pass.
Comment #14
dawehnerDone
Comment #15
droplet commentedReserved. Making some cleanups
Comment #16
droplet commentedwow. A huge patch. I wonder how much time @dawehner spent on it!!!
I haven't finished my review but clean up the vars scope that will help for reviewing I think. Hope I haven't messed it.
Comment #17
dawehnerI try to understand this for example. You seem to no longer do the minimal changes. Everything beyond the minimal changes will make life harder for other reviewers and core committers and ultimately for you as well.
Comment #18
droplet commentedcode like this creates a new `no-shadow` issues.
Most for-in loop, the var defined outside the block. I moved it back to block scope. (Including to remove unused var)
Comment #19
droplet commentedIt's very risky to assume for-in and Object.keys is a 1:1 changes and scan the patch online only. (this style, @dawehner patch is easier to review)
But, if you applied offline and start to read the code (to check if there's any extra if-else around the code) and var scope..etc. Then, I think my extra change would help you to understand it better (& faster).
Thanks
Comment #20
dawehnerThat is a strong point. The different semantic of var and let/const is dangerous quite often.
I really try to think: What would the core committers say, simply to avoid some slowdown for our overall process.
+1
This change seems not necessary even it is the right change on the longrun.
Can't we move those even into the for loop itself? I don't see them used outside of it.
Comment #21
droplet commented#2 removes the self ref.
I will give up if it slows down the process. Sorry for the noise.
Comment #22
dawehner@xjm asked for splitting up this issue into reviewable chunks. #2925064: [1/2] JS codestyle: no-restricted-syntax now contains the easy changes.
Comment #23
xjmComment #24
dawehnerComment #26
dawehnerHere is my try to reroll this patch.
Comment #28
webchickHm. Nothing in this patch touches image styles; let's try that again.
Comment #29
webchickComment #31
webchick"exception: [Warning] Line 177 of core/lib/Drupal/Core/Cache/ApcuBackend.php:
apcu_store(): Unable to allocate memory for pool."
Sounds like a testbot issue...
Comment #32
GrandmaGlassesRopeMan- reroll from #26.
Comment #33
dawehnerReading through this bit again I'm quite convinced that this can be replaced by
Object.keys(...).every(return filterStatusAllowsFeature)Right now we have basically something like:
NOT (NOT A OR NOT B). Using https://en.wikipedia.org/wiki/De_Morgan%27s_laws NR 2 we end up withNOT (NOT (A AND B))which isA and B.Comment #35
GrandmaGlassesRopeMan- some more updates.
Comment #37
GrandmaGlassesRopeMan- the one where we don't break table drag.
Comment #39
GrandmaGlassesRopeManComment #41
GrandmaGlassesRopeManComment #42
dawehnerI stared at that code now for a while. If result is true before, we return true, just as before. When result was false before, but one of the conditions is false, we return false. To be honest I'm a bit confused why we don't jut always return result in the every() function.
Comment #43
GrandmaGlassesRopeMan@dawehner Lets see how this goes with the tests.
Comment #44
GrandmaGlassesRopeManComment #45
dawehnerLet's hope for the best :P
Comment #47
GrandmaGlassesRopeMan@dawehner So #41 is it...
Comment #48
dawehneryeah, let's go with #41. To be honest the existing code is far from being easy to understand either, given its local state is using something from far above.
Comment #49
alexpottFYI part 1 introduced an unexpected regression see #2941106: Site email address in the install profile form is no longer copied to the user email address.
Comment #50
alexpott#41 makes
yarn lint:core-js-passingfail with:Also the changes to color.es6.js appear to be out-of-scope for fixing JS codestyle: no-restricted-syntax - they seem to be fixing no-shadow
Comment #51
GrandmaGlassesRopeMan- removes changes to color.es6.js
- fixes expected return.
Comment #53
GrandmaGlassesRopeMancc. @dawehner
Comment #54
alexpottI think we can simplify the logic here if we just accept that we should check all the constraints. If we want the early return we could use
.someand invert the logic but that would be head-scratching.Comment #56
alexpottWow there is something very strange going on inside
checkConstraintsPatch attached passes the failing test and uses .some to continue to have the performance hack of not checking all the constraints if one evals to false.
Comment #57
GrandmaGlassesRopeMan-
ternary()was slightly too long, broke it up into multiple lines.- fixed multi-line comment format.
@alexpott - I think this looks really good. 👍for RTBC if this patch works.
Comment #58
dawehnerI'm a bit confused. Isn't every and some just two side of the same spectrum given that we want an early return?
To be honest I'm not sure that the some/every really increases readability. An ordinary for loop could be better overall.
Comment #59
alexpottWell the problem is caused by
And the fact that if both are undefined it returns undefined as the function description says:
Bitwise AND with a third undefined state.. Ternary not always returning FALSE or TRUE is pretty magic.Ah this leads me a more elegant solution. All the problems are happening because of the initial state of result being undefined and checkConstraints also returning undefined.
Comment #60
GrandmaGlassesRopeManJust a very minor nit. Otherwise, this looks great, and awesome debug work @alexpott.
Can we switch this to the multi-line comment format?
Comment #61
alexpottSo this is the only usage of
ternary()- given that I think we should just inline the logic and not use it. Because calling ternary with one argument astrueis pretty weird.Comment #62
alexpottOh and we can actually remove
ternary()because it is no longer used and it is not part of our javascript API.Comment #63
GrandmaGlassesRopeManAlright, awesome. Tests are green, and the logic here makes a lot more sense.
Comment #64
alexpottI've stared at this for considerable amounts of time and whilst I think the return value is always going to be the same I'm pretty sure that we're doing quite a lot of unnecessary looping here because we've removed the early return. But what feels more icky is that the new code is harder to understand. Could we change the flow here to first determine the and once we have that delta use it to return the rowSettings. This way we wouldn't have to filter.
Comment #65
alexpottSomething like the patch attached.
Comment #67
GrandmaGlassesRopeMan@alexpott Can we do any kind of profiling to see if any of these loops actually cause some sort of performance impact? I personally don't think the new code from #62 is all that complicated, and actually a bit more understandable since we dropped
ternary().Comment #68
alexpottLooks like we can't use es6 functions like .find() yet. Let's go back to #62 - at least #65 proves we have test coverage.
@drpal the change in #65 is about the tabledrag changes not the states changes. I agree the loss of the early return in states is no biggie.
Comment #69
GrandmaGlassesRopeMan@alexpott - Looks like no
.find()support in IE. Eventually we should have a polyfill discussion around handling these.Comment #70
dawehnerBrowsers are so hard
Big +1 for the new bits though.
I think @alexpott should not have tried to use
.find. This issue is not about endless refactoring, because well, we could do that forever. We should focus on not doing that.Comment #71
alexpott@dawehner the reason I tried to improve it was because the new formulation in tabledrag is harder to understand than before as pointed out in #64 - I agree we shouldn't be endlessly refactoring but refactoring into less readable code should be avoided where possible - which is what I was trying to do.
So we've got @dawehner's and @drpal's and I've reviewed the code changes extensively plus we've proved there is test coverage. Time to get this done.
Committed b4064da and pushed to 8.6.x. Thanks!