Importing moment.js into QML using Qt 5.2, part 2
I'm a perfectionist. So I tried to improve my patch for importing moment.js into a QML project to make it smaller and less invasive. Again.
Turns out it was possible! Also turns out I was wrong about QML not running IIFEs at import time. The problem was that the result just wasn't saved anywhere.
My new patch is at https://gist.github.com/Nicd/03ad7ca2599bf3d0c533#file-moment-js-diff
. The gist also includes the whole file.
This time I tried not to modify the IIFE, but sadly it seems that is a necessity. First I had to rename the 'as' function to 'asUnit', and second add a Qt specific section of code to the bottom of the IIFE which correctly returns the moment variable from the function. It has to be done this way because the 'this' object passed to the IIFE is not the global object and adding properties to it does nothing. To catch the result, I added a 'var moment =' in front of the IIFE.
The patch is smaller this time, but I'm still not completely happy. If some Qt/QML guru took a look at this, it could still probably be improved further. My ultimate aim is that the moment.js code could be added into the project untouched. Time will tell if that's possible.
Previous parts of my life with moment.js and QML for reference:
Part 1: https://plus.google.com/+MikkoAhlroth/posts/c5gnV9kiy1L
Part 0: https://plus.google.com/+MikkoAhlroth/posts/Gr5PaZxDWLs