start using updating list after first async response
This commit is contained in:
parent
b60fbc2692
commit
e68324a63b
|
@ -34,6 +34,7 @@ TodoList.schema = {
|
||||||
name: 'TodoList',
|
name: 'TodoList',
|
||||||
properties: {
|
properties: {
|
||||||
name: 'string',
|
name: 'string',
|
||||||
|
creationDate: 'date',
|
||||||
items: {type: 'list', objectType: 'Todo'},
|
items: {type: 'list', objectType: 'Todo'},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -43,13 +43,14 @@ export default class TodoApp extends Component {
|
||||||
this.todoLists = realm.objects('TodoList');
|
this.todoLists = realm.objects('TodoList');
|
||||||
if (this.todoLists.length < 1) {
|
if (this.todoLists.length < 1) {
|
||||||
realm.write(() => {
|
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) {
|
this.anotherList.addListener(function(name, changes) {
|
||||||
console.log("changed: " + JSON.stringify(changes));
|
console.log("changed: " + JSON.stringify(changes));
|
||||||
|
this.todoLists = this.anotherList;
|
||||||
});
|
});
|
||||||
console.log("registered listener");
|
console.log("registered listener");
|
||||||
|
|
||||||
|
@ -110,6 +111,7 @@ export default class TodoApp extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
renderScene(route) {
|
renderScene(route) {
|
||||||
|
console.log(this.todoLists);
|
||||||
return <route.component items={this.todoLists} {...route.passProps} />
|
return <route.component items={this.todoLists} {...route.passProps} />
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +135,7 @@ export default class TodoApp extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
realm.write(() => {
|
realm.write(() => {
|
||||||
realm.create('TodoList', {name: ''});
|
realm.create('TodoList', {name: '', creationDate: new Date()});
|
||||||
});
|
});
|
||||||
|
|
||||||
this._setEditingRow(items.length - 1);
|
this._setEditingRow(items.length - 1);
|
||||||
|
|
|
@ -47,7 +47,7 @@ template<typename T>
|
||||||
typename T::Value CollectionClass<T>::create_collection_change_set(ContextType ctx, const CollectionChangeSet &change_set)
|
typename T::Value CollectionClass<T>::create_collection_change_set(ContextType ctx, const CollectionChangeSet &change_set)
|
||||||
{
|
{
|
||||||
ObjectType object = Object::create_empty(ctx);
|
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()) {
|
for (auto index : change_set.deletions.as_indexes()) {
|
||||||
deletions.push_back(Value::from_number(ctx, index));
|
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));
|
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;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue