Skip to content

Commit 0536ad7

Browse files
authored
Merge pull request #5 from clockworklabs/csharp-module-support
Fix the way we were getting the reducer name for reducer cache
2 parents 66ef98b + e2b8edf commit 0536ad7

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

src/spacetimedb_sdk/client_cache.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import importlib
22
import pkgutil
33

4+
45
def snake_to_camel(snake_case_string):
5-
return snake_case_string.replace('_', ' ').title().replace(' ','')
6+
return snake_case_string.replace("_", " ").title().replace(" ", "")
7+
68

79
class TableCache:
810
def __init__(self, table_class):
@@ -27,26 +29,28 @@ def delete_entry(self, key):
2729
def get_entry(self, key):
2830
if key in self.entries:
2931
return self.entries[key]
30-
32+
3133
def values(self):
3234
return self.entries.values()
3335

3436

3537
class ClientCache:
3638
def __init__(self, autogen_package):
37-
3839
self.tables = {}
3940
self.reducer_cache = {}
4041

41-
for importer, module_name, is_package in pkgutil.iter_modules(autogen_package.__path__):
42+
for importer, module_name, is_package in pkgutil.iter_modules(
43+
autogen_package.__path__
44+
):
4245
if not is_package:
4346
module = importlib.import_module(
44-
f"{autogen_package.__name__}.{module_name}")
47+
f"{autogen_package.__name__}.{module_name}"
48+
)
4549

4650
# check if its a reducer
4751
if module_name.endswith("_reducer"):
48-
reducer_name = module_name[:-len("_reducer")]
49-
args_class = getattr(module,"_decode_args")
52+
reducer_name = getattr(module, "reducer_name")
53+
args_class = getattr(module, "_decode_args")
5054
self.reducer_cache[reducer_name] = args_class
5155
else:
5256
# Assuming table class name is the same as the module name
@@ -56,11 +60,11 @@ def __init__(self, autogen_package):
5660
table_class = getattr(module, table_class_name)
5761

5862
# Check for a special property, e.g. 'is_table_class'
59-
if getattr(table_class, 'is_table_class', False):
63+
if getattr(table_class, "is_table_class", False):
6064
self.tables[table_class_name] = TableCache(table_class)
6165

6266
def get_table_cache(self, table_name):
63-
return self.tables[table_name]
67+
return self.tables[table_name]
6468

6569
def decode(self, table_name, value):
6670
if not table_name in self.tables:
@@ -94,5 +98,5 @@ def get_entry(self, table_name, key):
9498
if not table_name in self.tables:
9599
print(f"[get_entry] Error, table not found. ({table_name})")
96100
return
97-
98-
return self.tables[table_name].get_entry(key)
101+
102+
return self.tables[table_name].get_entry(key)

src/spacetimedb_sdk/spacetimedb_client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ def __init__(self):
110110

111111

112112
class ReducerEvent:
113+
"""
114+
This class contains the information about a reducer event to be passed to row update callbacks.
115+
"""
116+
113117
def __init__(self, caller_identity, reducer_name, status, message, args):
114118
self.caller_identity = caller_identity
115119
self.reducer_name = reducer_name

0 commit comments

Comments
 (0)