These are chat archives for canjs/canjs

19th
Feb 2016
Justin Meyer
@justinbmeyer
Feb 19 2016 01:15
@chasenlehara .splice
btw, trying to brainstorm about a <content select> replacement: canjs/canjs#2278
.unshift
Chasen Le Hara
@chasenlehara
Feb 19 2016 01:17
@justinbmeyer I ended up following my original idea: in init, this.bind(‘length’, this.dupeFunc)and dupeFunc has logic to remove duplicates.
Justin Meyer
@justinbmeyer
Feb 19 2016 01:18
I would listen to .add and .remove instead
and use a side map
to be "fast" about it
that way inserts and removals are O(1) instead of O(n)
Chasen Le Hara
@chasenlehara
Feb 19 2016 01:19
I wasn’t seeing add being fired in my case, but I’ll check again.
Justin Meyer
@justinbmeyer
Feb 19 2016 01:19
by a "side map", I mean maintain a hash map of objects
Chasen Le Hara
@chasenlehara
Feb 19 2016 01:20
Yeah, gotcha
Justin Meyer
@justinbmeyer
Feb 19 2016 01:20
so you can quickly tell if an item is already in the list or not
is your list a list of primitives, can.Maps, or POJOs, or a mix?
Chasen Le Hara
@chasenlehara
Feb 19 2016 01:21
can.Maps
Justin Meyer
@justinbmeyer
Feb 19 2016 01:22
if your browser supports Map you can use that as the hashMap
otherwise, you'll want an object keyed by your can.Map instances' can.cid(mapInstance)
the only problem with this ... is that you'll have an add followed by a remove event
vs overwriting .push, .unshift, .splice
Chasen Le Hara
@chasenlehara
Feb 19 2016 01:24
I don’t think I could use the cid because that’s not what makes the objects unique, it’s their data.
So I think I could keep a “side set” that has the unique values I need to check for.
Justin Meyer
@justinbmeyer
Feb 19 2016 01:24
oh, you are saying if you had two different map instances that had the same data ... those shouldn't go in the list?
var mapA = new can.Map({a: "b"})
var list = new SpecialList();
list.push(mapA, new can.Map({a: "b"}) )
list.length // -> 1
I was assuming you'd want
list.push(mapA, mapA )
list.length //-> 1
Chasen Le Hara
@chasenlehara
Feb 19 2016 01:27
The former is right; if another map instance is added that’s logically equivalent, I need to remove it (or prevent it from being added).
Justin Meyer
@justinbmeyer
Feb 19 2016 01:28
tricker ... so you store a JSON.stringify(SORT_KEYS(map.serialize()))
Chasen Le Hara
@chasenlehara
Feb 19 2016 01:28
Essentially; right now I’m defining a new prop that is a string of the props I care about.
Justin Meyer
@justinbmeyer
Feb 19 2016 01:29
I'd probably go with overwriting all the mutators ... kinda sucks, but you avoid double events
a plugin for hooking into when an item is removed or added to a list would be really nice :-)
Chasen Le Hara
@chasenlehara
Feb 19 2016 01:34
Yup, that would be great