forcedotcom/aura

dynamically enumerate a component's attributes

Jeff17Robbins opened this issue · 5 comments

It would be very helpful to have a JavaScript API to enumerate the <aura-attribute>s on a component. For example, this would allow code to call addValueHandler() on each attribute, without needing to hard-code the names of the attributes.

This requested feature would help move the Aura component to parity with the standard HTML Element, which has an attributes property.

Given that attributes are, in effect, the public parameters of a component, this API call would presumably be compatible with the security and encapsulation goals of LockerService. But even if this API were not applicable cross-component, it still would be useful internally in a component's implementation so that its JavaScript code could "know" what its declarative markup was doing.

I saw this code in inputRichTextRenderer.js

		var attributes = cmp.getDef().getAttributeDefs();
		attributes.each(function (attributeDef) {
			var name = attributeDef.getDescriptor().getName();

Are getDef() and getAttributeDefs() part of the public JavaScript API?

We're planning to expose that another way. Hopefully next release we can get that done so you can start using it without breakages.

That's great news, thank you!

@KrisGraySFDC , possibly unrelated, yet still on the theme of "introspection": a component reference seems restricted to these properties:

addHandler
addValueHandler
addValueProvider
destroy
get
getEvent
getGlobalId
getLocalId
isInstanceOf
isRendered
isValid
set

I was wondering why getType isn't on this list? For example, say I'm looking for all the aura:text componentswithin my component, oughtn't I have some way to query within my component, enumerate all the child components, and inquire what each components's type is?

Or is there some other way to find all my aura:text components?