-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
refactor: remove immutable from 'config' state slice #4960
refactor: remove immutable from 'config' state slice #4960
Conversation
718d0f6
to
80cb9d3
Compare
80cb9d3
to
349e141
Compare
349e141
to
652bebf
Compare
|
||
const backend = new Backend(implementation, { config, backendName: config.backend.name }); | ||
const backend = new Backend(implementation, { config: {}, backendName: 'github' }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@erezrokah why do you think it's better to not use real default state? When tests are converted to typescript we'll have to either put a lot of tsignore statements or "as SomeType" statements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I worried this will make the tests brittle. Personally I like to have in the tests as little as information possible required for them to pass so I don't have to change them too often.
As for typing the tests - we'll have to see if that makes our lives easier or not? I would expect tests to fail when something breaks and not rely on types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect tests to fail when something breaks and not rely on types
this is true. On the other hand you're basically passing incorrect values to functions being tested. So tests might pass because of that. And might fail if correct values are provided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is true. On the other hand you're basically passing incorrect values to functions being tested. So tests might pass because of that. And might fail if correct values are provided.
I believe that's something to verify when writing the tests. The test should be scoped to assert a specific thing and not verify that backend.ts
methods work with the default config?
If so, we should have separate unit tests to verify that backend.ts
handles the configuration properly (and not assume it works because we're passing default values).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright
@@ -643,7 +643,7 @@ function evaluateFolder( | |||
entryMap: EntryMap | undefined, | |||
field: EntryField | undefined, | |||
) { | |||
let currentFolder = config[folderKey]; | |||
let currentFolder = config[folderKey]!; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is a correct way to handle it. Because here we're lying to compiler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Under this function that value is always defined.
The only reason we allow not to set media_folder
is if you have an external media library which in that case this code doesn't run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if there is more correct way to express it with types, so we don't have to use these escape hatches.
for (const collection of collections) { | ||
newState[collection.name] = collection; | ||
} | ||
const newState = Object.fromEntries( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't agree that using map + fromEntries is more readable than simple loop :) functional style doesn't really shine here and looks way more confusing than the loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually both methods have a bug of not maintaining the order of the collections as appeared in the configuration.
See c0e43bc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, in future we can use js Map to maintain the order
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I'm wondering, why is it happening in the first place. I thought modern js engines maintain property order in js objects. It wasn't the case in the past, but I was sure that it had been fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm pretty sure this is the problem with Immutable. This works correctly. The order is being preserved.
let obj = {};
let arr = ['collection_1', 'collection_3', 'collection_2']
for (const item of arr) {
obj[item] = item;
}
Though the order is not being preserved if property name is a number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, JS keeps insertions order. It's the fromJS
that doesn't know how to handle it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥
Sorry for taking so long to do this. I feel like I had to grow another set of 👀 for it.
thx @erezrokah. no need to apologize. I know it's a lot of changes to review. thank you for being a thorough reviewer. I'll try to not make that many changes in future PRs, though it's not that easy in this particular-getting-rid-of-immutable case :) |
Summary
Continue with #3853
Test plan
Run existing tests