File tree Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @colyseus/schema" ,
3
- "version" : " 2.0.9 " ,
3
+ "version" : " 2.0.10 " ,
4
4
"description" : " Binary state serializer with delta encoding for games" ,
5
5
"bin" : {
6
6
"schema-codegen" : " ./bin/schema-codegen"
Original file line number Diff line number Diff line change @@ -155,16 +155,22 @@ function generateAllFieldCallbacks(klass: Class, indent: string) {
155
155
return `${ klass . properties
156
156
. filter ( prop => ! prop . deprecated ) // generate only for properties that haven't been deprecated.
157
157
. map ( prop => {
158
- const eventName = `_ ${ prop . name } Change` ;
158
+ const eventName = `__ ${ prop . name } Change` ;
159
159
eventNames . push ( eventName ) ;
160
+
161
+ const defaultNull = ( prop . childType )
162
+ ? "null"
163
+ : `default(${ getType ( prop ) } )` ;
164
+
160
165
return `\t${ indent } protected event PropertyChangeHandler<${ getType ( prop ) } > ${ eventName } ;
161
- \t${ indent } public Action On${ capitalize ( prop . name ) } Change(PropertyChangeHandler<${ getType ( prop ) } > handler ) {
166
+ \t${ indent } public Action On${ capitalize ( prop . name ) } Change(PropertyChangeHandler<${ getType ( prop ) } > __handler, bool __immediate = true ) {
162
167
\t${ indent } \tif (__callbacks == null) { __callbacks = new SchemaCallbacks(); }
163
- \t${ indent } \t__callbacks.AddPropertyCallback(nameof(${ prop . name } ));
164
- \t${ indent } \t${ eventName } += handler;
168
+ \t${ indent } \t__callbacks.AddPropertyCallback(nameof(this.${ prop . name } ));
169
+ \t${ indent } \t${ eventName } += __handler;
170
+ \t${ indent } \tif (__immediate && this.${ prop . name } != ${ defaultNull } ) { __handler(this.${ prop . name } , ${ defaultNull } ); }
165
171
\t${ indent } \treturn () => {
166
172
\t${ indent } \t\t__callbacks.RemovePropertyCallback(nameof(${ prop . name } ));
167
- \t${ indent } \t\t${ eventName } -= handler ;
173
+ \t${ indent } \t\t${ eventName } -= __handler ;
168
174
\t${ indent } \t};
169
175
\t${ indent } }` ;
170
176
} ) . join ( "\n\n" ) }
You can’t perform that action at this time.
0 commit comments