Skip to content

Commit 8f5e112

Browse files
committed
rename 'GetCallbackProxy' type to 'SchemaCallbackProxy<RoomState>'
1 parent 52b4b0e commit 8f5e112

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@colyseus/schema",
3-
"version": "3.0.14",
3+
"version": "3.0.15",
44
"description": "Binary state serializer with delta encoding for games",
55
"bin": {
66
"schema-codegen": "./bin/schema-codegen",

src/decoder/strategy/StateCallbacks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import type { CollectionSchema } from "../../types/custom/CollectionSchema";
1717
// - Avoid closures by allowing to pass a context. (https://github.com/colyseus/schema/issues/155#issuecomment-1804694081)
1818
//
1919

20-
export type GetCallbackProxy = (<T extends Schema>(instance: T) => CallbackProxy<T>);
20+
export type SchemaCallbackProxy<RoomState> = (<T extends Schema>(instance: T) => CallbackProxy<T>);
2121

2222
export type CallbackProxy<T> = unknown extends T // is "any"?
2323
? SchemaCallback<T> & CollectionCallback<any, any>
@@ -99,7 +99,7 @@ type CallContext = {
9999
}
100100

101101

102-
export function getDecoderStateCallbacks<T extends Schema>(decoder: Decoder<T>): GetCallbackProxy {
102+
export function getDecoderStateCallbacks<T extends Schema>(decoder: Decoder<T>): SchemaCallbackProxy<T> {
103103
const $root = decoder.root;
104104
const callbacks = $root.callbacks;
105105

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ export { TypeContext } from "./types/TypeContext";
4545
// Annotation types
4646
export type { DefinitionType, PrimitiveType, Definition, } from "./annotations";
4747

48-
export { getDecoderStateCallbacks, CallbackProxy, SchemaCallback, CollectionCallback } from "./decoder/strategy/StateCallbacks";
48+
export { getDecoderStateCallbacks, CallbackProxy, SchemaCallback, CollectionCallback, SchemaCallbackProxy } from "./decoder/strategy/StateCallbacks";
4949
export { getRawChangesCallback } from "./decoder/strategy/RawChanges";
5050

5151
export { Encoder } from "./encoder/Encoder";
52-
export { encodeSchemaOperation, encodeArray as encodeKeyValueOperation } from "./encoder/EncodeOperation";
52+
export { encodeSchemaOperation, encodeArray, encodeKeyValueOperation } from "./encoder/EncodeOperation";
5353
export { ChangeTree, Ref } from "./encoder/ChangeTree";
5454
export { StateView } from "./encoder/StateView";
5555

test/callbacks/StateCallbacks.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,28 @@ import * as assert from "assert";
22

33
import { Schema, type, ArraySchema, MapSchema, getDecoderStateCallbacks, decodeSchemaOperation, Decoder } from "../../src";
44
import { createInstanceFromReflection, getCallbacks, getDecoder } from "../Schema";
5+
import { SchemaCallbackProxy } from "../../src/decoder/strategy/StateCallbacks";
56

67
describe("StateCallbacks", () => {
78

9+
it("TypeScript type inference", () => {
10+
class Item extends Schema {
11+
@type("number") amount: number;
12+
}
13+
class State extends Schema {
14+
@type([Item]) items = new ArraySchema<Item>();
15+
@type('int64') actionType: number;
16+
}
17+
const state = new State();
18+
const decodedState = createInstanceFromReflection(state);
19+
const decoder = getDecoder(decodedState);
20+
21+
const $ = getDecoderStateCallbacks(decoder);
22+
const ref$: SchemaCallbackProxy<State> = $;
23+
24+
assert.strictEqual($, ref$);
25+
});
26+
827
it("should trigger changes in order they've been originally made", () => {
928
class State extends Schema {
1029
@type(['string']) boardTiles = new ArraySchema<string>();

0 commit comments

Comments
 (0)