sproutcore / guides

The guides source. Build and push to https://github.com/sproutcore-guides/sproutcore-guides.github.com.

Home Page:http://guides.sproutcore.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting Started Part 2 error.

defeated opened this issue · comments

The application stops working in Step 4, where we change createToDo(). Now entering some text and hitting Enter clears the list of ToDos, and throws an error.

In Firefox, Firebug reports the following error:

item[kvoChainList] is undefined
clonedChain = item[kvoChainList][chainGuid]; 

In Chrome, the error is slightly different:

Uncaught TypeError: Cannot read property 'sc232' of undefined
javascript.js:6690

Now, if I change SC.Store.create().from(SC.Record.fixtures) to SC.Store.create(), the error goes away (but the list is still cleared.)

Thank you for the bug report! This should be fixed by this commit in SproutCore: sproutcore/sproutcore@91ffedd

Will try to release a new gem soon. You can checkout SproutCore's master branch from Git by following these steps:
http://www.veebsbraindump.com/2010/09/using-the-latest-sproutcore-code-from-the-master-branch/

Thanks, that works again.

Aside question: is it normal to get SC.Error:sc214:SC.RecordArray is not editable (-1) When trying to clear the list of completed tasks?
The guide states: "All of the other operations that you perform on records should also work seamlessly, because we use standard get() and set() functions that work for every type of objects in SproutCore."

Destroying the record through the store fixes the problem:

  clearCompletedTodos: function() {
    this.filterProperty('isDone', true).forEach(function(todo) {
      Todos.store.destroyRecord(Todos.Todo, todo.get('id'));
    }, this);
  },

I am not very familiar with the SC API. There is maybe a more correct way...

It does not always work right... However, the guide about records (http://guides.sproutcore.com/records.html#destroying-records) give us a clean solution: call destroy() on the SC.Record. This would give:

  clearCompletedTodos: function() {
    this.filterProperty('isDone', true).forEach(function(todo) {
      todo.destroy();
    }, this);
  },

Something else now, when trying to remove newly created items, the items without ids are again going to break the example. A random call to generate ids should probably be added to the createTodo call:

  createTodo: function(title) {
    Todos.store.createRecord(Todos.Todo, { title: title, guid: Math.floor(Math.random() * 11) });
  },