Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23
  1. #16
    Senior Coder deathshadow's Avatar
    Join Date
    Feb 2016
    Location
    Keene, NH
    Posts
    2,318
    Thanks
    2
    Thanked 334 Times in 324 Posts
    In documenting I came up with a good question... with my classExists, ClassRemove, ClassAdd and so-forth functions I have it as:

    _.classAdd(element, [String || Array]);

    where if it's a string, it's a single class to be added, if it's an array it's an array of classes to be added to the element...

    Would it make sense for me to check for the presence of spaces so you could also pass:

    _.classRemove(e, "test one two three");

    That would function the same as:

    _.classRemove(e, ['test', 'one', 'two', 'three']);

    removing any of those classes if present? I'm not sure it's worth the extra code since the multi-class I tend to use when dealing with checkboxes in forms, but what I use it for isn't necessarily what other people would so...

    Worth the code? Not worth the code?

    I mean it would be a simple:

    Code:
    if (data.indexOf(' ') !== -1) data = data.explode(' ');
    Added to each function before the typeof check... and there's only like four functions... Argh, decisions, decisions... I could reduce them all to having that logic as a single function and pass the actual operation as a callback; not sure if the performance impact from that would be excessive or not.

    More things to test.
    Last edited by deathshadow; 02-10-2017 at 05:58 PM.
    I would rather have questions that can't be answered, than answers that can't be questioned.
    http://www.cutcodedown.com

  2. #17
    Senior Coder deathshadow's Avatar
    Join Date
    Feb 2016
    Location
    Keene, NH
    Posts
    2,318
    Thanks
    2
    Thanked 334 Times in 324 Posts
    Ok, took a little longer as I spent a few hours without power, but here's mine in beta and documented:
    elementals.js

    Once I get some demo's, debugging, and tutorials in place I'll be announcing the relaunch in its own thread... but for now, ideas, whaddaya think? I know it's hard to tell without any working demo's so I'm gonna get right on that next.

    you want to skip right to the library, you can do so here:
    http://www.elementalsjs.com/downloads/elementals.js

    It's mostly based on what I do with scripting on sites, which I realize doesn't exactly line up with what most people seem to throw JS at sites for. Interestingly the site itself uses the library to lazy-load disqus, my own social button implementations, and the advertising. I built the file monolithically by adding the site specific scripting to the end of elementals in this file:

    http://www.elementalsjs.com/scripts/library.js

    So as to reduce the number of handshakes. For now you could use that as an example of using some of the minor functionality of elementals.js

    As you can see it traps onload to handle the social scripts and advertising -- that way the IMPORTANT part of the page - the content -- loads before the bloated fancy extras. Given that without the adverts, social, and disqus plugin the pages average 3 separate files and well under 72k in size, the page remains pretty peppy despite the inclusion of the bloated extra stuff... as it should be.

    Whadday'all think?
    I would rather have questions that can't be answered, than answers that can't be questioned.
    http://www.cutcodedown.com

  3. #18
    Senior Coder deathshadow's Avatar
    Join Date
    Feb 2016
    Location
    Keene, NH
    Posts
    2,318
    Thanks
    2
    Thanked 334 Times in 324 Posts
    Just an update, I'm probably about a day out from release candidate one. Beta 5 is in development right now, which I'm hoping will be the last release before the first (and hopefully only) RC.

    I've also added a demo's page with some live demo's -- that section is likely going to grow the next day or so before the beta 5 or possibly even RC 1 release.

    elementals.js demos and libraries - elementals.js

    Whether this next release is the final beta or the first release candidate will hinge on what the folks I have testing it say, and what comes up whilst I'm finishing off the final demos.

    When it hits RC, I'm going to be giving it its own thread, and mass posting it on dev forums and social media.
    I would rather have questions that can't be answered, than answers that can't be questioned.
    http://www.cutcodedown.com

  4. #19
    Regular Coder
    Join Date
    Apr 2011
    Posts
    163
    Thanks
    0
    Thanked 51 Times in 49 Posts
    It looks promising, it got some nice tools to it.

    I played with it for a short while and found some bugs you might want to fix before release:

    Code:
    		msgLog = {
    
    			alert : function(m){_w.alert(m)}, // alert needs to called on the window object
    
    			append : function(m) {
    				_.make('br', { last : _d.body }); // elements should be appended to the body instead of the document
    				_.nodeAdd(_d.body, m);
    			},
    Only tested the reduce polyfill. When the second argument (initial value) is omitted it should use the first index as initial value and start from the second index.
    So ['a','b','c'].reduce((t,v) => t+v) should return 'abc' instead of '0abc'.

    It is suggested that you place all scripts involving elementals.js at the end of your markup right before you close the BODY tag,
    That's an understatement, placing elementals.js in the <head> will cause an error, because it tries to attach the 'elementals' class to the not yet existing <body>.

  5. #20
    Senior Coder deathshadow's Avatar
    Join Date
    Feb 2016
    Location
    Keene, NH
    Posts
    2,318
    Thanks
    2
    Thanked 334 Times in 324 Posts
    On the "suggested" -- good catch, that is indeed incorrect as it now MUST be, I'll edit the instructions accordingly.

    append should indeed be _d.body and not _d.

    But on alert, you can assign a function to a variable or object as a reference, so that is in fact valid as written. Check it:

    Code:
    <script>
    var test = window.alert;
    test('wtf');
    </script>
    Will work, as such:

    alert : _w.alert,

    Is in fact valid and functions as expected.

    the msgLog options for _.ajax has not been tested as well as I probably should, I'm going to tack that onto the to-do list for today.

    ... and I need to give the polyfills another once-over. Honestly "reduce" is one I had requested that I'm actually not that familiar with the workings of. I'm going to double-check my code against MDN's polyfills just to be sure I've got that right... though they recently rewrote them and NONE of them bear any resemblance to what they had up a few months ago -- to the point I can't even figure out what their current Array.reduce is even doing.

    But then I'm still adjusting to there even being a "const" much less what in blazes => is doing in JavaScript... and with no versions of IE even having support for it, it's not like you could even use it that way in the first place in a web production environment.

    "['a','b','c'].reduce((t,v) => t+v)"

    Not being something you would ever even be able to run using elementals in the environment it is meant for use in. ESPECIALLY if the polyfills are added. In fact by definition if the polyfill goes through, => doesn't exist.
    Last edited by deathshadow; 02-18-2017 at 08:09 PM.
    I would rather have questions that can't be answered, than answers that can't be questioned.
    http://www.cutcodedown.com

  6. #21
    Senior Coder deathshadow's Avatar
    Join Date
    Feb 2016
    Location
    Keene, NH
    Posts
    2,318
    Thanks
    2
    Thanked 334 Times in 324 Posts
    Ok, looks like there's gonna be a beta 6 before the RC.

    @Goos, does this seem more correct to you? I was operating on the assumption reduce would only be useful for numeric arrays, never even occurred to me people would use it on strings.

    Code:
    		reduce : function(c, v) {
    			_.throwNonType(c, 'function');
    			var i = 0, j = this.length;
    			if (typeof v == 'undefined') {
    				if (!j) throw new TypeError(
    					'Reduce of empty array with no initial value'
    				);
    				if (j == 1) return this[0];
    				v = this[i];
    				i++;
    			}
    			while (i < j) v = c(v, this[i], i++, this);
    			return v;
    		},
    
    		reduceRight : function(c, v) {
    			_.throwNonType(c, 'function');
    			var i = this.length;
    			if (typeof v == 'undefined') {
    				if (!i) throw new TypeError(
    					'Reduce of empty array with no initial value'
    				);
    				if (i == 1) return this[0];
    				v = this[--i];
    			}
    			while (i > 0) v = c(v, this[--i], i, this);
    			return v;
    		},
    Seems about right. Have to test it heavily.

    It's funny, I complained about the old MDN polyfills not being converted to JS enough from their C origins... their new ones are better but are so ridiculously over-commented they're nearly impossible to follow the logic of. I mean when you need six lines of comments before "if (k in O) {" you're probably doing something wrong... like typecasting an array to object when you're just going to access it as an array... when inherently to even call the function it must in fact be of type Array.

    Always annoys the hell out of me when you see mental midgetry like this in a codebase:

    Code:
        // 8. Repeat, while k < len
        while (k < len) {
    Big goof in lastIndexOf too.
    Last edited by deathshadow; 02-18-2017 at 08:56 PM.
    I would rather have questions that can't be answered, than answers that can't be questioned.
    http://www.cutcodedown.com

  7. #22
    Regular Coder
    Join Date
    Apr 2011
    Posts
    163
    Thanks
    0
    Thanked 51 Times in 49 Posts
    Those reduce functions seem to work fine. I'll have a more thorough look at them tomorrow.

    The alert logging throws an error at me
    Firefox: TypeError: 'alert' called on an object that does not implement interface Window
    Vivaldi: Uncaught TypeError: Illegal invocation.

    Code:
    var myAlert = window.alert; // direct reference to the window object
    myAlert('wtf');
    This works because myAlert has the 'window' environment bound to it.
    
    msglog = { myAlert : _w.alert} // the msglog object creates a new (environment/object scope/reference to 'this')
    msglog.myAlert('wtf')
    This doesn't because myAlert has the 'msglog' environment bound to it.
    I agree those polyfills on MDN are commented like they are part of a tutorial. Also adding a polyfill reduce and many other methods using Object.defineProperty is just plain ridiculous.
    And you're right about the arrow functions in combination with the polyfills, I would only use them when being lazy while testing some code.

    There is another library that uses the underscore. It's a fork of underscore.js called lodash
    Last edited by Goos; 02-18-2017 at 11:23 PM.

  8. #23
    Senior Coder deathshadow's Avatar
    Join Date
    Feb 2016
    Location
    Keene, NH
    Posts
    2,318
    Thanks
    2
    Thanked 334 Times in 324 Posts
    Interestingly it bombs intermittently here -- sometimes assignment from Window.alert works, sometimes it doesn't.... that's a really jacktarded ***nut way of handling scope. I'd question the sanity of whatever dip**** thought JavaScript should work that way, but it's JavaScript so...

    Ok, threw that in a wrapper. I also backlinked here in the changelog to give you credit for the assist. Beta 7... starting to feel like I'll be up to beta 10 before I even have a damned RC now.

    Now for the next demo, which will let me see how badly all these changes have banjaxed formSerialize... and to figure out if I really want to add type="file" support or not.
    Last edited by deathshadow; 02-19-2017 at 08:18 PM.
    I would rather have questions that can't be answered, than answers that can't be questioned.
    http://www.cutcodedown.com


 
Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •