/**
 * @license
 * Copyright 2016 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

foam.CLASS({
  package: 'foam.u2.stack',
  name: 'StackView',
  extends: 'foam.u2.View',

  requires: [
    'foam.u2.stack.Stack'
  ],

  exports: [ 'data as stack' ],

  properties: [
    {
      name: 'data',
      factory: function() { return this.Stack.create(); }
    },
    {
      class: 'Boolean',
      name: 'showActions',
      value: true
    }
  ],

  css: '%CUSTOMCSS%',

  methods: [
    // TODO: Why is this init() instead of initE()? Investigate and maybe fix.
    function init() {
      this.setNodeName('div');
      this.addClass(this.myClass());

      if ( this.showActions ) {
        this.start('actions')
          .add(this.data.cls_.getAxiomsByClass(foam.core.Action))
        .end();
      }

      this.add(this.slot(function(s) {
        if ( ! s ) return this.E('span');

        var view   = s[0];
        var parent = s[1];

        var X;
        // If parent is a Context (should be a better way to test this)
        if ( parent && parent.isContext ) {
          X = parent;
        } else if ( parent ) {
          // I'm not sure how this is a good idea, KGR
          // TODO: find all places we do this and see if we can replace
          // with case 1 above.

          // Do a bit of a dance with the context, to ensure that exports from
          // "parent" are available to "view"
          X = this.__subSubContext__.createSubContext(parent);
        } else {
          X = this.__subSubContext__;
        }

        return foam.u2.ViewSpec.createView(view, null, this, X);

      }, this.data$.dot('top')));
    }
  ]
});

@@ -1509,21 +1509,22 @@
     
-// If
+if ( !
  parent 
 is a
@@ -1523,59 +1523,69 @@
 ent 
-is a Context (should be a better way to test this)%0A
+) %7B%0A          X = this.__subSubContext__;%0A        %7D else %7B%0A  
     
@@ -1596,18 +1596,8 @@
 if (
- parent &&
  par
@@ -1620,24 +1620,26 @@
 %7B%0A          
+ 
+ 
 X = parent;%0A
@@ -1638,16 +1638,18 @@
 parent;%0A
+  
         
@@ -1662,29 +1662,104 @@
  if ( parent
- ) %7B%0A
+.__subContext__ ) %7B%0A            X = parent.__subContext__;%0A          %7D else %7B%0A  
           //
@@ -1801,16 +1801,18 @@
 ea, KGR%0A
+  
         
@@ -1885,16 +1885,18 @@
         
+  
 // with 
@@ -1910,16 +1910,18 @@
 above.%0A%0A
+  
         
@@ -2001,16 +2001,18 @@
         
+  
 // %22pare
@@ -2039,16 +2039,18 @@
  %22view%22%0A
+  
         
@@ -2116,54 +2116,11 @@
     
-%7D else %7B%0A          X = this.__subSubContext__;
+  %7D
 %0A   

Fix bug in StackView losing context registrations.