qmlweb
qmlweb copied to clipboard
Enums visibility
Now, enums are either visible in the global scope (global.TextInput = {…}
) or at element scope (this.Text = {…}
).
They should be instead visible on the whole evaluation scope, but not registered on global
.
just a thought: Is it an option to use string values instead of enums. then we dont need to pollute the global namespace, makes it easier to debug (no need to look up what the integer value means), and no confusion with the 0-valued enum item and thruthy comparison i.e. if (!enumValue)
...
(not right now though)
I'm not in QMLWeb, but having used Android SDK, I caution against using strings. using a proper enum or class is better because then you can add type safety. For a more nuanced discussion, see https://stijndewitt.com/2014/01/26/enums-in-javascript/ But I would recommend using var x = EnumType.Value because that is most source compatible with using objects or proper classes.
No, enums shouldn't be strings, they have specific integer values in QML and one could compare enums to integers.
cc3cbeacca4871a2177fba967ee6921bfd1ee4f8 adds support for declarative enums definition with the same effect as the most used one for now (i.e. adding the enums inside the component context for that element).
But the good thing is that it allows us to describe enums as
registerQmlType({
module: 'Module',
name: 'Example',
versions: /.*/,
baseClass: 'QtQml.Item',
enums: {
MyEnum: { Foo: -1, Bar: 0, Test: 10 }
},
…
});
We could use that later to propertly import enums when the module gets loaded.