These are chat archives for canjs/canjs

5th
Apr 2017
Juan Orozco
@Macrofig
Apr 05 2017 14:43
I'm trying to use can-view-callbacks.attr but I can't get the handler to call when I have the attribute anywhere but at the top of my app. Here's a demo: http://jsbin.com/yufuhek/edit?html,js,console
It calls only if the attr is on the first inserted element but nothing else.
Never mind... my demo is wrong.
Matthew Phillips
@matthewp
Apr 05 2017 14:47
Probably your issue in your app is that you are not importing the attr in your template
attr callbacks are discovered when the template is parsed
Juan Orozco
@Macrofig
Apr 05 2017 14:50
I have it at the top of my index file, just to make sure I didn't run into that.
So, it works perfectly in the demo but I'm using can.stache.from. In my app, I'm using steal-stache.
Everything else is exactly the same.
(Not saying it is steal-stache, just pointing out that is the only difference.)
Matthew Phillips
@matthewp
Apr 05 2017 14:57
are you using <can-import from="path/to/attr"/> ?
wait, where is it not working, in your demo or your app?
Juan Orozco
@Macrofig
Apr 05 2017 14:58
Sorry, it is not working in my app.
Checking on can-import
So, this will trigger the handler:
document.body.appendChild(
  stache('<my-app test-attr />')()
);
(in my app)
But if I use test-attr in the my-app template, the handler will not trigger.
This template is not loaded using can-import
Although some other templates are loaded using can-import
Matthew Phillips
@matthewp
Apr 05 2017 15:00
the attr should be loaded with can-import
add <can-import from="path/to/attr"/> to the top of your template
Juan Orozco
@Macrofig
Apr 05 2017 15:02
oh
okay...
to every template that uses the attr?
Matthew Phillips
@matthewp
Apr 05 2017 15:03
yep
Juan Orozco
@Macrofig
Apr 05 2017 15:03
oh... i guess it isn't registered with stache globally anymore...
Sweet. That worked. Thanks @matthewp
Matthew Phillips
@matthewp
Apr 05 2017 15:07
cool
Juan Orozco
@Macrofig
Apr 05 2017 15:07
Is it me (did I miss some documentation?) or is there some documentation missing for this situation?
Matthew Phillips
@matthewp
Apr 05 2017 15:07
I think the docs can be improved on this point, it's something people run into often
maybe file an issue in can-view-callbacks
Juan Orozco
@Macrofig
Apr 05 2017 15:09
👍🏽
Gerard Finnerty
@halcyonandon
Apr 05 2017 19:05
Hi, is it possible to use a ternary bool toggle in an inline click handler? something like <button ($click)="attr('showInfo', attr('showInfo') ? false : true)">click me</button>
also tried ($click)="attr('showInfo', !attr('showInfo')) and without attr
Gerard Finnerty
@halcyonandon
Apr 05 2017 19:18
ah, so this worked ($click)="^attr('showInfo')" but if i wanted to toggle an attr based on a different attr, I'm still not sure
Juan Orozco
@Macrofig
Apr 05 2017 20:31
Oh man. I totally need this: canjs/can-set#38
Does anyone have an example of how they handled date range with can-set/algebra?
Matthew Phillips
@matthewp
Apr 05 2017 20:45
@halcyonandon we don't support ternary operator yet
something to request, perhaps
Gerard Finnerty
@halcyonandon
Apr 05 2017 20:47
@matthewp thanks
Matthew Phillips
@matthewp
Apr 05 2017 20:48
np :)