canjs / can-connect

Model layer utilities for every JavaScript framework! Assemble real-time, high performance, restful data connections.
https://canjs.com/doc/can-connect.html
MIT License
29 stars 16 forks source link

weak-reference-set does not support multiple entries #468

Closed RyanMilligan closed 5 years ago

RyanMilligan commented 5 years ago

How often can you reproduce it?

Description: WeakReferenceSet's _getIndex function only ever looks at the first item in the set.

Steps to reproduce:

  1. Run the following code:
    
    var set = new WeakReferenceSet();
    var item1 = {};
    var item2 = {};
    var item3 = {};

set.addReference(item1); set.addReference(item2); set.addReference(item3);


<!-- Describe what you expected to have happen after completing the steps above. -->

__Expected results:__ Both items are in the set, so both lines should output `true`.

<!-- Describe what actually happened after completing the steps above. -->

__Actual results:__ The output is:

true false


The issue is that [_getIndex](https://github.com/canjs/can-connect/blob/3d1c0347a8e64a9c687e511ff9a303fdbf90fa38/helpers/weak-reference-set.js#L58) never returns true from the callback it passes to `every`, so only the first item is returned. I tried adding `return true;` after the if statement in my local copy and that solved the problem.