xposted from gitter, I figured this would be a more appropriate place to discuss…
Hi guys, I’ve got a side project I’ve dabbled with in the past and would like to try integrating more tightly with Canjs. Its using Openlayers - a sort of observable mapping library. It has these observable list-like objects called collections, and I’m having issues getting it to work with canjs templates for of, each, etc.
I just copied the entire topic from gitter, I didn’t get any responses yet so that’s why its so short.
Specifically, what’s not working is using for of on an object that is an ol.collection type. This specific type has a getArray method which returns an array of the objects. It also has a .length property and dispatches events like change:length. It also has some of the array-like methods like, push, pop.
<!-- my code does this, but updates are not reflected -->
{{#for(layer of map.layergroup.layers)}}<li>{{layer.title}}</li>{{/for}}
To try and work with this, I’ve implemented the can.value symbol and can.onValue…but neither seem to be working. I’ll look into using can-diff patcher directly.
If you are implementing observability yourself, you might checkout can-key-tree or https://canjs.com/doc/can-event-queue/map/map.html which will add a lot of the methods you need … you just need to dispatch like observable[canSymbol.for("can.dispatch")]("prop",[2,1]);
Okay. I updated that example with a much simpler sample. I’ve also implemented on/off patches, but neither of them are actually getting called right now…
Okay, I made some progress. I have it (mostly) working, I had to add a length getter. I feel like this is oddly specific though, not every “list-like” observable has a length property. Shouldn’t canjs be using the can.size symbol to look this up?