-
Notifications
You must be signed in to change notification settings - Fork 18
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
fixed and improved JS scaffolding #32
base: develop
Are you sure you want to change the base?
Conversation
source/modules/.scaffold/scaffold.js
Outdated
/*! | ||
import EstaticoModule from '../../assets/js/helpers/module'; | ||
|
||
const name = '{{name}}'; |
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 we can skip this since the super class already adds a name
property: https://github.com/unic/estatico/blob/develop/source/assets/js/helpers/module.js#L15
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.
Well, only for the instance when constructed, which has a lot of drawbacks (e.g. many instances in the memory, no possibility to use that name in the other static properties and so on)
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.
Ah, I see
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.
Found a way to remove the name constant
|
||
class {{className}} extends EstaticoModule { | ||
export default class {{className}} extends EstaticoModule { | ||
static events = { |
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.
While I certainly like the idea, could a stage 2 proposal be a bit too experimental to be used in production already? https://github.com/tc39/proposal-class-public-fields
Judging from https://github.com/babel/babel/search?q=static+property&type=Issues&utf8=%E2%9C%93, there might still be some cases where the transpiled result might not be the expected one.
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.
Did not see any major problems there, most problems are caused by wrong usage - e.g. some guys did not understand that a class member belongs to a class and not to the instance and of course the inheritance works different.
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.
(Even if not using this version, it's still better to go back to constants defined outside the class. At the moment the objects are created over and over again for every instance.)
@@ -12,7 +12,7 @@ class EstaticoModule { | |||
* @param {object} options - The options passed as data attribute in the Module | |||
*/ | |||
constructor($element, _defaultData, _defaultOptions, data, options) { | |||
this.name = this.constructor.name.toLowerCase(); | |||
this.name = this.constructor.name; |
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.
We might consider forcing the lowercase again. We usually use this.name
for data-attributes matching and - quoting specs - these have to be lowercase.
The name of a custom data attribute in HTML begins with data-. It must contain only letters, numbers and the following characters: dash (-), dot (.), colon (:), underscore (_) -- but NOT any ASCII capital letters (A to Z).
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.
No reason to convert the case to lower case. What will happen, you can see in the current master branch - sometimes everything breaks, because everyone is using a different case. (Yes, the master branch is broken at the moment.)
Also it is not possible to convert this outside an instance, e.g. getting a class' name in the right case. It only works after an instance is created and needs to be converted for each instance over and over agin. Please also see #33 where I found a quite clean solution for the module registration.
(In our current setup we convert original class names like "Image Gallery" to the file name "image_gallery" and class name "ImageGallery". By using the class name instead of an extra lowercase for the assignment, we don't need a third case.)
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.
@swey, so you would use [data-' + this.name.toLowerCase() + '="bla"']
and $domElement.data(this.name.toLowerCase())
instead?
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.
Ah, got it. Sorry, I only thought of data-init
. (We use a different data binding, so I forgot about that.)
Don't have a good solution in mind right now. Will think about 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.
I definitely like the approach from #32 and #33. However the data-
attributes management remains open, and the approach from @backflip ([data-' + this.name.toLowerCase() + '="bla"']
) seems rather error prone. How about having this.name
and this._name
/this.dataName
for these 2 purposes (I know, my naming skills are really bad… feel free to propose another one).
This has moreover impact on linting configuration and how we would have to specify defaults in head.js
: we would need to use PascalCased object properties instead of "camelCased". Note that many times head.js
is used as the configuration point for backend developers, so having proper naming conventions there is important. @backflip would it be fine for you to change linting rules to accept as well PascalCased object properties?
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.
The main problem is, that working with this.name
is only working inside an instance. Which means that all properties must be set at runtime and for every instance again (which can cause a lot of extra operations and will block more memory). But well, of course we're only talking of quite simple and cheap string operations.
But I don't see a clean solution for your data binding besides adding a const name = 'module_in_yor_prefered_case';
before the class definition - very similar to the old version of estatico.
(In our team we use data-js-binding
without the module name. But of course binding to multiple instances is not that clean. On the other hand it solved a lot of problems with nested modules for us.)
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.
Having a new idea on this. Coming back with it the next days :)
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.
…NCOREL-108-footer-module-tasks-frontend to develop * commit 'ce9f7c4904954e1568f062066952a96b293a06b4': CONCOREL-108: Add ConcordiaMed to the footer. Adjust docs CONCOREL-108: Adjust footer max-width to use grid max-width CONCOREL-108: Swap png image with SVG CONCOREL-108: Add documentation for footer module CONCOREL-108: Add Footer module with content CONCOREL-108: Make iconLink use flex instead of floats
@christiansany, can you have a look at this when working on unic/estatico-nou#3? |
Fixes the initialization of the JS for modules
Refactoring: