Skip to content
This repository has been archived by the owner on Mar 20, 2021. It is now read-only.

Throw occurs on restore for nested inline collections #376

Open
kpdecker opened this issue Jul 7, 2014 · 0 comments
Open

Throw occurs on restore for nested inline collections #376

kpdecker opened this issue Jul 7, 2014 · 0 comments

Comments

@kpdecker
Copy link
Contributor

kpdecker commented Jul 7, 2014

A throw occurs on restore for the following test:

      it('should handle nested inline collections', function() {
        var rootCollection1 = new Thorax.Collection([
          {id:'a', child: collection1},
          {id:'b', child: collection1},
        ]);
        var rootCollection2 = new Thorax.Collection([
          {id:'a', child: collection2},
          {id:'b', child: collection2},
        ]);

        server = new Thorax.View({
          template: Handlebars.compile('{{#collection}}{{#collection child}}something{{/collection}}{{/collection}}', {trackIds: true}),
          collection: rootCollection2
        });
        view = new Thorax.View({
          template: Handlebars.compile('{{#collection}}{{#collection child}}somethingelse{{/collection}}{{/collection}}', {trackIds: true}),
          collection: rootCollection2
        });

        registerEvents();
        restoreView();
        expect(_.keys(view.children).length).to.equal(1);

        var collectionView = _.values(view.children)[0];
        expect(collectionView.collection).to.equal(rootCollection2);
        expect(_.keys(collectionView.children).length).to.equal(2);

        var childView = _.values(collectionView.children)[0];
        expect(childView.model.attributes.child).to.equal(collection2);
        expect(_.keys(childView.children).length).to.equal(1);

        var childCollectionView = _.values(childView.children)[0];
        expect(childCollectionView.collection).to.equal(collection2);
        expect(_.keys(childCollectionView.children).length).to.equal(0);
        expect(childCollectionView.itemTemplate()).to.equal('somethingelse');

        var viewCids = _.map(childCollectionView.$('[data-model-cid]'), function(el) {
          return el.getAttribute('data-model-cid');
        });
        expect(viewCids).to.eql(collection2.map(function(model) { return model.cid; }));
        expect(view.$el.children().text()).to.equal('somethingsomethingsomethingsomethingsomethingsomethingsomethingsomething');
        expectEvents(1, 2, 0);
        compareViews();
      });

(Note that the assertions here might be incorrect, they have not been tested)

This is due to template for the deeply nested view not being properly accessible. We need to see if there is a way that we can safely restore such views, otherwise we need to make sure that we mark these views as non-restorable.

@kpdecker kpdecker added this to the 3.0 milestone Sep 3, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

1 participant