Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

before and after callbacks #31

Open
teejayhh opened this issue Jul 12, 2015 · 7 comments
Open

before and after callbacks #31

teejayhh opened this issue Jul 12, 2015 · 7 comments

Comments

@teejayhh
Copy link

First of all I really like meteorhacks libs and I wanted to give flowrouter/ flowlayout a shot. So I played around with it a little bit and tried to implement transitions between route changes. As far as I can see there is no code which gets called just after a template has been added to the dom or just before it gets removed from the dom.

It is possible to use -> http://dvcs.w3.org/hg/domcore/raw-file/tip/Overview.html#mutation-observers and bind event listeners to templates. Those dom events should be bound to the regions. I am just brainstorming here and would like your opinion if this could be a good solution without touching the layout component at all. Or if it would be better to implement callbacks which delay the reset or on after insert?

Cheers Thomas

@arunoda
Copy link
Contributor

arunoda commented Jul 12, 2015

I'm quite not sure about this.
But we have triggers in the router: https://github.com/meteorhacks/flow-router#triggers

@teejayhh
Copy link
Author

let me try this out tonight, but I figured you take so much care separating the concerns so that this sort of thing made sense to be with the layout rather than the router.

@teejayhh
Copy link
Author

The situation is a little bit tricky. Lets say you would like to transition from one page to another with a content slide - left to right or right to left for instance you would need 2 templates rendered at the same time on route click. The current page/slide sits on screen and the next slide sits offscreen. Once you change the route the two templates would change places with an animation. I can only see this working if you use two or more different regions.

You also need some sort of config one each route to keep track in which state it is. You could set up a rule which says that only one region is visible at a time and always the non visible region will be used for the next content population.

Here is a quick prototype to illustrate what I would like to do.

FlowRouter.route('/', {
    name:'login'
    ,subscriptions: function(params, queryParams) {
    }
    ,action: function(params) {
        FlowLayout.render("loginLayout",{'main1':'login'});
    }
    ,triggersExit: [function(context, redirect) {
        TweenMax.fromTo($("#main1"),1,{autoAlpha:1,y:0},{autoAlpha:0,y:50});
        console.log('exit login');
    }]
    ,triggersEnter: [function(context, redirect) {
        TweenMax.fromTo($("#main1"),1,{autoAlpha:0,y:50},{delay:0.5,autoAlpha:1,y:0});
        console.log('enter login');
    }]
});

FlowRouter.route('/register', {
    name:'register'
    ,subscriptions: function(params, queryParams) {
    }
    ,action: function(params) {
        FlowLayout.render("loginLayout",{main2:'register'});
    }
    ,triggersEnter: [function(context, redirect) {
        TweenMax.fromTo($("#main2"),1,{autoAlpha:0,y:50},{delay:0.5,autoAlpha:1,y:0});
        console.log('enter register');
    }]
    ,triggersExit: [function(context, redirect) {
        TweenMax.fromTo($("#main2"),1,{autoAlpha:1,y:0},{autoAlpha:0,y:50});
        console.log('exit register');
    }]
});

This is all super static and will probably fall apart as soon as subscription come into play.

@joefru
Copy link

joefru commented Jul 17, 2015

Could you use Template.myTemplate.onCreated and/or .onRendered to achieve this?

@ryanbuiltthat
Copy link

@teejayhh did you ever get your transitions working?

@jiku
Copy link

jiku commented Sep 30, 2015

Maybe a callback after onCreated, onRendered, etc? For anything that needs to be done on routing after those events. For me, I sometimes add event listeners last in onRendered that I want to emit to on routing.

@danieldietrich
Copy link

I used this workaround as after-callback (in the specific case of rendering a template in the flow-router): arillo/meteor-flow-router-helpers#23 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants