life

The life plugin tracks a spirits lifecycle. Oftentimes a spirit would use it to retrieve the lifecycle status of another spirit.

var otherspirit = gui.get('#thatspirit');
console.log(otherspirit.life.attached); // true

Lifecycle flags

The lifecycle status of a spirit is reflected in a set of boolean properties. These are all readonly, or at least they should be.

constructed
Spirit is constructed? This is almost certainly true by the time you address the spirit.
configured
Spirit is configured? If true, the spirits (other) plugins are ready to be used.
entered
The spirit is now or has ever been positioned in the DOM?
attached
The spirit is currently positioned in the DOM? Note that this is initially false until the spirit has been discovered by the framework. It is also false whenever detached is true.
detached
The spirit is currently not positioned in the DOM? Note that this is initially true until the spirit has been discovered by the framework. It is also true whenever attached is false.
ready
The method onready has been called on the spirit? If true, this implies that all descendant spirits are also ready.
async
The spirit has entered the phase of it's life that happens roughly 4 milliseconds after ready?
destructed
The spirit is destructed? If true, don't try anything funny. The spirits properties and (other) plugins may not even exist.

Perhaps refactor something to allow undefined as a third state for these booleans?

Lifecycle listeners

You can add like an event listener to get notified whenever a spirit transitions into a new lifecycle phase. This is particularly useful for plugins, as they would otherwise need to rewrite the spirits methods.

onconstruct: function() {
	this.super.onconstruct();
	this.spirit.life.add(gui.LIFE_ATTACH);
}
onlife: function(l) {
	if(l.type === gui.LIFE_ATTACH) {
		this.spirit.dom.parent().className = "container";
	}
}

The callback method recieves a gui.Life object with two properties type and target where the target is always a spirit. Note that this is a "non-bubbling" type of event, so you need to get a hold of the spirit in order to listen for it. We recomment you add listeners using this list of constants.

  • gui.LIFE_CONSTRUCT
  • gui.LIFE_CONFIGURE
  • gui.LIFE_ENTER
  • gui.LIFE_ATTACH
  • gui.LIFE_READY
  • gui.LIFE_DETACH
  • gui.LIFE_ASYNC
  • gui.LIFE_DESTRUCT

The constants map down to strings, but we can reduce the risk of typos by using the constants instead of the strings. That's because the plugin has been rigged to explode on undefined.

Custom events

You can make up new lifecycle events as you go along.

this.life.copypasted = true;
this.life.dispatch('copypasted');