onUpdate method

void onUpdate(
  1. EntityEventSource src
)

When invoked, the entity should use the event source to obtain the most recent value for each of its fields, internally performing an update where necessary Implementations can override this if for example they only want to update selected fields they can use EntityEventSource.valueOf

Implementation

void onUpdate(EntityEventSource src) {
  //Do not allow objects that are partially loaded to be persisted
  canPersist = false;
  src.allFields((fieldName, value) {
    Future<dynamic> fieldFuture;
    final field = fieldsByName[fieldName];
    if (field != null && value != null) {
      fieldFuture = field.read(src, value);
    } else {
      fieldFuture = Future.value(null);
    }
    return fieldFuture;
  }).whenComplete(() {
    postDeserialisation();
    //Done de-serialising, this can now be persisted
    canPersist = true;
  });
}