colyseus-events
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -16,3 +16,3 @@ import { ArraySchema, CollectionSchema, MapSchema, Schema, SetSchema } from '@colyseus/schema'; | ||
*/ | ||
export declare function wireEvents<T extends Events>(state: Colyseus, events: T, namespace: string): T; | ||
export declare function wireEvents<T extends Events>(state: Colyseus, events: T, namespace?: string): T; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -17,3 +17,3 @@ "use strict"; | ||
*/ | ||
function wireEvents(state, events, namespace) { | ||
function wireEvents(state, events, namespace = '') { | ||
if (isPrimitive(state)) { | ||
@@ -25,3 +25,3 @@ return events; | ||
for (const { field, value } of changes) { | ||
const fieldNamespace = `${namespace}.${field}`; | ||
const fieldNamespace = namespace ? `${namespace}.${field}` : field; | ||
events.emit(fieldNamespace, value, fieldNamespace); | ||
@@ -34,3 +34,3 @@ //@ts-ignore : the field is legal for the state | ||
if (!schemaKeys.includes(field) && Object.prototype.hasOwnProperty.call(state, field)) { | ||
const fieldNamespace = `${namespace}.${field}`; | ||
const fieldNamespace = namespace ? `${namespace}.${field}` : field; | ||
//@ts-ignore : the field is legal for the state | ||
@@ -37,0 +37,0 @@ wireEvents(state[field], events, fieldNamespace); |
{ | ||
"name": "colyseus-events", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "generate notification events from colyseus state", | ||
@@ -5,0 +5,0 @@ "repository": "git@github.com:starwards/colyseus-events.git", |
@@ -21,3 +21,3 @@ # colyseus-events | ||
const room: Room<GameState> = await client.joinOrCreate("game"); | ||
const events = wireEvents(room.state, new EventEmitter(), "state"); | ||
const events = wireEvents(room.state, new EventEmitter()); | ||
``` | ||
@@ -29,6 +29,5 @@ then you can wire listeners to `events` and start triggering them. | ||
examples: | ||
when the server executes: `state.foo.bar = 15` event `'state.foo.bar'` will be emitted with values `15` and `'state.foo.bar'`. | ||
when the server executes: `state.foo.bar.push(15)` event `'state.foo.bar[0]'` will be emitted with values `15` and `'state.foo.bar[0]'`. | ||
when the server executes: `room.state.foo.bar = 15` event `'foo.bar'` will be emitted with values `15` and `'foo.bar'`. | ||
when the server executes: `room.state.foo.bar.push(15)` event `'foo.bar[0]'` will be emitted with values `15` and `'foo.bar[0]'`. | ||
``` | ||
@@ -35,0 +34,0 @@ ## Contributor instructions |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12596
65