These are chat archives for canjs/canjs

15th
May 2018
Chasen Le Hara
@chasenlehara
May 15 2018 16:56
@nriesco Meant to follow up with you yesterday… in your case, what’s changing the class of the elements?
Instead of changing the class directly, I would keep that state in your view-model so you can have the show class added/removed in your template.
Nico R.
@nriesco
May 15 2018 23:11
thanks @chasenlehara the problem is that I’m trying to use an external library and the library easily adds a class when you scroll the browser’s screen, so it looked simpler. I had other issues though that made me impossible to try other options but that’s another story.
So I guess the answer is to bind the library to the code
but that would take a lot of time in this case because of the other bug
Anyway, as several javascript libraries (I mean browser libraries) add and remove classes to elements it would be great to subscribe to those changes
so if a certain say div element gets a new class it will trigger a change in an observable in canjs
Chasen Le Hara
@chasenlehara
May 15 2018 23:42
@nriesco Hm, so if the library doesn’t give you any hooks into when they show/hide things…
Maybe MutationObserver would be a good fit? You can listen for changes to DOM nodes and do whatever you want with that.
Here’s a quick example of the class on an element changing outside CanJS, and how a component’s VM could be updated in response to that: https://jsbin.com/pumuzuyifi/2/edit?js,output
Maybe there’s a better solution, that’s the first one that springs to my mind though.
Nico R.
@nriesco
May 15 2018 23:46
sounds reasonable. I’m always looking for ways to connect canjs with other components and this might be a good choice for a lot of them
one last question… about connectedCallback
I changed it to myName
and still works
so it’s just a name?
Chasen Le Hara
@chasenlehara
May 15 2018 23:49
Changed what to myName?
Nico R.
@nriesco
May 15 2018 23:49
your jsbin had a property name connectedCallback
Chasen Le Hara
@chasenlehara
May 15 2018 23:50
Oh, it should definitely not work if you change that method name :D
let me double check
Chasen Le Hara
@chasenlehara
May 15 2018 23:50
It might not have saved
Chasen Le Hara
@chasenlehara
May 15 2018 23:52
So in yours, the highlighting is still happening but the text isn’t flipping back and forth between Highlighted / Not highlighted
Nico R.
@nriesco
May 15 2018 23:52
Oh I see, my bad...
it’s like those brain teaser exercises where the word red is written in blue color and you have to say it out loud
thanks again @chasenlehara
Chasen Le Hara
@chasenlehara
May 15 2018 23:54
Haha yup!