These are chat archives for ractivejs/ractive

19th
Jul 2017
Bob Schellink
@sabob
Jul 19 2017 10:27
Ractive splice method returns a promise. But there is also a property called "result" on the promise. which contains the removed item/s. This is useful to me as I want to get the removed item and insert it somewhere else without doing promise.then. Just wondering if this is part of the api or for internal usage?
Chris Reeves
@evs-chris
Jul 19 2017 13:31
It is part of the api
kouts
@kouts
Jul 19 2017 15:51
Is there any way one can monkey patch the unrender method of a component so that something executes before the unrender method, something like an onbeforeunrender event?
Chris Reeves
@evs-chris
Jul 19 2017 16:11
I'll have to check, but I think you can just provide an unrender method at extend time as long as it calls super
Martin Kolárik
@MartinKolarik
Jul 19 2017 16:27
yep that should work for all methods
and there are also events and onunrender method
kouts
@kouts
Jul 19 2017 16:39
@evs-chris I'm not sure how to do this something like
Ractive.components.mycomponent = Ractive.extend({    
    unrender: function(){
        // do something here
        this.super.unrender();
    }
});
Chris Reeves
@evs-chris
Jul 19 2017 16:48
Yes, but Ractive.prototype.unrender.call(this)
It's a bit easier with es6 classes
kouts
@kouts
Jul 19 2017 17:13
thanks that seems to work ok!
kouts
@kouts
Jul 19 2017 20:55
I get a warnign though: Overriding Ractive prototype function 'unrender' without calling the '/\b_super\b/' method can be very dangerous.
Chris Reeves
@evs-chris
Jul 19 2017 21:02
hmmmm...
that should really only apply to on methods, I think
nope, I'm wrong
kouts
@kouts
Jul 19 2017 21:05
Ahhh ok then, anyway this was just some tests - experiments so no worries... :relaxed:
Chris Reeves
@evs-chris
Jul 19 2017 21:07
turns out that ractive does supply a super to overridden internal functions
kouts
@kouts
Jul 19 2017 21:07
so how to use this?
Chris Reeves
@evs-chris
Jul 19 2017 21:07
so you can just this._super() with the args passed through, and all will be well
Ractive.extend({
  unrender() {
    // do whatever
    this._super();
  }
});
Joseph
@fskreuz
Jul 19 2017 21:08
Ractive.components.mycomponent = Ractive.extend({    
    unrender: function(){
        // do something here
        this.super();
    }
});
This probably already does it
ack! beat me to it (and forgot super had a leading underscore)
Chris Reeves
@evs-chris
Jul 19 2017 21:09
other methods have other args that must be passed through to avoid errors
but unrender is pretty simple
:smile:
kouts
@kouts
Jul 19 2017 21:09
Great, I'm gonna try this right away!
Joseph
@fskreuz
Jul 19 2017 21:11
Sometimes I wonder why super should only exist when called. Setup overhead?
Chris Reeves
@evs-chris
Jul 19 2017 21:20
I think it's more that it changes depending on the method being called
so for teardown, you wouldn't want it to point to render
kouts
@kouts
Jul 19 2017 21:43
This works ok
Ractive.components.mycomponent = Ractive.extend({    
    unrender: function(){
        // do something here
        this._super();
    }
});
But for some reason this won't work:
Ractive.components.mycomponent = Ractive.extend({    
    unrender: function(){
        // do something here
        setTimeout(function(){
            this._super();
        }.bind(this), 350);
    }
});
i.e this._super(); inside setTimeout
Chris Reeves
@evs-chris
Jul 19 2017 21:53
_super is only available during function execution
deferring inside the unrender would also effectively be the same as as using the unrender event
everything is synchronous
you could try stashing a reference to this._super and calling it from the timeout, but there're probably some assumptions about what will happen in unrender made by the code that calls it
Chris Reeves
@evs-chris
Jul 19 2017 21:59
what are you trying to do? perhaps there's another way ™