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(
|
2017-06-29 22:17:42 +00:00
|
|
|
{Future index([Map params]),
|
2017-02-01 21:43:18 +00:00
|
|
|
Future read(id, [Map params]),
|
|
|
|
Future create(data, [Map params]),
|
|
|
|
Future modify(id, data, [Map params]),
|
|
|
|
Future update(id, data, [Map params]),
|
|
|
|
Future remove(id, [Map params])})
|
|
|
|
: 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);
|
|
|
|
}
|