platform/lib/src/core/anonymous_service.dart

51 lines
1.4 KiB
Dart
Raw Normal View History

2017-02-01 21:43:18 +00:00
import 'dart:async';
import 'service.dart';
/// An easy helper class to create one-off services without having to create an entire class.
///
/// Well-suited for testing.
class AnonymousService extends Service {
Function _index, _read, _create, _modify, _update, _remove;
AnonymousService(
2018-02-07 05:46:59 +00:00
{FutureOr index([Map params]),
FutureOr read(id, [Map params]),
FutureOr create(data, [Map params]),
FutureOr modify(id, data, [Map params]),
FutureOr update(id, data, [Map params]),
FutureOr remove(id, [Map params])})
2017-02-01 21:43:18 +00:00
: super() {
_index = index;
_read = read;
_create = create;
_modify = modify;
_update = update;
_remove = remove;
}
@override
index([Map params]) => _index != null ? _index(params) : super.index(params);
@override
read(id, [Map params]) =>
_read != null ? _read(id, params) : super.read(id, params);
@override
create(data, [Map params]) =>
_create != null ? _create(data, params) : super.create(data, params);
@override
modify(id, data, [Map params]) => _modify != null
? _modify(id, data, params)
: super.modify(id, data, params);
@override
update(id, data, [Map params]) => _update != null
? _update(id, data, params)
: super.update(id, data, params);
@override
remove(id, [Map params]) =>
_remove != null ? _remove(id, params) : super.remove(id, params);
}