These are chat archives for ractivejs/ractive

20th
Dec 2017
kouts
@kouts
Dec 20 2017 14:06
Quick question: Is it possible to call a function from a component that is not yet rendered? I'm trying to register beforeEnter methods on View components that will get invoked before the component gets rendered.
Chris Reeves
@evs-chris
Dec 20 2017 14:16
If it has been instantiated, yes. You can still do data and events things with instances before they render.
kouts
@kouts
Dec 20 2017 14:22
So how do I instantiate the component without it being rendered :smile: ?
Chris Reeves
@evs-chris
Dec 20 2017 14:24
Two ways: have a containing instance that also isn't rendered or using an anchor so that you get to manage the lifecycle rather than ractive.
Sounds like an anchor is probably what you'll need
actually, if you're just about to enter the route as the component renders, you can use the init or config event because the component will be rendering in the same tick
so you could have a *.init listener on the root instance for that
kouts
@kouts
Dec 20 2017 14:40
anchors are not working for me for some reason, Ι'm using the dynamic component paradigm for route Views so I'll just try a render guard something like
{{#if component_show}} <component /> {{/if}}
let's see
if that works
kouts
@kouts
Dec 20 2017 14:59
is there any way to defer render inside the onconfig or oninit lifecycle events?
Chris Reeves
@evs-chris
Dec 20 2017 15:20
no, the render will happen no matter what
kouts
@kouts
Dec 20 2017 15:20
hmm ok nice to know though
Chris Reeves
@evs-chris
Dec 20 2017 15:21
an anchor it a macro partial will give you full control over rendering from the api side
or*
kouts
@kouts
Dec 20 2017 15:22
I tried anchors but maybe the way I have setup the app is not suitable
They seem to render the component without data
Chris Reeves
@evs-chris
Dec 20 2017 15:23
are you using mappings?
kouts
@kouts
Dec 20 2017 15:23
I also tried linking the data with Ractive.link but this doesn't work either
Chris Reeves
@evs-chris
Dec 20 2017 15:23
that's odd, because that should definitely work
kouts
@kouts
Dec 20 2017 15:24
I'll try to make a fiddle or something but currently I'm short of time so I'll have to go with what I have now
thanks for your help @evs-chris