Class outline of unnamed Dojo declare classes in Worklight - ibm-mobilefirst

I use the Worklight IDE to get some nice features such as the Dojo class outline in the outline view that works very nice!
Except: The class outline only works with a named class like:
declare("Myclassname", [ MySuperClass ],
{
...
}
and this shows a nice outline of the Myclassname class.
However, the new Dojo guidelines mention not to use named classes anymore as they pollute the global namespace and the parser now also automatically loads the used modules.
This means the outline cannot be used anymore as it doesn't show the class outline anymore then.
Any ideas on this topic?

var Myclassname = declare([ MySuperClass ],
{
...
}
if you are in a require return the Myclassname

Related

How to iterate Apache velocity template variable attributes

As title, is there any way to iterate or display Apache velocity template attributes?
for example, I have following code :
<code>
${ctx.messages.headerMessage}
</code>
And I want to know how many other attributes the variable ${ctx} has
It's only possible to discover and to loop on an object properties (that is, the ones with getters and/or setters) if you can add a new tool to your Velocity context. If you can't, you're rather stuck.
There are several ways to do this, I illustrate below how to do this with commons-beanutils.
First, add Apache commons-beanutils in your class path, and add it to your Velocity context from Java:
import org.apache.commons.beanutils.PropertyUtils;
...
context.put("beans", new PropertyUtils());
...
One remark: if you do not have access to the Java part, but if by chance commons-beanutils is already in the classpath, there is one hakish way of having access to it: #set($beans = $foo.class.forName('org.apache.commons.beanutils.PropertyUtils').newInstance()).
Then, let's say that I have the following object:
class Foo
{
public boolean isSomething() { return true; }
public String getName() { return "Nestor"; }
}
which is present in my context under $foo. Using your newly $beans properties introspector, you can do:
#set ($properties = $beans.getPropertyDescriptors($foo.class))
#foreach ($property in $properties)
$property.name ($property.propertyType) = $property.readMethod.invoke($foo)
#end
This will produce:
bar (boolean) = true
class (class java.lang.Class) = class Foo
name (class java.lang.String) = Robert
(you'll need to filter out the class property, of course)
One last remark, though. Templates are for coding the View layer of an MVC application, and doing such a generic introspection of objects in them is rather inadequate in the view layer. You're far better of moving all this introspection code on the Java side.

How to extend classes and controllers in PrestaShop 1.7?

I want to extend some core classes and controllers via a module but I don't know how. I can do it with overrides but according to the developers this isn't a good way:
The legacy architecture can still be overridden, though. But in
general, we advise against overriding code. It is better to extend it.
But how can I extend it? Is there any code example?
Best regards
In prestashop docs you can see the override.
Put ur class in /modules/my_module/override/classes
or controller /modules/my_module/override/controllers/{front or admin}
I use it on my modules.
An example of my module, overriding a frontcontroller function:
<?php
class FrontController extends FrontControllerCore
{
protected function smartyOutputContent($content)
{
if (version_compare(_PS_VERSION_, '1.7', '<')) {
//do something
} else {
parent::smartyOutputContent($content);
}
}
}

Disambiguating namespaces in generated XAML code

I have a Page that imports controls from a library like this:
<Page
x:Class="Foo.Bar.SomePage"
xmlns:myNamespace="using:Bar.Controls">
<myNamespace:SomeControl x:Name="someControl">
<!-- snip -->
</myNamespace:SomeControl>
</Page>
As you can see here, the page is declared in the ::Foo::Bar namespace, while SomeControl is declared in the ::Bar namespace. The problem I face is that Visual Studio generates this code:
namespace Bar {
namespace Controls {
ref class SomeControl;
}
}
namespace Foo
{
namespace Bar
{
partial ref class SomePage : /* ... */
{
/* ... */
private: Bar::SomeControl^ someControl;
};
}
}
The field definition Bar::SomeControl^ someControl tries to select ::Foo::Bar::SomeControl instead of ::Bar::SomeControl because Visual Studio doesn't fully-qualify it.
Is this by design (is there a way to phrase the using: URI in such a way that it will fully-qualify the name), or is this a bug? How can I work around that?
I think that I could convince people to make an exception to the namespace structure for this specific class, but it would be much simpler if there was an in-code solution for this.
For posterity, right now I'm using this kludge before #including the g.h file, but it's not super pretty:
namespace Foo
{
namespace Bar
{
typedef ::Bar::SomeControl SomeControl;
}
}
It introduces the control into the (incorrect) namespace so that it works even though the XAML code generator gets it wrong.

Referencing a custom WinRT component breaks javascript class?

I have a javascript Windows Store application that I'm working on, and I needed to create a WinRT component for some processing. As soon as I add the reference to that component, I get a javascript error:
0x800a01bd - Javascript runtime error: Object doesn't support this action.
This occurs on a line w/ the following:
engine = new MyApp.Engine();
Which is defined:
WinJS.Namespace.define("MyApp", {
Engine: WinJS.Class.define(function() {
//constructor stuff
//other stuff snipped for brevity
}
});
I'm not even accessing any code in my custom component, simply adding the reference causes it to break. Anyone run into this? Googling/Binging has been no help.
I found the answer.
So in my Javascript code, I had the declaration for a namespace.
In my WinRT C# component, I was using the same namespace. That namespace apparently stomps out my JS namespace declartion. I changed my WinRT component from this:
namespace MyApp
{
public sealed class SomeClass
{
}
}
to:
namespace MyAppUtils
{
public sealed class SomeClass
{
}
}
And now everything is good..so, Lesson: If you're using JS and a custom WinRT component, you (apparently) can't use the same namespace in both.

Design Mode Preprocessor Directive Workaround

I know that there is no DESIGN, DESIGN_MODE, DESIGN_TIME, etc preprocessor directive value. However, I need something that can do the trick. I can't use a normal If statement, because in my case I need to change the inherited class so that the control renders properly at design time. If not, I'll receive an exception due to the fact that the inherited class is an abstract class.
Here's what I'm looking to accomplish:
Partial Class MyCustomControl
#If DesignMode Then
Inherits UserControl
#Else
Inherits WidgetControl
#End If
Any suggestions?
Try using:
if (this.DesignMode == true)
{ }
else
{ }
In the past I have created a dummy class as a go between. Sometimes VS will still figure out what you are doing and get upset, but normally restarting the IDE will solve that.
Partial Class MyCustomControl : MyAbstractClass_FAKE_IMPL
{
//your normal class
}
and
Partial Class MyAbstractClass_FAKE_IMPL : MyAbstractClass
{
//let IDE autogenerate implementation code that you are always going to override in reality.
}