Nathan.fooo aa5f052ecf
Refactor/crate directory (#1621)
* chore: fix wanrings

* chore: remove protobuf ref in flowy-error-code

* chore: remove protobuf ref in lib-ws

* refactor: remove protobuf trait in flowy http model

* refactor: remove flowy-error-code crate

Co-authored-by: nathan <nathan@appflowy.io>
2022-12-30 11:16:47 +08:00

46 lines
1.3 KiB
Plaintext

class {{ event_class }} {
{%- if has_input %}
{{ input_deserializer }} request;
{{ event_class }}(this.request);
{%- else %}
{{ event_class }}();
{%- endif %}
Future<Either<{{ output_deserializer }}, {{ error_deserializer }}>> send() {
{%- if has_input %}
final request = FFIRequest.create()
..event = {{ event }}.toString()
..payload = requestToBytes(this.request);
return Dispatch.asyncRequest(request)
.then((bytesResult) => bytesResult.fold(
{%- if has_output %}
(okBytes) => left({{ output_deserializer }}.fromBuffer(okBytes)),
{%- else %}
(bytes) => left(unit),
{%- endif %}
(errBytes) => right({{ error_deserializer }}.fromBuffer(errBytes)),
));
{%- else %}
final request = FFIRequest.create()
..event = {{ event }}.toString();
{%- if has_input %}
..payload = bytes;
{%- endif %}
return Dispatch.asyncRequest(request).then((bytesResult) => bytesResult.fold(
{%- if has_output %}
(okBytes) => left({{ output_deserializer }}.fromBuffer(okBytes)),
{%- else %}
(bytes) => left(unit),
{%- endif %}
(errBytes) => right({{ error_deserializer }}.fromBuffer(errBytes)),
));
{%- endif %}
}
}