These are chat archives for ractivejs/ractive

17th
Sep 2018
Arnaud Dagnelies
@dagnelies
Sep 17 2018 07:57
I know I'm late, but you might be interested in this demo too: https://dagnelies.github.io/ractive-examples/datatables/datatable.html
(shameless self promotion)
@nhaberl ;)
Norbert Haberl
@nhaberl
Sep 17 2018 11:57
@dagnelies thanks, we've tried this but there are some major things missing like paging that's why we have used datatables.net and in a few minutes we had a decorator that worked for us.
kouts
@kouts
Sep 17 2018 13:34
Is there any way to know if an instance (not component) is rendered on an element except element.__ractive_instances__[0]
I'm playing with a different concept of "dynamic view" that a dynamic view is simply an instance instead of a component. This makes life a lot easier, it also seems that Ractive is smart enough to teardown the previous instance if a new instance gets rendered in the same element!
So I can have something like this:
kouts
@kouts
Sep 17 2018 13:39
<body>
    <div id="top_menu"></div> <!-- Ractive instance -->
    <div id="main_container"></div> <!-- Also an Ractive instance that gets overwritten in each view change --> 
</body>
Chris Reeves
@evs-chris
Sep 17 2018 14:16
you could check the context on the element and compare it to the context on the parent element
if there is no possibly of a parent instance, simply getting the content would be enough to let you know there's already an instance there
kouts
@kouts
Sep 17 2018 14:27
Let's say I want to check if <div id="main_container"></div> is an Ractive instance
what I do now is document.querySelector('#main_container').__ractive_instances__[0]
Joseph
@fskreuz
Sep 17 2018 14:29
There's a method for that https://ractive.js.org/api/#ractivegetcontext . If it's part of a Ractive instance, it would return a context object which should have a reference to that instance context.ractive.
Before that method existed, I think Ractive also deposits a property (iirc, _ractive. I could be remembering it wrong.) on the element. If it's a part of an instance, it would have that property.
kouts
@kouts
Sep 17 2018 14:51
Unless I'm doing something wrong Ractive.getContext(document.querySelector('#main_container')) gives me undefined
same for body which is the parent element
Chris Reeves
@evs-chris
Sep 17 2018 14:53
the undefined means there's no instance there
kouts
@kouts
Sep 17 2018 14:53
anyway not much of importance but I wonder how Ractive internally understands that there is an instance on #main_container that when a new instance is to get initialized in the same element the previous one gets destroyed (torn down) first
Chris Reeves
@evs-chris
Sep 17 2018 14:54
it uses the ractive_instances array internally
heh
kouts
@kouts
Sep 17 2018 14:54
:smile:
Chris Reeves
@evs-chris
Sep 17 2018 14:55
markdown got me
kouts
@kouts
Sep 17 2018 14:55
Ok so that's not going to go anywhere anytime soon right?
I mean, it's pretty safe to use it
Chris Reeves
@evs-chris
Sep 17 2018 14:57
yes
kouts
@kouts
Sep 17 2018 14:57
:thumbsup:
thanks guys
Chris Reeves
@evs-chris
Sep 17 2018 14:58
to clarify the getContext a little more now that I've got a keyboard, Ractive.getContext('#main_container') will return undefined if there's not an instance there or a context if there is an instance there
kouts
@kouts
Sep 17 2018 14:59
I'm getting undefined
all the time
let me recheck
Chris Reeves
@evs-chris
Sep 17 2018 14:59
even with an instance there?
that seems like a bug
kouts
@kouts
Sep 17 2018 14:59
yes
yeap
I'm pretty sure now
Chris Reeves
@evs-chris
Sep 17 2018 15:02
kouts
@kouts
Sep 17 2018 15:08
Here is an example --- edited
Chris Reeves
@evs-chris
Sep 17 2018 15:11
that's getting a context for both calls, right?
ohhhh
you want document.getElementById without the # in the string
getContext uses document.querySelector if the arg passed isn't already a node
gets me all the time
kouts
@kouts
Sep 17 2018 15:19
You are right @evs-chris it works
I wonder whats happening in my code :smile: