These are chat archives for canjs/canjs

28th
Aug 2018
qantourisc
@qantourisc
Aug 28 2018 09:59
Where to unlisten to event to prevent memory leaks ?
Kevin Phillips
@phillipskevin
Aug 28 2018 13:31
how are you listening to the event, @qantourisc ?
RanjanSubbiah-tc
@RanjanSubbiah-tc
Aug 28 2018 14:20
hey guys, Is it possible to do live-bindings using can-slot? https://canjs.com/doc/can-component/can-slot.html
{{#each ./slides}}

        <can-slot name="nameOfImage" isActiveYes:from="../isActive(scope.index)"/>

        <content />

{{/each}}

<can-template name="nameOfImage">

        <div
            class="slide photosSlide {{#if ./isActiveYes}} active {{/if}}"
            tabindex="{{#if ./isActiveYes}} 0 {{else}} -1 {{/if}}"
        >
               </div>
</can-template>
it's not working when I implement it like above
qantourisc
@qantourisc
Aug 28 2018 14:55
@phillipskevin Mostly binding on defineMaps. The app is leaking, but I am not sure where from :(
Kevin Phillips
@phillipskevin
Aug 28 2018 14:56
how are you doing the binding though?
qantourisc
@qantourisc
Aug 28 2018 14:57
o let me check
I have a few: let compute = can.compute( serialize() ).on("change",func) and a few this.on("field",func); or did you mean something else ?
I also have some "recrusive" bindings, or is there a better way to do it ? I wish to listen to myDefineMapInstance.member.submember. But member might not be defined yet.
Kevin Phillips
@phillipskevin
Aug 28 2018 15:06
so for the first ones, you basically need to call off
each this.on("field",func); should have a matching this.off("field",func);
qantourisc
@qantourisc
Aug 28 2018 15:07
I'd be happy to. I was quite literal in my initial question though: where/when ? I'd be happy to cleanup, but I need some hook for when things "disappear".
Kevin Phillips
@phillipskevin
Aug 28 2018 15:07
when are you setting them up?
qantourisc
@qantourisc
Aug 28 2018 15:07
Mostly if not all can.components, and members of the ViewModel
curse the lack of clear RAII on JS ;)
Kevin Phillips
@phillipskevin
Aug 28 2018 15:08
are you calling it in init?
qantourisc
@qantourisc
Aug 28 2018 15:08
yes
Kevin Phillips
@phillipskevin
Aug 28 2018 15:09
ok, can you do it in inserted instead? (or the connectedCallback in newest versions)
qantourisc
@qantourisc
Aug 28 2018 15:09
Sorry, i feel to green in javascript memory management to provide the answers you seek without so many questions.
I think running them during inserted would be possible yes.
Kevin Phillips
@phillipskevin
Aug 28 2018 15:12
if you can set up the listeners in inserted then you can remove the listeners in beforeremove
also, there are probably better ways to do these things without having to manually setup/teardown event handlers
can-component's events object does this cleanup for you
qantourisc
@qantourisc
Aug 28 2018 15:13
Looks intrestesting, i'm tempted to call ViewModel.my_cleanup() from beforeremove for my convienece though.
Kevin Phillips
@phillipskevin
Aug 28 2018 15:13
or using derived properties in the viewmodel is even better
qantourisc
@qantourisc
Aug 28 2018 15:14
Derived sound nice. he! reminds me of some ugly code I have going.
I have a DefineMap that combines 2 DefineMaps into a new view, with writable properties, but .... I had to manually bind and trigger events in the combining DefineMap.
Ideally it would have been a DefineMap.value function thing, but I couldn't get writes to work to it
Kevin Phillips
@phillipskevin
Aug 28 2018 15:18
that is what the prop.lastSet is for
for handling when the property is set
qantourisc
@qantourisc
Aug 28 2018 15:19
ooo, thanks i'll look into that after doing this other unrelated change !
It works, but it's yet another bind ;)
qantourisc
@qantourisc
Aug 28 2018 15:57
let some_leaf = can.compute(()={
   if (this.a === undefined) return undefined;
   return this.a.b;
});
some_leaf.on("change",()....);
Is there a better way to said above ?
This message was deleted
RanjanSubbiah-tc
@RanjanSubbiah-tc
Aug 28 2018 18:26
@phillipskevin how's it going? can I bug you for some help with the question I posted above ?