-
-
Notifications
You must be signed in to change notification settings - Fork 461
Closed
Labels
Description
Because of how the class Collection
adds the _events
property to use for composition it produces some unexpected behaviors with some array methods like filter
To Reproduce
Steps:
- Create an empty collection:
const collection = new Collection()
- Output
Object.keys(collection)
Expected - An empty collection should have no keys or values
Observed ['_events']
is the output
To Reproduce
Steps:
- Create an empty collection:
const collection = new Collection()
- Output
collection.filter(() => false)
// or true, doesn't matter
Expected - An empty array should be the result
Observed [0, _events: Events]
is the output with filtering using true or false
Here is a small code snipped with the reproduction of the issue.
const emptyCollection = new Collection();
console.log(emptyCollection.length); // output: 0, expected
console.log(Object.keys(emptyCollection)); // output: ['_events'], not expected
const allIncluded = emptyCollection.filter(() => true);
console.log(allIncluded); // output: [0, _events: Events], not expected
const allExcluded = emptyCollection.filter(() => false);
console.log(allExcluded); // output: [0, _events: Events], not expected
Environment (please select one):
- Code executes in browser (e.g: using script tag to load library)
- Packaged software (e.g: ES6 imports, react, angular, vue.js)
- Running headless (usually Node.js)
Notes:
I've seen a few places in the source code where some properties are sat as enumerable: false
.
Would that do the trick to remove _events
as enumerable from collection?
( And ids
from Children
that extends Collection
)
Closing comment:
Thank you so much for building this project! I am playing around with building a collaborative whiteboard and the performance of two.js blows away some of competing products.