ember Uncaught Error: assertion failed: Emptying a view in the inBuffer state
Asked Answered
A

2

17

I get this assertion when run the code below:

Emptying a view in the inBuffer state is not allowed and should not happen under normal circumstances. Most likely there is a bug in your application. This may be due to excessive property change notifications.

Link to demo: http://plnkr.co/edit/s3bUw4JFrJvsL690QUMi

var App = Ember.Application.create({
  Store: DS.Store.extend({
    revision: 4,
    adapter: DS.FixtureAdapter.create()
  }),

  Router: Ember.Router.extend({
    root: Ember.Route.extend({
      index: Ember.Route.extend({
        route: "/",
        connectOutlets: function(router){
          var person;
          person = App.Person.find(657);
          person.addObserver("isLoaded", function() {
            return router.get('router.applicationController').connectOutlet("things", person.get("things"));
          });
        }
      })
    })
  }),

  ApplicationController: Em.Controller.extend(),

  ApplicationView: Em.View.extend({
    template: Em.Handlebars.compile("{{outlet}}")
  }),

  ThingsController: Em.ArrayController.extend({
    thingTypes: (function() {
      return App.ThingType.find();
    }).property()
  }),

  ThingsView: Em.View.extend({
    template: Em.Handlebars.compile([
      '{{#each controller.thingTypes}}', 
        '{{this.name}}', 
      '{{/each}}',
      '{{#each controller.content}}', 
        '{{this.title}}', 
      '{{/each}}'].join(""))
  }),

  //MODELS
  Person: DS.Model.extend({
    things: DS.hasMany('App.Thing', {
      embedded: true
    })
  }),

  Thing: DS.Model.extend({
    description: DS.attr('string'),
    thingType: DS.belongsTo("App.ThingType", {
      embedded: true
    }),
    title: (function() {
      return this.get("thingType.name");
    }).property("description")
  }),

  ThingType: DS.Model.extend({
    name: DS.attr("string")
  })
});

App.Person.FIXTURES = [
  {
    id: 657,
    things: [
      {
        id: 1,
        description: "Some text",
        thing_type: {
          id: 1,
          name: "type 1"
        }
      }, {
        id: 2,
        description: "Some text",
        thing_type: {
          id: 2,
          name: "type 2"
        }
      }
    ]
  }
];

App.ThingType.FIXTURES = [
  {
    id: 1,
    name: "type 1"
  }, {
    id: 2,
    name: "type 2"
  }, {
    id: 3,
    name: "type 3"
  }
];

Why is this happening?

Alidaalidade answered 17/1, 2013 at 13:16 Comment(1)
This still happens in the new router. Unable to nail the issue :-(Continuum
P
2

I was having the same error while trying to load a list of dropdown values from fixtures. What resolved it was overriding queryFixtures on the fixture adapter:

App.FixtureAdapter = DS.FixtureAdapter.extend
  latency: 200
  queryFixtures: (records, query, type) ->
    records.filter (record) ->
      for key of query
        continue  unless query.hasOwnProperty(key)
        value = query[key]
        return false  if record[key] isnt value
      true

I probably wouldn't have figured it out had I not set the latency first. Then the error was a bit more descriptive.

Paries answered 26/2, 2014 at 15:26 Comment(0)
M
0

a bit late I guess... but I got it to work here: http://plnkr.co/edit/hDCT4Qy1h5aE6GjM76qp

Didn't change the logic but where its called

I modified your router like this:

Router: Ember.Router.extend({
    root: Ember.Route.extend({
      index: Ember.Route.extend({
        route: "/",
        connectOutlets: function(router) {
          var person;
          router.set('router.applicationController.currentPerson', App.Person.find(657));
        }
      })
    })
  })

And created an ApplicationController:

ApplicationController: Em.Controller.extend({
    currentPerson: null,
    currentPersonLoaded: function() {
      this.connectOutlet("things", this.get("currentPerson.things"));
    }.observes("currentPerson.isLoaded"),
  })

I dont know if this is the output you wished but the bug vanished!

Mensch answered 14/12, 2013 at 1:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.