Cosmos.mixins.PersistState = {
  /**
   * Heart of the Cosmos framework. Enables dumping a state object into a
   * Component and exporting the current state.
   *
   * Props:
   *   - state: An object that will be poured inside the initial Component
   *            state as soon as it loads (replacing any default state.)
   */
  generateSnapshot: function() {
    /**
     * Generate a snapshot of the Component props (including current state.)
     * It excludes internal props set by React during run-time and props with
     * default values.
     */
    var defaultProps = this.getDefaultProps ? this.getDefaultProps() : {},
        props = {},
        value,
        state;
    for (var key in this.props) {
      value = this.props[key];
      // Ignore "system" props
      if (key == '__owner__' ||
        // Current state should be used instead of initial one
        key == 'state') {
        continue;
      }
      // No point in embedding default props
      if (defaultProps.hasOwnProperty(key) && defaultProps[key] == value) {
        continue;
      }
      props[key] = value;
    }
    state = _.clone(this.state);
    if (!_.isEmpty(state)) {
      props.state = state;
    }
    return props;
  },
  componentWillMount: function() {
    // Allow passing a serialized snapshot of a state through the props
    if (this.props.state) {
      this.replaceState(this.props.state);
    }
  },
  componentWillReceiveProps: function(nextProps) {
    // A Component can have its configuration replaced at any time
    if (nextProps.state) {
      this.replaceState(nextProps.state);
    }
  }
};

@@ -348,28 +348,37 @@
 t: function(
+recursive
 ) %7B%0A
-
     /**%0A    
@@ -678,24 +678,70 @@
        state
+,%0A        children = %7B%7D,%0A        childrenProps
 ;%0A    for (v
@@ -1241,22 +1241,1642 @@
  state;%0A
-
     %7D%0A
+    if (recursive) %7B%0A      _.each(this.refs, function(instance, ref) %7B%0A        // The child component needs to implement the PeristState mixin to be%0A        // able to serialize its current state%0A        if (typeof(instance.generateSnapshot) == 'function') %7B%0A          children%5Bref%5D = instance.generateSnapshot(true);%0A        %7D else %7B%0A          childrenProps = this.getChildProps(ref);%0A          if (!_.isEmpty(childrenProps)) %7B%0A            children%5Bref%5D = childrenProps;%0A          %7D%0A        %7D%0A      %7D.bind(this));%0A      if (!_.isEmpty(children)) %7B%0A        props.children = children;%0A      %7D%0A    %7D%0A    return props;%0A  %7D,%0A  loadChild: function(ref) %7B%0A    return Cosmos(this.getChildProps(ref));%0A  %7D,%0A  getChildProps: function(ref) %7B%0A    var props = %7B%7D;%0A    // A tree of props can be embeded inside a single (root) Component%0A    // input, trickling down recursively all the way to the tree leaves. Child%0A    // props are set inside the .children prop of the parent Component, as a%0A    // hash with keys corresponding to Component *refs*. These pre-defined%0A    // props will be overriden with those generated at run-time.%0A    if (this.props.children && this.props.children%5Bref%5D) %7B%0A      _.extend(props, this.props.children%5Bref%5D);%0A    %7D%0A    // The .children object on a Component class contains a hash of functions.%0A    // Keys in this hash correspond with *refs* of child Components and their%0A    // values are functions that return props for each of those child Components.%0A    if (this.children && typeof(this.children%5Bref%5D) == 'function') %7B%0A      props = this.children%5Bref%5D.call(this, props);%0A    %7D%0A    props.ref = ref;%0A
     retu

Implement recursive snapshots in PersistState mixin #34