-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
…e updated. not really for performance improvements, as the objects comparaison it not that cheap, but more like correctness.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -7,34 +7,70 @@ | |||||
|
||||||
'use strict'; | ||||||
|
||||||
function multi(node, args) { | ||||||
var multi = function(node, args) { | ||||||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
akhoury
Author
Collaborator
|
module.exports = multi; |
and here
Ractive.decorators.multi = multi; |
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
zaus
Feb 3, 2016
But that's my point -- it's already in local scope, so you don't need to declare it as a variable to use it that way.
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
akhoury
Feb 3, 2016
Author
Collaborator
i dont understand. I need to conditionally reference that function in either places, how do you that without the local variable? can you give me an example?
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
akhoury
Feb 3, 2016
Author
Collaborator
btw - it's using the function declaration style now, not var
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
JonDum
Feb 3, 2016
Owner
The only difference between function foo()
and var foo = function()
is that the function declaration style gets hoisted to the top of scope. That's it. It still behaves like a normal variable, so it works fine references in if statements like that.
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
akhoury
Feb 3, 2016
Author
Collaborator
yea, i know, that's how it was before I did this commit, so i changed it back (here) to maintain your style.
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
zaus
Jan 31, 2016
self
will minify but this
will not, and also ensures you're using the correct this
if you have a nested function declaration (such as within a callback of .forEach
).
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
akhoury
Jan 31, 2016
Author
Collaborator
i removed self
all over the place because all the nested functions did this .bind(self)
then used self
within, which doesn't make use the binding at that point. But, you're right about minifiers though ... feel free to submit a PR to correct this if you want, but to be honest, I don't think I care too much. Sometimes I'd rather have a meaningful code style vs worrying about some extra bytes, where do you draw the line on that?
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
zaus
Feb 3, 2016
Fair enough. Good point about the bindings, probably has some kind of lifecycle/dependency benefit.
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
akhoury
Feb 3, 2016
Author
Collaborator
well, ok, i guess less function calls is the thing, except that these call happen once per the multi-decorator construction, not per update. But OK, i guess, as long we don't do bind(self)
- i don't have objections.
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
zaus
Feb 4, 2016
I don't think it's applicable here regarding self
vs. this
, but I thought I'd mention the following.
I think the Ractive author posted somewhere about variables created in an external scope possibly interfering with garbage collection. If I remember correctly it was in the context of referencing a DOM element within a function and storing it to global variable, which prevented Ractive from cleaning up the function call because it couldn't release all the stuff it had made. So probably not relevant, but referencing a variable from another scope in a function that gets called elsewhere made me wonder. Sorry to muck up the discussion...
Also these weird posts about this
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
akhoury
Feb 4, 2016
Author
Collaborator
true - but sometimes you don't want it to be garbage-collected - in this example, the var multi
will be referenced all over the place if you're using it, and you don't want that to be scraped by the gc.
Also, referencing a DOM element in JS and vice versa could cause a memory leak, but that in old browsers, not new ones, hopefully.
see ractivejs/ractive#1451 (comment)
1 comment
on commit 203bd2c
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.
Nice! Still, less CPU cycles the better!
Do you need to declare it as a local variable? It's already not in global scope because it's within the
(function(){ ... })()
wrapper, and minifies better (function m(n,a)
vsvar m=function(n,a)
), and I read somewhere that named functions are easier to debug because they show up in the stack trace. Please correct me if I'm wrong.