nickfargo/state — pull request #13 by nickfargo (2013-10-19 06:37:21+00:00)
Title: Retained attribute

As discussed in #11
Implements and closes #12

* * *

New declarable `retained` attribute allows ad-hoc construct such as this:
```js
var owner;

state( owner = {}, 'abstract', {
A: ( function () {
var internalState;
return state({

// Redirect an incoming transition to the retained internal state
enter: function ( transition ) { transition.go( internalState ); },

// Remember which internal state was current and retain that reference
exit: function ( transition ) { internalState = transition.origin; },

AA: state({}),
AB: state({})
});
}() ),
B: state
});
```

to be syntactically reduced to this:
```js
state( owner = {}, 'abstract', {
A: state( 'retained', {
AA: state,
AB: state
}),
B: state
});
```

where both cases exhibit:
```js
owner.state('-> AB'); // will be retained
owner.state('-> B'); // exited A; A retains AB as its internal currency
owner.state('-> A'); // traversal to `retained` state A will be redirected
owner.state().name; // >>> State `AB`
```

and the newer form also works across prototypes/protostates.