Open vbulant opened 8 years ago
I would suggest to think from the end result - What should the example teach/demonstrate?
Possible points:
It can be a small helper function, or just a dummy function for demonstrative purposes.
With these 2 components/modules (module.js
and alertifier.js
) we want to demonstrate:
init
and factory
functionsAs Vojta wrote,
let’s think of something closer to the "real world"
but defintely not necessary about
Something you 99% need in each of your project
Also, we can try to resolve the schizophrenia with named vs. arrow functions here.
for init: "using cookies" message based on version/time
for factory: button triggering collapse (show/hide content)
Great idea!
@zoltan-kovac any luck with the factory/collapse example? If not, I’ll try to do something simple.
Sorry for interrupting, I've just got an idea come into my mind: Each project I have participated in uses anchor scroll navigation (from regular "Go to top" to custom in-page navigation between anchor breakpoints). Sometimes even such a simple thing as this may cause a lot of extra code (hidden containers for anchors, unnecessary events and hooks in JavaScript). I think this might have been a good and useful JavaScript demo in a devstack.
/* anchorNavigator.js */
export default class AnchorNavigator {
constructor(container) {
this.container = container;
this.container.onClick = this.handleClick;
}
handleClick() {
const { scrollTo } = this.container.dataset; // "#" + scrollTo
/**
* Use one of the smooth scroll techniques here.
* I would suggest the method from MDN (no jQuery).
*/
}
}
initializeMethod(AnchorNavigation, document.querySelectorAll('[data-scroll-to]'));
<header id="header"></header>
...
<button data-scroll-to="header">Go to top</button>
This would also be a nice example to demonstrate a proper semantics between a
and button
. It was quite an interesting thing to find out that doing in-page scroll navigations with a
is wrong. Anchor element semantically should lead to the different page. In-page actions is a primarily usage for button
.
@vbulant I have this branch somewhere. Will put it together during the easter. My solution is animating height with css transitions, with hooks on transitionEnd event. This is the bootstrap approach. If we really want simpler solution, maybe go ahead.
@kettanaito it's a nice example, but I wouldn't use [data-scroll-to]
as selector, but rather a class="js-scrollTo"
for the JS init and use [data-scroll-to]
only as info where to scroll
https://intuio.at/blog/dont-use-data-attributes-to-find-html-elements-with-js/
@ronaldruzicka a valid argument. Sure, it was just an example :)
P.S. However, now returning to benchmarks regarding getElementsByClassName
vs querySelectorAll
: the first method is faster in a larger scope. I think this is what should be taken into account. When running a selector over 10,000+ elements it sure has a significant superiority over querySelectorAll
, but you will unlikely to notice a difference when used for smaller amount of DOMElements. I often hear to not rush into trusting JavaScript benchmarks, as they are all quite isolated, and may not affect the performance as it seems.
There are rarely more than 10 in-page scrolling anchors on the same page, so this optimization may be redundant (best optimization is not to over-optimize). Yet, I would leave it to an open discussion.
In case anyone wants to continue with @zoltan-kovac’s collapse, it’s pushed here: https://github.com/actum/gulp-dev-stack/tree/82-collapse
Reasons
no-alert
eslint rule