1

I have a component like tweetEnyo, created with enyo script. And based on its kind, i want to perform some action.

Is there a way to find the kind of a component created in enyo at runtime?

sufyan.shoaib
  • 1,117
  • 9
  • 19

2 Answers2

3

You should be able to access the kind property at runtime. Here's an example detecting the kinds of items selected:

http://jsfiddle.net/RoySutton/frTFK/

If you need to find it using the debugger, you can use the ID with the global enyo object's $ hash. e.g.:

enyo.$.app_myKind.kind

Not to steal the thunder from an upcoming blog post, but in the Chrome/Firefox web inspector, $0 is the last inspected element. So, enyo.$[$0.id].kind is the kind of the inspected item.

I did note that App had no kind associated with it in my example. Usure why that is.

Update: App was not declared with a specific kind and will fall back to the default kind for the parent, in this case Control. You can access that value with .defaultKind. Additionally you can specify kind using actual references to the kind (e.g. kind: enyo.Button), so .kind can't be relied on.

The correct way to get the name is to use .kindName, which will be the actual kind.

Pre101
  • 2,370
  • 16
  • 23
  • Yup, inSender.kind does give me the kind of the component. Though "enyo.$.app_myKind.kind" seems not working, see [this](http://jsfiddle.net/frTFK/1/) – sufyan.shoaib Apr 24 '13 at 13:56
  • As I mentioned, the App instance doesn't seem to have a kind but if I change that to app_button it works fine in that fiddle. – Pre101 Apr 25 '13 at 01:23
  • Got your point. I still wonder why there isnt any way to just know the kind of component by just a simple method like ... someComp.getKind(). – sufyan.shoaib Apr 25 '13 at 10:12
  • In the cases where kind is null, you can also check ``.defaultKind`` to get the kind that was used. – Pre101 Apr 25 '13 at 13:19
  • OK, I finally just went and read the source in Oop.js. You can use ``.kindName`` which works in all circumstances. – Pre101 Apr 25 '13 at 13:37
0

From enyo website:

The base enyo.Control works much like an HTML tag. You can assign classes and attributes and give it a style. E.g.

new enyo.Control({content: "Hello From Enyo", classes: "foo",
    style: "color: red", attributes: {tabIndex: 0}}).renderInto(document.body);

So you could do:

new enyo.Control({content: "Hello From Enyo", classes: "foo",
                  style: "color: red", attributes: {tabIndex: 0, enyo:true}}).renderInto(document.body);

Which sets an attr for enyo to true and check for that. Anything that has that is enyo component.

Example: http://jsfiddle.net/NKTRe/

Lemex
  • 3,772
  • 14
  • 53
  • 87
  • Thanks for the reply LmC. Well that will tell me that its a enyo component but it wont tell me what kind of component is it, in this case its 'Control' kind. – sufyan.shoaib Apr 24 '13 at 10:50
  • 1
    Well rather than writing true? Do something like enyo:componenttype? If you follow me? – Lemex Apr 24 '13 at 10:56
  • thats a good work around, but there will be so many components from other sources that we all be using, and it will be cumbersome to add that attribute in each to know there kind. There must be some default method to know its kind. I found some where, they were trying something like... someComponentObj['kind'] .. But it doesnt work in my case. Although, someComponentObj['name'] does return its name correctly. – sufyan.shoaib Apr 24 '13 at 11:02
  • Fair point, May i asked why you require to know what it is? My understanding is you shouldnt care what it is as thats enyos job you should only care about whats rendered? – Lemex Apr 24 '13 at 11:04
  • actually i have a keyboard kind of enyo component which detects internally if one of its property kind is Input then it writes keyboard pressed character to input, otherwise if its console, then it writes the character into console. fyi, its gts.keyboard component – sufyan.shoaib Apr 24 '13 at 11:06
  • Hmm the only other thing is detect what has been focused on. If its of kind input or editable then write to it else write to console – Lemex Apr 24 '13 at 11:08
  • "If its of kind input or editable" :) sounds like i need to detect its kind ? .. i changed the keyboard script to assume only input kind. again thats a work around.. will wait to see if i find any other suggestions.. – sufyan.shoaib Apr 24 '13 at 11:24
  • No sorry i mean is something like: http://stackoverflow.com/questions/5108337/jquery-determine-if-input-element-is-textbox-or-select-list – Lemex Apr 24 '13 at 11:30