Bug with : supersonic.ui.views.find()?


#1

What is the expected behavior when there is absolutely no view ever created with the ID passed into this API? I’m finding that the promise is always successful. i was putting an API I called ‘getStartedView’ which would first try to ‘find’ the view, and then if it did not exist, i would create the few, start it and return it.

What I find is that i can pass any string like 'this_does_not_exist" and this find() api will tell me it found a view like
{id: 'this_does_not_exist’
location: ‘this_does_not_exist’
}

This is not what I would expect from an API called ‘find’, I would expect to fail to find the view and reject the defer/promise not actually go and create a new view and assume that the location is the same as the ID (which would rarely ever be the case)

What am I missing here?


#2

Thought I’d add the code snipped that shows the behavior:

var viewId = “someViewThatDoesNotExist”;
supersonic.ui.views.find(viewId).then( function(startedView) {
supersonic.logger.log("found a view with location: " + startedView.getLocation());
}, function (error) {
//error never gets called anyway so no need for code here
})

// OUTPUT :

[Log] supersonic.logger.info: found a view with location: some_stupid_viewname (cordova.js, line 4966)


#3

Any update here? Is this API works-as-designed? Is ‘find()’ supposed to create and start a view automatically when it can’t be found? I just want to know if this is WAD…


#4

Can someone gimme some quick feedback here? just asking for the proper function of the API not anything more.


#5

Any news on this? This is a very confusing behavior, as it doesn’t find preloaded view either… at least I can’t tell if they are preloaded


#6

Yes the name and the behavior of the .find() is very confusing.

But in documentation they wrote: “Get a new view instance by a view identifier.” (
http://docs.appgyver.com/supersonic/api-reference/stable/supersonic/ui/views/find/)
So .find() visibly return systematically a view with arg ID as location and ID if the view previously not exists.

Ok it’s totally unintuitive. :slight_smile:

As workaround you can test if the view has the expected location (and not the ID as location) :

foundView.getLocation()

Or if she is started (depending your logic) :

foundView.isStarted().then(...)

But the problem is that the found view was created by supersonic.ui.views.find() and remain in memory. So you have to detroy it manually:

supersonic.ui.views.stop(view).then(...)

Anyone at appgyver can confirm?


#7

I run into the same problem. All I want is to be able to find out if the view has been started, if so, push the started view on top. If the view is not found, it should start the view before pushing.

Thanks to Damien. The following is what works for me:

    supersonic.ui.views.find("myView")
    .then(function(foundView){
       	foundView.isStarted().then(
       		function(started) {
           		if (started) {
           			supersonic.ui.layers.push(foundView);
           		}
           		else {
  				var newView = new supersonic.ui.View(
      					{
					  location: "main#myView",
					  id: "myView"
       					});
  				newView.start().then(function(){
  					supersonic.ui.layers.push(newView);	
  				})
           		};
            	});
  	});