Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

template dom-repeat does not iterate over array-like objects #3811

Closed
pmaudsley opened this issue Jul 26, 2016 · 3 comments
Closed

template dom-repeat does not iterate over array-like objects #3811

pmaudsley opened this issue Jul 26, 2016 · 3 comments

Comments

@pmaudsley
Copy link

I know there is an issues regarding repeating over object keys in #1385

However, I am working with array-like objects and these also do not get stamped out either due to the Array.isArray() check.

I'll add a PR which implements a further check on objects passed through dom-repeat has the required properties and methods. (https://www.polymer-project.org/1.0/docs/devguide/properties#array-mutation)

@mattyclarkson
Copy link

To provide more background: We have a web API that we models objects as a sparse array:

{
  "elements": {
    "713": {
      "type": "abc"
    },
    "16": {
      "type": "foo"
    }
  }

These are represented as an array-like Object as so:

console.log(api.elements.length);  // => 2
console.log(api.elements[0]._id);  // => 713
console.log(api.elements[1]._id);  // => 16
api.elements.push({'type': 'foo'});
api.elements[2].loadId().then(console.log);  // => unique id (say, 199)
api.elements.splice(1, 1);  // Removes the object with ID 16 in the API and locally
console.log(api.elements[0]._id);  // => 713
console.log(api.elements[1]._id);  // => 199

For all intents an purposes, api.elements acts like and array. It implements all the functions that a ES2015 array implements and when objects are added/removed does the necessary grunt work to keep the API up-to-date. Representing the API as an array, makes Polymer integration easy as dom-repeat works really well in this situation, except...it doesn't work because it has a Array.isArray check that discards our object and doesn't create a collection from it.

@stale
Copy link

stale bot commented Mar 13, 2020

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 stale bot added the wontfix label Mar 13, 2020
@stale
Copy link

stale bot commented Apr 17, 2022

This issue has been automatically closed after being marked stale. If you're still facing this problem with the above solution, please comment and we'll reopen!

@stale stale bot closed this as completed Apr 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants