These are chat archives for ractivejs/ractive

6th
Mar 2018
Chris Reeves
@evs-chris
Mar 06 2018 01:05
I just pushed some pretty big internal changes to edge, so anyone that plays with edge a lot, please keep an eye out and let me know if I broke anything the test suite doesn't have covered.
For the curious, shuffling now makes an effort to detach as few chunks of DOM as is possible rather than pulling out everything, plopping it in a docfrag in the correct order, and re-attaching the docfrag.
Index, key, keypath, and rootpath models, along with @ceremcem's newly added last model, are tracked strictly in the template rather than in the model, so that we can introduce {{#each someComputed as item, 'idProp' as shuffle}}...{{/each}}. That will allow computeds and expressions to shuffle implicitly, as if the appropriate splice operations were made.
Cerem Cem ASLAN
@ceremcem
Mar 06 2018 02:33
:tada:
...but I didn't exactly get what to expect from {{#each ... part
Chris Reeves
@evs-chris
Mar 06 2018 03:01
that part isn't done yet, just the groundwork for it
it will allow computed lists to be shuffled
see #3097 as the most recent example of where it would help
also would handle #2947
Joe Turner
@JoeTurner-IR
Mar 06 2018 19:39
is there a way to unobserve?
so I can have teardown: function() { this.unobserve('keypath'); }
kouts
@kouts
Mar 06 2018 19:40
you can store the observer in a variable and call cancel
var handle = this.observe(...);
handle.cancel();
Joe Turner
@JoeTurner-IR
Mar 06 2018 19:43
it works, but doesn't look that pretty
because the variable has to be stored outside of the object
but so long as it works :P
kouts
@kouts
Mar 06 2018 19:44
do you want to stop observing from within the observer?
Paul Maly
@PaulMaly_twitter
Mar 06 2018 19:44
Do it oninit
Also we have observeOnce()
Joe Turner
@JoeTurner-IR
Mar 06 2018 19:45
var observer = null; var r = new Ractive({'onrender': function{ observer = this.observe('sdf'); }, 'onteardown': function() { observer.cancel() });
Paul Maly
@PaulMaly_twitter
Mar 06 2018 19:46
Nope
oninit: function() { var observer = this.observe(); this.on(‘teardown’, () => observer.cancel()); }
sorry, mobile
Joe Turner
@JoeTurner-IR
Mar 06 2018 19:49
I see
I was using a nice on: { init: (), render: (), teardown() } structure for all my components
but I might make an exception
although the way I suggested does work
kouts
@kouts
Mar 06 2018 19:55
If you register an observer oninit like this:
oninit: function(){
    this.observe('something', function (newValue, oldValue, keypath){
       ...
    });
});
I think it gets canceled automatically on teardown
so no need to cancel it manually
Paul Maly
@PaulMaly_twitter
Mar 06 2018 19:59
I don’t know anything about it
kouts
@kouts
Mar 06 2018 20:01
you can also use the observe: { ... } attribute on the instance
any observers defined there will unsubscribe during teardown
Chris Reeves
@evs-chris
Mar 06 2018 20:48
observers are indeed implicitly torn down with their instance, however, if you do something like oninit() { this.parent.observe('key', () => ); } it will carry on observing until the parent is also torn down
Joseph
@fskreuz
Mar 06 2018 21:00
A rule of thumb I follow is if it ain't Ractive, you clean it up. :grin: (i.e. setting up jQuery plugins inside components, building network connections, subscriptions to external event systems, running timers etc.)
Joe Turner
@JoeTurner-IR
Mar 06 2018 21:01
well it wasn't being torn down when defined in the render event
Chris Reeves
@evs-chris
Mar 06 2018 21:07
that's really odd, as the model stops notifying deps about changes after it is torn down
unless we're talking about < 0.8?
Joe Turner
@JoeTurner-IR
Mar 06 2018 21:39
0.9.13
there's a chance that it's another instance of the component firing it
let me investigate
Joe Turner
@JoeTurner-IR
Mar 06 2018 22:43
yea was multiple instances and a rather complicated setup causing the problem
Ractive is guilt-free :p
Juan C. Andreu
@andreujuanc
Mar 06 2018 23:32
Must invite :beer: then xD