Make Router methods return promises and resolve when page is navigated to

If Router.push() and Router.goto() and Router.goBack() returned promises after being called and resolved after page shown, I could run some code in the same js scope not having to pass data to the receiving page when I want to do something on the sending page:

var somePageIsVisible = false;

Router.push('somePage').then(function() {
 // do stuff once shown
 somePageIsVisible = true;
});

Compare to having to do something like:

Sending Page:

var somePageIsVisible = require('isSomePageVisible');

function showSomePage() {
  Router.push('somePage', {pageVisible: true});
}

// later on check if somePage is active:
if(somePageIsVisible.value) {
    // do stuff
  }

Receiving Page:

var somePageIsVisible = require('isSomePageVisible');

var pageVisible = this.Parameter.map(function(data) {
  somePageIsVisible.value = data.pageVisible;
  return data.pageVisible;
});

Meant to put in feature request oops

I’m trying to create a smaller version of my usecase, app is too big, so will bump this later

This is a planned feature, though I can’t provide an expected release date yet.

Awesome for some reason I had a hard time making a small testcase, but glad you guys agree without the testcase, right now I’m using setTimeout to determine when the page is active.

I’ve done a lot of work on navigation transitions recently and am no longer certain this interface is correct solution. It’s not clear when the then part should be executed, as there are multiple legitimate points where it makes sense:

  • once the page is prepared (but prior to nav)
  • once the navigiation animation is done
  • once the page is active and has no busy tasks active

The first and last of these now have numerous ways to configure them as well. Thus having a single .then interface could be problematic.

What is the high-level use-case that is to be solved? Let’s look from the angle to find the correct solution.

Then let’s not make it return a promise, how about an EventEmmiter or something, something where you can detect all those events, perhaps with an on method? Not sure how the API could look though, if you have ideas let me know.

Just throwing it out there (its late here):

var route = Router.push('somePage');
route.on('somethingHappened').then(callback);

or

Router.push('somePage')
  .onSomething(callback) // returns `this`
  .onSomethingElse(callback) // returns `this`

When I say return this I mean returns the same object that Router.push is returning so it can call other methods on. But try to figure out how to fit promises in, as callbacks are very limiting, and annoying.

All of these states are (or will be soon) detectable in UX via events. I’m looking for the use-case that prevents using that mechanism and requires it be done in a .then fashion in JavaScript.

That is, what are you doing when the next page is activated?

I haven’t touched any Fuse code in a while, I’ve been keeping up with the slack team so I’m not far behind, but since I haven’t looked at my codebase in a while, I’ll have to come back to you on that question sorry. But if I can remember correctly by looking at the first post. It was just setting an Observable’s value on the script that the push method was called from once the page was showing.

Imagine there’s like an indicator for which page is active, but instead of doing like a WhileActive or something since that would only work on the Activated page, the Observable knows when the page is active and triggers whatever is subscribed to that Observable.

The activated page can however send events, or even execute JS callbacks. Active page indicators can also be done many different ways.

If you do get the chance to look back at the code, then please let me know what you find out. I’d really like to solve this starting form the highest-level UX expectation.

So that’s the thing “even execute JS callbacks” well that means calling the JS that’s a part of the activated page, but what if for some reason you want to execute some JS in the same script depending on whether a page is activated you’ll only know by executing a function after its triggered, but you want to easily do it without bringing UserEvents to the picture. At least so far I’ve been able to avoid UserEvents. Again I’m sure I can refactor and figure other ways out, from what I remember I was doing something with setTimeout that just made it work, even though I don’t like the solution. Yea right now I don’t want to focus on the app I’m building as I"m working on other stuff so I won’t even try to mess with the code, because I’ve been having other problems with router’s as well that was taking days for me to debug and still haven’t figured out (will get back on it whenever I do)

Okay, please post the high-level use-case if you remember. As you say, there are many ways to accomplish what you needed. The question is which way is the most appropriate way – one of those other ways might be better served with a new feature instead. We’re trying to avoid developing from technical goals only, and focus on the use-cases. It shouldn’t just be capable of doing things, but hopefully make sense in doing them as well. And preferably be close to the “ideal” way of doing it.