Closure call with mismatched arguments: function 'call' again - callback

Exactly one month ago I encountered this problem Closure call with mismatched arguments: function 'call' with js interop.
Now I have the same problem with the SnapSVG library. I'm using it in combination with JsInterop since a moment. Today i tried to use the mouseover function and I get the same exception.
But when I hover the SVG element my function is fired four times :
hover in
hover in
hover in
hover in
Breaking on exception: Closure call with mismatched arguments: function 'call'
I tried :
var img = s.image("$url", x, y, image.width/2, image.height/2);
js.FunctionProxy hover = new js.FunctionProxy(() {
print("hover in");
});
img.mouseover(hover);
and
var img = s.image("$url", x, y, image.width/2, image.height/2);
img.mouseover(() {
print("hover in");
});
This time I checked twice and there is no extra arguments for the callback function.

Considering the logs you paste, the mouseover handler seems to be called sometimes with parameters sometimes without. To handle that you can use a function with optional parameters :
var img = s.image("$url", x, y, image.width/2, image.height/2);
img.mouseover(([p1, p2, p3, p4]) {
print("hover in");
});
The above callback now handles calls with from 0 to 4 parameters.

Related

Opa5: cannot read property "iLookAtTheScreen" of undefined

So I'm writing my first test in Opa5 and I get this error, when I call the iLookAtTheScreen function to a page. I have a Worklist test to a page and a WorklistJourney which calls the test functions.
WorklistJourney:
QUnit.module("TabBar");
opaTest("Should see all the toolbar buttons", function (Given, When, Then) {
// Arrangements
Given.iStartMyApp();
//Actions
When.onTheWorklistPage.iLookAtTheScreen();
// Assertions
Then.onTheWorklistPage.theTabBarShouldHaveAllTheButtons().
and.iTeardownMyAppFrame();
});
}
Here when I call the iLookAtTheScreen() function it says that onTheWorklistPage is undefined. I do have an onTheWorklistPage segment in the Worklist.js file. I have no idea what's the problem.

Click on Leaflet map closes modal, click on marker opens modal

My Leaflet map has markers that open modals.
When a user clicks on the map, however, I would like for the modal to close. But the bit of code that makes that happen (below) interacts with the marker, and forces it to close as soon as it opens:
map.on('click', function(e) {
$('.modal').modal('hide'); });
I did get this to work—see the JSFiddle here: https://jsfiddle.net/askebos/Lh1y12uq/
But as you can see, the only reason it seems to be working is because it creates the following error:
Uncaught TypeError: e.preventDefault is not a function.
I imagine it's because the map.on('click'...) function is prevented from executing.
Any thoughts on how I can get to the same behaviour without the error?
The solution is to add an init() function that keeps track when a marker is clicked. Inspiration came from this question.
First, add the init() function to your code:
function init() {
init.called = true;
}
Then call the function when the marker is clicked:
function markerOnClick(e) {
init();
...
}
Make a function that fires when the map is clicked, but include an if/else statement that checks whether init.called has been set to true. If this is the case, reset init.called. If it has not been set to true, then the map was clicked elsewhere and any modals may close.
function mapClick () {
if(init.called) {
init.called = false;
}
else{
$('.modal').modal('hide');
}
}
Finally, bind the mapClick function to map clicks.
map.on('click', mapClick);
The function will no longer override marker clicks, and the error has been resolved as well. That still doesn't tell me why e.preventDefault caused an error, so any explanations would be welcome!
A working JSFiddle can be found here: https://jsfiddle.net/askebos/oesh59jr/

sap.m.TileContainer scrollIntoView issue

I have an XML view that contains a TileContainer which is bound to a model that is used to create StandardTiles. The XML snippet is:
<TileContainer id="tilelist" tiles="{Applications}">
<tiles>
<StandardTile name="{ID}" icon="{Icon}" title="{Name}" press="doNavigation" info="{Description}"
number="{path : 'Number', formatter: 'linxas.com.fiori.launchpad.util.Formatter.formatUsingURL'}"
numberUnit="{NumberUnit}"/>
</tiles>
</TileContainer>
This is working perfectly, the correct tiles are getting displayed etc. When I click on a tile, there is navigation that occurs and I want to "remember" which tile was clicked (by index) so when returning I can scroll to that tile. This is done on the tile's press event handler (doNavigation function) and stores the index in sessionStorage. This is also working properly.
doNavigation : function (evt) {
if (sessionStorage && this.getView().byId('tilelist')) {
sessionStorage.setItem("selected_tile", this.getView().byId('tilelist').indexOfTile(evt.getSource()));
}
...
}
The proper value is stored. So when navigating back, within the onAfterRendering function of the page that contains the TileContainer I have the following code. It is attempting to see if there is a "selected_tile" value stored in sessionStorage, if so it calls scollIntoView passing in the tile index. The issue is that this code is executed, but doesn't work and I suspect it is because at the time of calling this function, the TileContainer's tiles aggregation is returning 0 length.
onAfterRendering : function (evt) {
var theList = this.getView().byId("tilelist");
if (sessionStorage && theList) {
var tile_index = sessionStorage.getItem("selected_tile");
console.log(tile_index + " of " + theList.getTiles().length);
if (tile_index) {
theList.scrollIntoView(+tile_index, true);
sessionStorage.removeItem("selected_tile");
}
}
}
My console output looks something like this (based on the tile that was clicked):
5 of 0
Any help would be appreciated. I assume that there is somewhere else that I need to execute this last bit of code as the TileContainer does not seem to be finished processing its tiles at this point, at least that is my assumption of why the tiles aggregation is 0.
Are you using Routing in your project?
If yes, you can try to register a method to handle the routePatternMatched event of the router. This method will be called after the onAfterRendering method - if the proper route pattern is matched.
To achieve this, just create the following:
onInit: function() {
sap.ui.core.UIComponent.getRouterFor(this).getRoute("NameOfYourCurrentRoute").attachPatternMatched(this._routePatternMatched, this);
},
_routePatternMatched: function(oEvent) {
//do your stuff here
},
Hopefully the TileList is ready at this point to navigate to the correct tile.

Closure call with mismatched arguments: function 'call'

I'm using the (2.0)js-interop library in combination with the JS library ImageLoaded and I'm stuck the FunctionProxy class because the code below throw the following error:
Breaking on exception: Closure call with mismatched arguments: function 'call'
js.FunctionProxy loaded = new js.FunctionProxy((){
print("called");
js.Proxy pckry = new js.Proxy(context.Packery, container, options);
});
js.Proxy img = new js.Proxy(context.imagesLoaded, container, loaded);
Which is weird because my js callback is called 5 times before the app crashes.
Looking at the Usage section of imagesLoaded it looks like the callback takes one parameter. So you have to add this parameter to your callback :
js.FunctionProxy loaded = new js.FunctionProxy((instance) {
print("called");
js.Proxy pckry = new js.Proxy(context.Packery, container, options);
});
js.Proxy img = new js.Proxy(context.imagesLoaded, container, loaded);
Additional notes :
You can avoid new js.FunctionProxy. There are only a limited number of cases where it's needed and your case here is not one of them.
imagesLoaded can be use as a function and it simplifies the code.
Thus, you should be able to use :
final img = context.imagesLoaded(container, (instance) {
print("called");
js.Proxy pckry = new js.Proxy(context.Packery, container, options);
});

what is the argument we get in callback of UIcontrol push button in Matlab

I am showing lot of buttons on image using pushbutton with UIcontrol.(around 20)
How to handle callback with single function(which has similar behaviour and i just have to change id for each button,i dont want to write 20 callback for each.)
S = uicontrol('style','push',...
'units','pix',...
'position',Pos,...
'string',Button_name,...
'fontsize',10,...
'fontweight','bold');
set(S,'callback',{#pb1_call}) % Set the callbacks.
end
function [] = pb1_call(varargin)
disp(varargin)
end
The Matlab documentation describes this reasonably well, look at uicontrol properties.
function pushbutton1_Callback(hObject,eventdata)
display Goodbye
close(gcbf)
The callback fires with the firing object and event data. If you set a Tag onto the uicontrol you could do:
function pushbutton1_Callback(hObject,eventdata)
buttonID = get(hObject, 'Tag');
switch buttonID
case 'button1'
...
end
Also worth noting, if the callback is a method of a handle class then there are three arguments:
function pushbutton1_Callback(self, hObject, eventdata)
You can set the callback function to an anonymous function, which will allow you to pass additional information to the callback
set(S,'callback',{#(u,v)pb1_call(u,v,buttonID}) % Set the callbacks.
Then your callback function will have the signature
function pb1_call(hObject,eventdata,buttonID)