-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: ArraySchema.unshift() not working as intended. #170
Comments
Thanks for sharing the reproduction scenario, will add this to colyseus/colyseus#641 |
Thank you, appreciate your work! Can you recommend a workaround for this until 3.0 is out that doesn't use .unshift() but still inserts an item at the front of the array? My only solution right now is to reverse() push() reverse() - which seems to work fine. |
As a workaround, you can try flushing the changes (via x.push(1)
x.push(2)
x.push(3)
x.push(4)
x.push(5)
x.pop()
x.pop()
x.push(9)
this.broadcastPatch(); // HERE
x.unshift(8) |
Will try, thank you! |
Bug description
Array.unshift should insert an item at the beginning of the array.
ArraySchema.unshift does the same, if the array has only been .push()'d to so far. As soon as either .pop() or .shift() was called on the ArraySchema, any .unshift() will mess the array up.
Example code below is also available on stackblitz.
This example uses .pop() though a similar invalid state is reached if .pop() is replaced with .shift()
Optional: Minimal reproduction
https://stackblitz.com/edit/colyseus-schema-issue-report-iwe3ai?file=index.ts
The text was updated successfully, but these errors were encountered: