qmlweb icon indicating copy to clipboard operation
qmlweb copied to clipboard

Enums visibility

Open ChALkeR opened this issue 8 years ago • 4 comments

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.

ChALkeR avatar May 09 '16 07:05 ChALkeR

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)

henrikrudstrom avatar May 09 '16 08:05 henrikrudstrom

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.

jhihn avatar Jun 07 '16 15:06 jhihn

No, enums shouldn't be strings, they have specific integer values in QML and one could compare enums to integers.

ChALkeR avatar Jun 08 '16 21:06 ChALkeR

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.

ChALkeR avatar Jun 10 '16 21:06 ChALkeR