start using updating list after first async response

This commit is contained in:
Ari Lazier 2016-05-27 17:13:55 -07:00
parent b60fbc2692
commit e68324a63b
3 changed files with 7 additions and 12 deletions

View File

@ -34,6 +34,7 @@ TodoList.schema = {
name: 'TodoList',
properties: {
name: 'string',
creationDate: 'date',
items: {type: 'list', objectType: 'Todo'},
},
};

View File

@ -43,13 +43,14 @@ export default class TodoApp extends Component {
this.todoLists = realm.objects('TodoList');
if (this.todoLists.length < 1) {
realm.write(() => {
realm.create('TodoList', {name: 'Todo List'});
realm.create('TodoList', {name: 'Todo List', creationDate: new Date()});
});
}
this.anotherList = realm.objects('TodoList');
this.anotherList = realm.objects('TodoList').sorted('creationDate');
this.anotherList.addListener(function(name, changes) {
console.log("changed: " + JSON.stringify(changes));
this.todoLists = this.anotherList;
});
console.log("registered listener");
@ -110,6 +111,7 @@ export default class TodoApp extends Component {
}
renderScene(route) {
console.log(this.todoLists);
return <route.component items={this.todoLists} {...route.passProps} />
}
@ -133,7 +135,7 @@ export default class TodoApp extends Component {
}
realm.write(() => {
realm.create('TodoList', {name: ''});
realm.create('TodoList', {name: '', creationDate: new Date()});
});
this._setEditingRow(items.length - 1);

View File

@ -47,7 +47,7 @@ template<typename T>
typename T::Value CollectionClass<T>::create_collection_change_set(ContextType ctx, const CollectionChangeSet &change_set)
{
ObjectType object = Object::create_empty(ctx);
std::vector<ValueType> deletions, insertions, modifications, moves;
std::vector<ValueType> deletions, insertions, modifications;
for (auto index : change_set.deletions.as_indexes()) {
deletions.push_back(Value::from_number(ctx, index));
}
@ -63,14 +63,6 @@ typename T::Value CollectionClass<T>::create_collection_change_set(ContextType c
}
Object::set_property(ctx, object, "modifications", Object::create_array(ctx, modifications));
for (auto& move : change_set.moves) {
ObjectType move_object = Object::create_empty(ctx);
Object::set_property(ctx, move_object, "from", Value::from_number(ctx, move.from));
Object::set_property(ctx, move_object, "to", Value::from_number(ctx, move.to));
moves.push_back(move_object);
}
Object::set_property(ctx, object, "moves", Object::create_array(ctx, moves));
return object;
}