Closed mykiimike closed 7 years ago
Last commit corrects a small issue on production check and i added template and public file overloading
Ok i added more features. You can now load views, public files and express plugins from your local installation directory
Thanks for submission!
I can't merge this as-is, since there's some issues with using hads programmatically with this (it wasn't documented, but still possible). Also, why did change the let
in var
? When using ES6, it's best to use let
and const
, and let var
be a thing of the past. Using let
everywhere is harmless, var
not so much 😉
There's some good ideas there, especially the views overloading, it is perfect for #2 in mind.
Do you mind if I merge this in a separate branch for now to give iron the few issues?
The trick is that I'm already using it :) My changes work well: p We should modify the hads.js and use object design to make a little more flexible module development.
It's like you want to finish :)
Actually, the let keyword is used to duplicate scoping contexts. It is used when you must keep a scope variable -1 in an iteration.
for (var i = 1; i <= 5; i++) {
var item = document.createElement("li");
item.appendChild(document.createTextNode("Item " + i));
(function(i) {
item.onclick = function(ev) {
console.log("Item " + i + " a reçu un clic.");
};
})(i);
list.appendChild(item);
}
Can be reduced to
for (let i = 1; i <= 5; i++) {
let item = document.createElement("LI");
item.appendChild(document.createTextNode("Élément " + i));
item.onclick = function (ev) {
console.log("Clic sur l'élément " + i + ".");
};
list.appendChild(item);
}
In the example above the scope of i is replicated at each iteration, impossible to retrieve the pointer except to be in the function called. In the first example, replication is forced at each iteration.
Normally it should only be used very rarely when a single pointer mutates. I read on the web that the use of let would be more efficient etc ... And in fact I do not think that it is because it requires that the JavaScript engine duplicates variables of the same scope (with let) 'With var we get a pointer.
So where I removed let is that it is justified (according to the use of every thing in a language).
It's not just a matter of duplicate scopes: variables using var
are function-scoped and hoisted (which can leads to very bad things), let
are block-scoped. There's no scope duplication, and the JS engine can better optimize let
statements because no hoisting is involved. The general opinion is that using only const
and let
does not hurt, and prevents var
potential issues. See this SE post.
As for the PR, I'll merge it in a branch in the meantime I refactor Hads code base a bit to better fit all the use cases (local offline, server with readonly, publish static HTML). 😀
http://stackoverflow.com/questions/37792934/why-is-let-slower-than-var-in-a-for-loop-in-nodejs
What happens when you declare a let variable in a for loop like that is that a new declarative environment is created to hold that variable (details here), and then for each loop iteration another declarative environment is created to hold a per-iteration copy of the variable (same for the block); each iteration's copy is initialized from the previous one's value (details here), but they're separate variables, as demonstrated in the link by the values output by the closures.
let must be used in certain condition http://www.ecma-international.org/ecma-262/6.0/index.html#sec-forbodyevaluation
http://stackoverflow.com/questions/36623440/let-vs-var-performance-in-nodejs-and-chrome
Thanks for the branching
+++ mykii
Hey,
Here is a patch i made because i need to publish single simple website using hads. Merge it if you want
All the best, Michael