-
Notifications
You must be signed in to change notification settings - Fork 173
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
Bundle with rollup / browserify (ES2015 modules) #40
Comments
yes, I have to replace with |
Would you care for some proper testing after update? I can assign you for that. |
Sure, I need to use this library for a project anyway. So, I could test if it works with |
Please update from npm and let me know how it goes. |
Sorry, I didn't have time today, I'll test it either tomorrow or within the next few days. Thanks! |
So, I just updated to |
IDK @mrksbnch I am open to suggestions. Do you think we can use something like |
@thednp Normally, this UMD wrapper for the plugins should work (I haven't tested this yet, though): (function (root, factory) {
if (typeof define === "function" && define.amd) {
define(["kute.js"], factory);
} else if (typeof exports === "object") {
module.exports = factory(require("kute.js"));
} else {
root.KUTE.PLUGIN_NAME = factory(root.KUTE);
}
}(this, function (KUTE) {
// Now you should be able to use `KUTE.pp` or `KUTE.prS` etc.
})); I'm not sure if you need to export anything for the plugins at all. If not, you can just get rid of #38 will also solve this issue. |
OK but can you please test this? |
@thednp Sure, will do later today. |
I would personally go the #38 route (major version bump). Plugin-based architectures don't play well with CommonJS, especially when the plugins modify the core libraries functionality. |
As for KUTE.js some plugins only extend the KUTE object, not override functionality. |
@thednp If you want to fix this issue before version 1.6.0, my code above works for me. Like I said, I don't think you need to export anything from the plugins. So, I can also confirm that this works: (function (root, factory) {
if (typeof define === "function" && define.amd) {
define(["kute.js"], factory);
} else if (typeof exports === "object") {
factory(require("kute.js"));
} else {
factory(root.KUTE);
}
}(this, function (KUTE) { I also changed line 26 var g = window, K = g.KUTE /* ... */ to var K = KUTE /* ... */ However, I got another error on line 242, but this is probably related to #35:
Any ideas? |
Just to clear things up: If I just import KUTE.js and the SVG plugin (with the improved UMD wrapper), I don't get any errors. I just got the last error because I tried to morph two paths: KUTE.to('#nav-morph-init', {
path: '#nav-morph-init',
}, {
path: '#nav-morph-open',
}).start(); So, it's not strictly related to this issue, but more to #35. |
Your above example should be KUTE.fromTo( // proper tween constructor method to be used, pay attention
'#nav-morph-init', // element
{ path: '#nav-morph-init'}, // start path
{path: '#nav-morph-open'} // end path
).start(); or KUTE.to( // proper tween constructor method to be used, pay attention
'#nav-morph-init', // element
{path: '#nav-morph-open'} // end path
).start(); I think that's why you get an error, also due to the fact that the script found no element in your HTML. About your UMD version, probably related to the issue it's about the interpolate functions that are exported to the With versions 1.5.0 - 1.5.9 I've done some experiments with regards to performance and the fastest seems to be the usage of FYI: I would love to have some coding partners to talk to, brainstorm, exchange ideas in the following spectrum of interests:
|
I can't see how that can be that much faster, that is micro-benchmarking IMO. A good read on that subject: https://github.com/getify/You-Dont-Know-JS/blob/master/async%20%26%20performance/ch6.md (If you have time, the whole series is a great read BTW). Using |
@RyanZim I am totally against pollution of the global scope but a small little object var AnimationObject = window._Animation = {
update: function(){},
ticker: function(){},
tick: 0,
domUpdate : {}, // DOM update functions for each property used by active tweens
easing: {}, // easing functions used by active tweens
interpolate: {}, // interpolate functions used by active tweens
tweens: [] // active tweens
} would be better than populating in the KUTE object, because object lookup access speed and stuff like such. |
Sounds good. I'm not really sure why using Personally, I think it's ok to use Little off topic: I'll try to morph |
@mrksbnch What is wrong with using I now understand that I cannot simply connect KUTE with it's plugins the way I did, your method is probably best, but really can you please explain a little bit what's going on? |
In CommonJS, we expect that everything stays contained inside its own module; that way, there is never any possibility for collision.
I can't see why there would be any speed difference, but I could be wrong. If you can provide actual performance figures/tests, that would be great. |
You have a note on performance on the demo page. Also the performance testing page here. There are almost 2 years testing performance and improving the code, and I figured that's what all major scripts do. Anyways, to put it short: the shorter the "distance/depth" from
So how can I still use |
If you bundle your files with
Are you referring to the performance of a key lookup in an object? I might be wrong, but if I do... import KUTE from 'kute.js';
KUTE.to(...); ...I can directly access the import 'kute.js';
window.KUTE.to(...); ..., and take one more key lookup. |
Yes, functions like ticker, or those built dynamically for DOM updates, like Take this example: (root is the
In any case, no matter what, the first will execute faster because there is less object traversing by a level of one, and that is the nature of Javascript really, no matter what node or browser you're working with. Please tell me: what are |
@thednp Have you ever benchmarked JS object lookup speed? That is one of the fastest areas of JS IIRC. I would like to see some actual figures of the difference between level 2 & level 3 lookups. |
I did a little benchmarking: level 3 lookups are 0.00228635622 nanoseconds slower than level 2 lookups. Studies show that the brain can't perceive speed differences less than 13 milliseconds. Based on that, you would need to do 5,685,903,136 (that's over 5 billion) object lookups to make a speed difference large enough for the brain to perceive! 😮 Not worth it IMO. |
@RyanZim I perfectly agree with you. Remember the point of this is to achieve best possible performance in most situations (even on very high stress level) so I figured it has to be like this:
So it's not just as you tested in your benchmark Ryan, it's a bit more complex, but we aren't spending time with something important here. We should be going forward with what needs to be done and not argue with things that are facts. GSAP does this, @mrksbnch confirmed snapSVG does this, I already know and do this, so we're wasting time. Can you please think about a way to make node work in the manner I need please? |
@mrksbnch this code you posted (function (root, factory) {
if (typeof define === "function" && define.amd) {
define(["kute.js"], factory);
} else if (typeof exports === "object") {
factory(require("kute.js"));
} else {
factory(root.KUTE);
}
}(this, function (KUTE) { is for plugins right? |
@thednp Yes |
Please stay with me on this, I really want it solved once and for all. So if I do this |
Hm, like I said, const g = window !== undefined ? window : global; @RyanZim Do you know if this will this work? |
Also @IngwiePhoenix could be of use in this mater. |
@mrksbnch I will prepare some new code with your findings, will publish 1.5.91 on npm and you can do some testings ok? But I need you to test CSS, ATTR and Text plugins as well. |
@thednp Sure, will do |
Before that, please do me a little test in your node env: console.log(global||window) and let me know what this outputs in your node. |
@thednp This will output the |
good, in that case we use you UMD wrapper and this |
OK my tests are ok, please update and test. |
I'm afraid this won't work for CommonJS. This line module.exports = factory(require("./kute.js")); should be module.exports = factory(require("kute.js")); because your npm package name is |
OK patching up and please test 1.5.92. |
@thednp Did you already update the code on npm? |
yes 1.5.92 https://www.npmjs.com/package/kute.js What's going on? |
Thanks, it's working for me now. However, I couldn't test an actual SVG animation (SVG plugin) due to the |
That's because the element is not found. The plugin needs to read the |
That's what I thought too, but it's in my HTML: <svg
class="js-nav-morph"
width="100%" height="100%"
viewBox="0 0 300 300"
preserveAspectRatio="none">
<path id="nav-morph-init" d=".."/>
<path id="nav-morph-open" style="visibility: hidden;" d="..."/>
</svg> I also tested it with |
Can you make a repo so I can have a look at it. |
Sure, I can provide a reduced test case (probably not right now) and will create another issue for it. |
If I try to import KUTE.js in my project...
..., I'll get the following error in the console:
In this case, I was trying to bundle my JavaScript files with
rollup
, but it doesn't seem to work withbrowserify
either.The SVG plugin looks for KUTE.js on the window object, but this is not defined if KUTE.js is imported from an AMD or CommonJS context (UMD wrapper). So, how's this supposed to work in this case? I couldn't find any notes in the documentation.
The text was updated successfully, but these errors were encountered: