feat: add delta-backed replicated state

Track mutable provider state and publish immutable operation batches. Keep path codecs isolated per client subscription and state member.
This commit is contained in:
Armin Ronacher 2026-08-31 14:04:42 +02:00
parent ae2cc5116f
commit 86bac52f94
50 changed files with 1356 additions and 998 deletions

View file

@ -6,7 +6,7 @@ export interface ExampleFacetReply {
}
export interface ExampleFacetService {
readonly workerActivations: ReplicatedState<number>;
readonly workerActivations: ReplicatedState<{ count: number }>;
greet(input: { readonly name: string }, context: Context): Promise<ExampleFacetReply>;
}

View file

@ -5,18 +5,19 @@ import { ExampleFacetService } from "./contract.ts";
export default defineFacet({
id: "@earendil-works/pi-example-plugin/session",
setup(env) {
const workerActivations = env.replicatedState(0);
const workerActivations = env.replicatedState({ count: 0 });
env.provide(ExampleFacetService, {
workerActivations,
async greet({ name }) {
return {
message: `Hello ${name} from the bundled Session worker facet!!!`,
workerActivations: workerActivations.value,
workerActivations: workerActivations.value.count,
};
},
});
env.onActivate(() => {
workerActivations.set(workerActivations.value + 1, BACKGROUND_CONTEXT);
workerActivations.state.count += 1;
workerActivations.publish(BACKGROUND_CONTEXT);
});
},
});