refactor: Add 'table' subscription fns to generated proto services

* Provides a simple convenience, as nearly all api subscriptions made on the
  front-end are converted to TableUpdates anyways

* Can help reduce overhead by instantiating TableUpdate subscriptions
  lazily, and by using one internal TableUpdate subscription to provide
  notifications to all observers
This commit is contained in:
John Colvin committed 2022-05-24 12:25:16 -04:00
1 parent 377be5030f
commit ef69dfa646
1 file changed
+12 -1
@@ -10,14 +10,22 @@ namespace {{package}} {
public sealed class {{name}} : IApiClient, IDisposable {
readonly ClientChannel _channel;
{{name}}(ClientChannel channel) =>
{{name}}(ClientChannel channel) {
_channel = channel;
{{#each method}}
{{#if server_streaming}}
_{{name}}_tablei_src = new(() => subscribei_{{name}}().Table().Cache());
{{/if}}
{{/each}}
}
public void Dispose() =>
_channel.Dispose();
{{#each method}}
{{#if server_streaming}}
readonly Lazy<IObservable<TableUpdate<{{output_type_full}}Immutable, {{key_type.cstype}}>>> _{{name}}_tablei_src;
// {{comment}}
public IObservable<Update<{{output_type_full}}, {{key_type.cstype}}>> subscribe_{{name}}(string qualifier = null) =>
_channel.subscribe<{{output_type_full}}, {{output_type_full}}>(
@@ -29,6 +37,9 @@ namespace {{package}} {
{{@index}}, "{{name}}", qualifier, {{output_type_full}}.Parser, a => ({{output_type_full}}Immutable)a)
.reconstitute(_key);
public IObservable<TableUpdate<{{output_type_full}}Immutable, {{key_type.cstype}}>> subscribei_{{name}}_table(string qualifier = null) =>
_{{name}}_tablei_src.Value;
static {{key_type.cstype}} _key({{output_type_full}} row) =>
row.{{camel key_field}};