PDA

View Full Version : [OPEN] Can't use function from singleton in viewModel formulas



nclemeur
14 Jun 2017, 3:43 PM
If I have a singleton MySingleton with the function myFunction, I can't use that function in a viewmodel formula. I get the error: Framework Error: Error in formula {myFormula}: MySingleton is not defined even though I have added the singleton class to the requires (I have also tried using the full class name in the formula instead of the alternate class name, but that result in the same problem)



Ext.define('MyApp.view.MyWindowViewModel', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.mywindow',

requires: [
'Ext.app.bind.Formula',
'MySingleton'
],

formulas: {
myFormula: function(get) {
return MySingleton.myFuntion();
}
}
});



Ext.define('MyApp.view.MySingleton', {
extend: 'Ext.Base',

alternateClassName: [
'MySingleton'
],
singleton: true,

myField: 'Hello',

myFunction: function() {
return "hello";
}

});

petr.vecera
15 Jun 2017, 7:20 AM
And is your code valid ExtJS? Does the same run correctly when you preview your app?

nclemeur
15 Jun 2017, 3:24 PM
Yes, of course it is working in preview and production build. Please find attached an example project that illustrate the problem

56448

petr.vecera
16 Jun 2017, 12:39 AM
Thank you for the project. I've logged the request in the system. But I am afraid the fix won't be out very soon. The SA design view is not full fledged APP and not all the code there is executed. SA mimics some actions of the apps. So if it didn't work before, fixing of this could be problematic.

nclemeur
16 Jun 2017, 3:10 AM
Thank you for the project. I've logged the request in the system. But I am afraid the fix won't be out very soon. The SA design view is not full fledged APP and not all the code there is executed. SA mimics some actions of the apps. So if it didn't work before, fixing of this could be problematic.

Maybe it would be good enough to not show the error? Something a little bit more advanced could be to provide an Architect only property for the formula in which we could provide a default return value (only used by SA.) This is a think similar to the idea of mock data in stores. Ideally anything that is not evaluated by the designer could be configured that way (ie with a SA only property). I think this idea could also be extended to properties that use binding, but I am digressing here...