-
Notifications
You must be signed in to change notification settings - Fork 456
Improve the UX/DX for creating a module for framework - Closes #2863 #2865
Conversation
Please resolve the conflicts. |
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.
In general, I'm kind of against having a BaseModule class at this moment. This change just makes the code more dependent on ES6 Classes while we can simply validate the JSON Schema for the module with schema validators.
Maybe this topic may require an STM, but I'd prefer to add complexity to the code when it's actually needed.
}, | ||
|
||
/** | ||
* Supported configurations for the module with default values | ||
*/ | ||
|
||
defaults: {}, | ||
get defaults() { return {}; }, |
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 avoid getters and setters in javascript. Because,
- I think it makes code a bit hard to read,
- It's not widely adopted by js developers,
- Stubbing or spying is still possible (https://stackoverflow.com/a/43744255) but it's not as straightforward as faking class methods.
- We get no feedback or exception if we make a typo like
obj.defults = 'something'
.
So I would prefer to have get and set methods instead of getters and setters.
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 think if we only have getter
it will throw an error if we do * obj.defults = 'something'
but it is very confusing to use defaults
with getter because in babel/es rule you can export default
. so,
export default class X {
default: 'x',
}
and you can do
import X from './above.js'
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.
In this project unless we have babel or typescript we can not use export default
. Event though its not confusing to if we have const options = module.defaults
and export default
. Both have totally different reasons and syntax.
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.
@yatki getters are used if you don't want to a setter ;)
Yes you can ask to freeze an object that will not be modified, but then it can not be modified by internal logic as well. So getters are a valid use case and in my experience its widely adopted language struct overall, for JS its newly announced language feature so will take some time for users to adopt.
48f0de9
to
66ce7a5
Compare
66ce7a5
to
4714a02
Compare
What was the problem?
Currently we are expecting any module to export a
json
object in following structure, which was not aligned with other framework structs.How did I fix it?
Introduced a new
BaseModule
class.Review checklist