Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

colyseus-events

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

colyseus-events - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

2

dist/index.d.ts

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc