These are chat archives for canjs/canjs

22nd
Feb 2016
Mason Shin
@minsooshin
Feb 22 2016 20:02
when I leave a page, the component still remember the last state of viewModel?
for example, I have { a: 1, b: 2} and change that to { a: 4, b:2 }
and leave the page, and come back later
Mohamed Cherif Bouchelaghem
@cherifGsoul
Feb 22 2016 20:03
@minsooshin do you the AppViewModel?
Mason Shin
@minsooshin
Feb 22 2016 20:03
component viewModel
Mohamed Cherif Bouchelaghem
@cherifGsoul
Feb 22 2016 20:03
when the components is removed even it's viewModel should be removed too
Mason Shin
@minsooshin
Feb 22 2016 20:03
okay
that’s what I expected...
then, I have an issue on my process in somewhere :)
Mohamed Cherif Bouchelaghem
@cherifGsoul
Feb 22 2016 20:04
for shared states put them in appViewModel
Mason Shin
@minsooshin
Feb 22 2016 20:04
I am getting last state of viewModel when I come back to the page.
got it
thanks @cherifGsoul
Mohamed Cherif Bouchelaghem
@cherifGsoul
Feb 22 2016 20:05
Welcome
last state??
dylanrtt
@dylanrtt
Feb 22 2016 20:09
@minsooshin that usually has to do with the way you define the prototype. For example, if you define foo: new can.Map(), then foo will be shared by all instances. The solution for that example would be to use foo: {} or variations of the define plugin
Mason Shin
@minsooshin
Feb 22 2016 20:10
@cherifGsoul for example
viewModel: {
  a: 1,
  b: 2
}
and I have changed the a to 4
and I left the page, then the component will be removed from the page
Mohamed Cherif Bouchelaghem
@cherifGsoul
Feb 22 2016 20:11
weired behavior
Mason Shin
@minsooshin
Feb 22 2016 20:11
when I come back to the page, I expect a is 1, not 4
but I am getting 4
dylanrtt
@dylanrtt
Feb 22 2016 20:12
@minsooshin is the viewmodel's _cid changing between instances?
Mason Shin
@minsooshin
Feb 22 2016 20:12
for workaround, I set this
events: {
  removed: function() {
    this.viewModel.attr(‘a’, 1);
  }
}
let me check @dylanrtt
if it is not changed, that means the component has last state of data, right?
dylanrtt
@dylanrtt
Feb 22 2016 20:13
yes the same reference
Mason Shin
@minsooshin
Feb 22 2016 20:15
it has been changed…it should be different reference
will investigate more
dylanrtt
@dylanrtt
Feb 22 2016 20:15
in your example, a and b are primitive values, but in your app are they something else?
Mason Shin
@minsooshin
Feb 22 2016 20:16
actually, I am changing string value, and I am passing that data to another component as a param
timeframe: ‘two-weeks’ this is initial property
and user can change this value from the dropdown menu
setTimeframe: function(context, timeframe) {
  context.attr('timeframe', timeframe);
}
with this ($click)=“setTimeframe(.., ‘one-month’)” on the stache
now I got it
component _cid is changed
but the property’s _cid is not changed
dylanrtt
@dylanrtt
Feb 22 2016 20:22
so the property is a map? how are you defining it?
Mason Shin
@minsooshin
Feb 22 2016 20:25
I defined with new can.List([…])
var a = new can.List([]);
can.Map.extend({
  a: a,
  b: function() {
   …
  }
});
dylanrtt
@dylanrtt
Feb 22 2016 20:26
ah yes, that would share the same list between all instances of the viewmodel. One solution is to define it as simply myList: [] and new can.List() will be called on it automatically, or you can use the define plugin's "value" or "Value"
Mason Shin
@minsooshin
Feb 22 2016 20:27
got it
resolved
thanks @dylanrtt