Encapsulation

Enyo Scoping

Enyo kinds are meant to be self-contained, so that they may be reused in different scenarios. Encapsulation is a major goal shaping the way scoping works in Enyo.

In a kind definition, the list of components determines what is in scope for the kind. In other words, the this.$ hash for a kind contains the collection of components defined in the kind.

Code should not attempt to access components in another object's $ hash. For example, this.$.oneComponent.$.itsChild should be avoided, as it breaks encapsulation by assuming the presence of something (itsChild) that is not in the scope of the current kind.

Communication Between Objects

So how do you allow one object to communicate with another? In one of two ways: by calling methods or sending events.

Picture the UI as a series of controls nested within other controls.

Globals

Globals are bad. There should be virtually no reason to have global variables in Enyo. If you find yourself using lots of globals, most likely you are not honoring encapsulation, and some number of your kinds are defined such that they are limited to one particular usage.