Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Julian Gonggrijp
    @jgonggrijp
    @jcwren_twitter Potentially interesting for underscore-like algorithms that work async: async library
    Kevin Partington
    @platinumazure
    @jcwren_twitter Yeah, in that example it does nothing. I can safely say that declaring the parameter and then not using it at all (as is done in that mapLoop example) is... a bit silly. Glad you're in good shape now!
    The correct syntax for no parameter async arrow function is async () => {}
    iscelinetam
    @iscelinetam
    hello
    matteocacciola
    @matteocacciola
    hello, I am building my VueJs based app with webpack. It uses underscorejs too
    I am experiencing this error
    can someone help me, please?
    underscorejs version is 1.10.2
    2020-04-07-145446_1920x1080_scrot.png
    jgonggrijp @jgonggrijp reacted to the issue on github :point_up:
    Cameron Beccario
    @cambecc_twitter
    Hi @jgonggrijp. Thanks so much for the conversion to es module syntax! I've been looking forward to this for a long time, hoping that one day tree shaking could be used on underscore to reduce bundle sizes. I'm giving it a try now and noticed that webpack's ability to remove dead code is somewhat limited due to all the side effects. I have some ideas to make it more tree-shakable and would like to contribute, but I wanted to check first if you had noticed the same and had plans to improve it (or concluded it was impossible).
    Cameron Beccario
    @cambecc
    For example, converting all of the calls to restArguments into statically exported functions.
    Julian Gonggrijp
    @jgonggrijp
    @cambecc Hey glad you appreciate it!
    Yes I'm aware of the limitation in threeshaking. Rollup has the same problem. I think the best solution is to chop the entire library into tiny modules. I'm working on a plan to convince Jeremy that this is the right thing to do.
    Converting the restArguments calls to straight functions works too, but at the expense of increasing code size (or switching to ES6 syntax entirely, but that would require transpilation and probably increase code size even more). Also, it's only a partial solution because there are also lots of functions that really have to be generated from a function call.
    Julian Gonggrijp
    @jgonggrijp
    @cambecc I already have a completely modularized version of Underscore ready to push, so basically just waiting for agreement from Jeremy.
    Cameron Beccario
    @cambecc
    @jgonggrijp That's great to hear! Hopefully that can happen soon. Btw, I'm happy to test it out in the interim.
    Julian Gonggrijp
    @jgonggrijp
    @cambecc That's a very nice offer of you. I prefer to not have it out in the open yet, though. I'll make sure to keep you updated.
    Cameron Beccario
    @cambecc
    👍
    Danny Villa Kalonji
    @Danny-Villa
    Hi! I'd like to know supported browsers since I can't see it anywhere in the doc.
    Julian Gonggrijp
    @jgonggrijp
    @Danny-Villa it's IE8 and anything more standards-compliant.
    Julian Gonggrijp
    @jgonggrijp

    Dependency graph of the upcoming modular Underscore (jashkenas/underscore#2849): https://gist.github.com/jgonggrijp/61e9a00b8807cd41a2ffa73b8ad8cc7a/raw/dfc8879dadc1f0691c84a1f1063971067c344775/modular-underscore-dependencies.png

    Blue balloons are Object functions, Red is Utility, Orange is Function, Purple is Collection, Green is Array. Yellow arrows indicate direct and indirect dependencies on iteratee.

    Julian Gonggrijp
    @jgonggrijp
    The modularization branch was merged! Now I just need to write an article about how to get the most out of it, and then we'll be ready for the release. jashkenas/underscore#2849
    Grigoris Ntousakis
    @GNtousakis
    Hello!! Is anyone online? :))
    Julian Gonggrijp
    @jgonggrijp
    Hi @GNtousakis ! Yes, I am.
    Ario K
    @itsario_twitter
    hello
    anfengchen
    @anfengchen
    hello
    // Internal helper to create a simple lookup structure. // 'collectNonEnumProps' used to depend on '_.contains', but this led to // circular imports. 'emulatedSet' is a one-off solution that only works for // arrays of strings. function emulatedSet(keys) { var hash = {}; for (var l = keys.length, i = 0; i < l; ++i) hash[keys[i]] = true; return { contains: function(key) { return hash[key]; }, push: function(key) { hash[key] = true; return keys.push(key); } }; }
    anfengchen
    @anfengchen
    I think maybe there is something wrong in the native underscore.js function "emulatedSet" ? As hash inherit from Object.prototype, the 'contains' using hash[key] will cause
    problem. I hope someone can explain it. Thank you.
    Julian Gonggrijp
    @jgonggrijp
    @anfengchen I have not noticed any problems with this, but you might be right. Do you have example code that demonstrates a problem with it?
    anfengchen
    @anfengchen
    /********************************************************************************************
     * Native code in underscore.js
     * "emulatedSet" was called in "collectNonEnumProps", which aim to solve the ieEnumBug
     ********************************************************************************************/
    // Internal helper to create a simple lookup structure.
    // `collectNonEnumProps` used to depend on `_.contains`, but this led to
    // circular imports. `emulatedSet` is a one-off solution that only works for
    // arrays of strings.
    function emulatedSet(keys) {
        var hash = {};
        for (var l = keys.length, i = 0; i < l; ++i) hash[keys[i]] = true;
        return {
            contains: function(key) { return hash[key]; },
            push: function(key) {
                hash[key] = true;
                return keys.push(key);
            }
        };
    }
    
    var hasEnumBug = !{ toString: null }.propertyIsEnumerable('toString');
    var nonEnumerableProps = ['valueOf', 'isPrototypeOf', 'toString',
        'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString'
    ];
    
    // Internal helper. Checks `keys` for the presence of keys in IE < 9 that won't
    // be iterated by `for key in ...` and thus missed. Extends `keys` in place if
    // needed.nonEnumerableProps
    function collectNonEnumProps(obj, keys) {
        keys = emulatedSet(keys);
        var nonEnumIdx = nonEnumerableProps.length;
        var constructor = obj.constructor;
        var proto = Object.prototype.toString.call(constructor) == '[Object Function]' &&
            constructor.prototype || Object.prototype;
    
        // Constructor is a special case.
        var prop = 'constructor';
        if (obj.hasOwnProperty(prop) && !keys.contains(prop)) keys.push(prop);
    
        while (nonEnumIdx--) {
            prop = nonEnumerableProps[nonEnumIdx];
            if (prop in obj && obj[prop] !== proto[prop] && !keys.contains(prop)) {
                keys.push(prop);
            }
        }
    }
    
    /*********************************************************************************
     * my test code
     *********************************************************************************/
    var obj = { toString: null, valueOf: 'value' };
    // in IE<9, the keys for obj will be []
    
    var keys = [];
    // keys will be [], but we expert ['toString','valueOf']
    collectNonEnumProps(obj, keys); // keys = []
    @jgonggrijp As I can't install IE8 in my computer, I don't know if my test is right simulation of IEEnumBug.
    Julian Gonggrijp
    @jgonggrijp
    @anfengchen I see what you mean. It could probably be fixed by changing the implementation of contains to return hash[key] === true;. I suspect nobody is trying to use Underscore with IE8 anymore, but please feel welcome to submit a PR and get the credits.
    Julian Gonggrijp
    @jgonggrijp
    I'm in need of people who develop real-world applications (or libraries) with performance-critical sections that depend on Underscore. If you think you fit that description, or you know somebody else who does, please let me know.
    Also, I'm looking for expert Underscore users who could review a PR in which I substantially refactored the library. Who can help me out?
    Julian Gonggrijp
    @jgonggrijp
    Security fix in _.template, please upgrade to underscore@latest or underscore@preview.
    RestartMV
    @RestartMV

    So admittedly I'm coming from a matlab background, but I keep getting irritated when trying to extract values from arrays in JS, and what I keep wanting is something that makes selecting specific array elements at known indexes as easy is it is in matlab.
    For instance:

    Array = [1,2,4,8,16,32,64]

    In matlab you can enter Array([2,3,end]) and get out [2,4,64] as a new array, or Array(1:4) and get out the first four elements, or Array(1:2:end) and get only odd-numbered elements. Similarly, if this were a 2d array, you could grab one row or column at a time by saying Array(1,1:end), or Array(1:end,1).

    It's a useful enough tool that it's a pain whenever I can't just do it directly in js, and I'm sure my workarounds aren't exactly optimal. Is there any chance that this utility belt might include more powerful array referencing in the future (obviously without the matlab quirk of starting index counting at 1)?

    Julian Gonggrijp
    @jgonggrijp
    @RestartMV Nice question. Unfortunately, JS is not so powerful that a library like Underscore could enable new syntax. You can however get close by combining a couple of Underscore functions:
    import { pick, toArray, compose } from 'underscore';
    
    const pickArray = compose(toArray, pick);
    
    const array = [1,2,4,8,16,32,64];
    
    pickArray(array, [1, 2, 6]);
    // [2, 4, 64]
    You can add your own pickArray function to Underscore so you can also use it in chaining:
    import { mixin, chain } from 'underscore';
    
    mixin({pickArray});
    
    chain(array).pickArray([1, 2, 6]).reverse().value();
    // [64, 4, 2]
    Julian Gonggrijp
    @jgonggrijp
    Underscore also has last for retrieving the last element(s) of an array.
    RestartMV
    @RestartMV
    well that's useful anyway
    I guess in theory you could enter the array indicies in as a string but that seems pretty hideous as a workaround and isn't the type of general purpose thing that tons of people would like
    Julian Gonggrijp
    @jgonggrijp
    @RestartMV The initial version of Underscore took inspiration from a couple of other libraries, one of which actually did use string shorthands for all kinds of things. I guess that besides ugliness, it's also rather inefficient because of the additional parsing required, but it's still interesting. https://web.archive.org/web/20081201075555/https://osteele.com/sources/javascript/functional/
    Dylan Reichstadt
    @dylanlive
    Hey All! Just wanted to pop by and say it seems cnn.com/activate isn't loading properly, and I see it's trying to fetch https://underscorejs.org/underscore-min.js and getting a 404. Not sure if that's something controlled by these maintainers
    Seems there's another request failing on that page, so it might not just be that. Anyway, night all!
    Julian Gonggrijp
    @jgonggrijp
    @dylanlive Thanks for the heads-up! It is controlled by the maintainers (and I renamed it to underscore-umd-min.js), but it's not supposed to be used in production. I'll contact CNN about it.
    Dylan Reichstadt
    @dylanlive
    Awesome, thanks! I tried to find their contact form but that was challenging :P
    Julian Gonggrijp
    @jgonggrijp
    @dylanlive I didn't find any such thing, did you? I ended up just sending them a tweet.
    Dylan Reichstadt
    @dylanlive
    Just https://www.cnn.com/feedback - but ironically that seems broken too lol. Though after hitting Submit it does look like a POST request is made. I reached out to them citing your tweet
    Julian Gonggrijp
    @jgonggrijp
    @dylanlive I just released 1.13.1, which puts back the underscore.js alias in git and on the website. That means that cnn.com/activate is un-broken for now, though I find it worrying that they haven't already switched to a CDN url.