mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
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:
parent
ae2cc5116f
commit
86bac52f94
50 changed files with 1356 additions and 998 deletions
|
|
@ -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>;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
},
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue