These are chat archives for canjs/canjs

13th
Jul 2016
Sarath Nair
@sarathnair
Jul 13 2016 06:11

I have a doubt regarding Can.js list and the 'remove' event it generates

Consider the following piece of code

var hobbies = new can.List(["JS","C++"]);

hobbies.bind('remove',function(ev,hobby, index){
  console.log("Removed " + hobby + " from index " + index);
});

hobbies.attr(["C++"],true);

I am expecting the remove event to tell me that "JS" was removed, but rather it tells me "C++" was removed. Am I missing something here?
JSBin: http://jsbin.com/sowiwinize/edit?html,js,console

Andrei Balmus
@abalmush
Jul 13 2016 07:29
Hello guys, who knows how can I register a stache template from string and use it like so {{>myTemplate}}
should I use can.stache.registerHelper for that?
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jul 13 2016 09:07
Andrei Balmus
@abalmush
Jul 13 2016 09:47
Hi @cherifGsoul, thanks for you answer. I’ve also found that can.view.registerView works the same way, which approach is better in thiat case how do you think?
i can use it like this:
import addressFormFields from './templates/address-form-fields.html!text';
can.view.registerView('addressFormFields', addressFormFields);
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jul 13 2016 09:50
use registerView I think is more secure
Andrei Balmus
@abalmush
Jul 13 2016 09:51
ok great, thank you again Mohamed!
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jul 13 2016 09:51
No problem
Kevin Phillips
@phillipskevin
Jul 13 2016 14:14
@sarathnair what is happening is hobby[0] is changed from “JS” to “C++” and hobby[1] is removed.
you can look at either the set or changed events
var hobbies = new can.List(["JS","C++"]);

hobbies.bind('remove', function(ev,hobby, index){
  console.log("Removed " + hobby + " from index " + index);
});

hobbies.bind('change', function(ev, index, how, newVal, oldVal){
  console.log("Changed " + oldVal + " to " + newVal + " at index " + index);
});

hobbies.attr(["C++"],true);
"Changed JS to C++ at index 0"
"Changed C++ to undefined at index 1"
"Removed C++ from index 1"
Jeremy Miller
@jjm340
Jul 13 2016 17:53
How does one cross bind an event? So I have a a component that has a next() function on it and I want to call that method from outside of the component. Would a reference scope work here?
Thomas Sieverding
@Bajix
Jul 13 2016 17:53
Maybe {next}=“~next”?
Jeremy Miller
@jjm340
Jul 13 2016 17:59
What does the ~ denote?
It should actually be “@next"
{{@key}} - Pass the value at key, even if it's a function or a compute.
Jeremy Miller
@jjm340
Jul 13 2016 23:42
Whoa, very cool, thanks a bunch!