polymer icon indicating copy to clipboard operation
polymer copied to clipboard

_notifySplice adds an attribute named 'splices' to arrays

Open david-saslawsky opened this issue 10 years ago • 4 comments

The following code

    Polymer({
        is: 'x-qwe',

        properties: {
            data: {
                type: Array,
                value: function() {
                    return [];
                }
            }
        },

        attached: function() {
            this.splice('data', 1, 0, { name: 'TEST' });
            console.log(JSON.stringify(this.data.splices));
        }
    });

returns {"keySplices":null,"indexSplices":null}

Looks like the bug is in this.set(path + '.splices', change):

      set: function(path, value, root) {
        var prop = root || this;
        var parts = this._getPathParts(path);
        var array;
        var last = parts[parts.length-1];
        if (parts.length > 1) {
          for (var i=0; i<parts.length-1; i++) {
            var part = parts[i];
            prop = prop[part];
            if (array && (parseInt(part) == part)) {
              parts[i] = Polymer.Collection.get(array).getKey(prop);
            }
            if (!prop) {
              return;
            }
            array = Array.isArray(prop) ? prop : null;
          }
          if (array && (parseInt(last) == last)) {
            var coll = Polymer.Collection.get(array);
            var old = prop[last];
            var key = coll.getKey(old);
            parts[i] = key;
            coll.setItem(key, value);
          }
          prop[last] = value; // <<< HERE
          if (!root) {
            this.notifyPath(parts.join('.'), value);
          }
        } else {
          prop[path] = value;
        }
      },

david-saslawsky avatar Aug 23 '15 10:08 david-saslawsky

I'm observing something similar when changing an array via:

this.push('array', item);

When observing array.splices I get a change record with correct base and path properties, but keySplices and arraySplices are null.

Polymer is up to date. Any help is appreciated.

flauschtrud avatar Oct 29 '15 22:10 flauschtrud

+1

mercmobily avatar Dec 28 '15 03:12 mercmobily

Looks like this was fixed in https://github.com/Polymer/polymer/pull/3439, and i can no longer repro in in v1.latest:

https://jsbin.com/voritiduse/1/edit?html,output

chen-ye avatar Oct 23 '19 22:10 chen-ye

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 23 '20 01:10 stale[bot]