Avatar for PaddeK

PaddeK

Member since Mar 2017 • Last active Jul 2018
  • 2 conversations
  • 105 comments

Most recent activity

  • in News
    Avatar for PaddeK

    Here is a semi complete map poly of a older project of mine.

    'use strict';
    
    class Map
    {
        constructor (keyVal)
        {
            this.clear();
    
            if (Array.isArray(keyVal)) {
                keyVal.forEach(kv => this._keys.push(kv[0]) && this._values.push(kv[1]));
            }
        }
    
        get size ()
        {
            return this._keys.length;
        }
    
        has (key)
        {
            return this._keys.includes(key);
        }
    
        get (key)
        {
            return this._values[this._keys.indexOf(key)];
        }
    
        set (key, value)
        {
            let i = this._keys.indexOf(key);
    
            if (i !== -1) {
                this._values[i] = value;
            } else {
                this._keys.push(key);
                this._values.push(value);
            }
        }
    
        delete (key)
        {
            let i = this._keys.indexOf(key);
    
            if (i === -1) {
                return false;
            }
    
            this._keys.splice(i, 1);
            this._values.splice(i, 1);
        }
    
        keys ()
        {
            return this._keys;
        }
    
        values ()
        {
            return this._values;
        }
    
        clear ()
        {
            this._keys = [];
            this._values = [];
        }
    
        entries ()
        {
            return this._iterator();
        }
    
        _iterator ()
        {
            let i = 0;
    
            return {
                next: () => i < this._keys.length ? {value: [this._keys[i], this._values[i++]], done: false} : {done: true}
            };
        }
    
        forEach (callback, scope = null)
        {
            this._keys.forEach(key => callback.call(scope, this.get(key), key, this));
        }
    }
    

    Amazingly close to what @Gordon already had :D

  • in News
    Avatar for PaddeK

    Well sorry.. its a quick hack. Its a function to run promise chains in sequence with optional mapper functions for the resolves. And the resulting resolve returns the changed map (key: original promise, value: resolve result of that promise) so you can reference results by promises you did feed the function.

    I guess it doesnt help that code with 120 chars per line (pretty common standard) is getting wrapped in posts here.

    --- Little warning ---
    The code has bugs.. it was a first draft of something i needed at work the next day.. so dont use it for production :D

  • in News
    Avatar for PaddeK

    I guess you are right @Gordon in terms of performance impact. But RAM is still an issue i guess because its very precious :)

    I have a sweet little example for the Map vs. Object point @opichals made before.
    Should be self-explanatory.

    'use strict';
    
    let sequence = (...map) => (ok, nok) => {
            map = new Map(map.map(e => Array.isArray(e) ? e : [e]));
            ok(Array.from(map.keys()).reduce((all, prm) => {
                return all.then(res => prm.then(data => res.set(prm, (map.get(prm) || (() => data))(data))).catch(nok));
            }, Promise.resolve(map)));
        };
    
    let add = num => num + 1;
    let mul = num => num * 2;
    let addPromise = num => Promise.resolve(num);
    let mulPromise = num => Promise.resolve(num);
    
    let adding = addPromise(10);
    let multing = mulPromise(20);
    
    let map = [adding,[multing, mul]];
    
    new Promise(sequence(...map)).then(result => {
        console.log('result', {addResult: result.get(adding), mulResult: result.get(multing)});
    }).catch(console.log.bind(null, 'error'));
    
  • in News
    Avatar for PaddeK

    There should be polyfills for them.. but i guess they are always not optimal memory and/or speed wise

  • in Pico / Wifi / Original Espruino
    Avatar for PaddeK

    This would be my guess too, since its hardware related. Maybe you could add some layer on top of it, like you mentioned with polling, but i imagine this would come at a hefty price speedwise.

  • in Pico / Wifi / Original Espruino
    Avatar for PaddeK

    My understanding was PA.1 and PA.2 is fine but not PA.1 and PB.1 . Thats how i understand the 2. Note in the setWatch reference.

  • in News
    Avatar for PaddeK

    So many things to play with and so little time.
    Thanks for all the improvements!

  • in News
    Avatar for PaddeK

    Great thanks! I am so exited about this.. i am used to ES6 and it allows for so much cleaner and shorter code :)

  • in News
    Avatar for PaddeK

    I miss destructuring and rest + spread in the list. Or are they implemented already and i missed it?

    Thanks for giving the community this much influence it is really appreciated!

  • Avatar for PaddeK

    Just as a update, Particle is in a presale for their nrf52840 based boards.
    Expected shipping starts in July 2018.
    Another interesting thing is the formfactor.. they hop on to the adafruit feather train.. this could be a good choice for the next espruino generation too.

Actions