These are chat archives for canjs/canjs

13th
Apr 2017
Szabolcs Schmidt
@sszabolcs
Apr 13 2017 09:58

Hi!

I have a situation where I don't know if I'm facing a bug or not.
I have a can.Model Person with an Address.List type addresses attribute. If I reload the Person with his addresses after someone else deleted an address then the address list does not get shrinked, the deleted item won't be removed unless you specify 'removeAttr: true' on the Person model. As long as you don't set 'removeAttr' to true can-list.js's _updateAttrs() method does not shrink the list in these lines:

} else if (items.length < this.length && remove) {
                    this.splice(items.length);

Is this the expected behavior? I would expect a list to be shrinked when the list is updated with data from the server.
Here is a jsfiddle with which you can play:
jsfiddle
Add some new Addresses and then remove them. You can see that the list is refreshed as expected. Now try to comment out the 'removeAttr: true' line in Person Model. If you remove an Address the list won't be updated.
Thanks a lot!

Brad Momberger
@bmomberger-bitovi
Apr 13 2017 13:41
This is the expected behavior. The default behavior is to merge what the server returns with what exists on the object. I don't know why this is offhand, but I suspect that it's so the server can send minimal updates.
Also I notice that the Legacy tab in CanJS 3's docs is missing can-model completely, but here's the relevant page from 2.3: https://v2.canjs.com/docs/can.Model.removeAttr.html
Szabolcs Schmidt
@sszabolcs
Apr 13 2017 13:50
Thanks for the correct explanation. This kind of merging is acceptable for a model with static properties. It is only a problem for me when I have a list of items on a model and so that list won't be in sync with the server regardless the server sends all the time the full list.
Special thanks for the missing doc link!
Szabolcs Schmidt
@sszabolcs
Apr 13 2017 14:01
Of course I can live with that and will use removeAttr=true.
Christopher Baker
@christopherjbaker
Apr 13 2017 16:31
All the tutorials I've seen using promises use {{#if promise.isPending}} and if {{#if promise.isResolved}}. Why not use if/else? Is there a case where isPending is false and isResolved is also false? If so, what does it mean and how do you catch it?
Kevin Phillips
@phillipskevin
Apr 13 2017 16:31
isRejected, yeah
Christopher Baker
@christopherjbaker
Apr 13 2017 16:37
does canjs use native promises (with a polyfill), or a specific library/
Kevin Phillips
@phillipskevin
Apr 13 2017 16:38
native promises
you need to provide a polyfill if you want to use CanJS in browsers that don’t support them
Steal ships with a promise polyfill
:point_up: that’s all specific to CanJS 3.0
Ranjan Subbiah
@ranjanbuilds
Apr 13 2017 16:43

'this.default_selectors.set('quantity.options', quantityOptions)

Hi, I am trying to set options hash with quantityOptions within a DefineMap. However, doing the above creates the quantity.options property instead. Can I get some help on how to do this properly?

Kevin Phillips
@phillipskevin
Apr 13 2017 16:44
Hey Ranjan
in DefineMap, you can just do this.default_selectors.quantity.options = quantityOptions;
you don’t need to use set
Brad Momberger
@bmomberger-bitovi
Apr 13 2017 16:46
Also Babel has a promise library that overwrites the one from Steal
Ranjan Subbiah
@ranjanbuilds
Apr 13 2017 16:49

Hey Kevin, I wasn't using set initially, but I was getting this error

Potentially unhandled rejection [1] TypeError: objEv.obj.addEventListener is not a function

Kevin Phillips
@phillipskevin
Apr 13 2017 16:50
hmm, not sure why that would happen
if you want to use set, you can pass an object
this.default_selectors.set({
  quantity: {
    options: quantityOptions
  }
})
Ranjan Subbiah
@ranjanbuilds
Apr 13 2017 16:58
thanks Kevin, that worked for me
Kevin Phillips
@phillipskevin
Apr 13 2017 16:58
great
if you want to submit an issue or create a JSBin that shows the addEventListener is not a function issue we can take a look
Ranjan Subbiah
@ranjanbuilds
Apr 13 2017 17:01
Will do