Skip to content
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

Issue #26 - Add support for passing a different state encoder to expo… #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Myrannas
Copy link

As requested, I've reopened the PR with some adjustments - in particular moving the encoding methods to be static on the classes so that a new instance is not required.

…xported encoding and decoding methods, and add a binary encoding strategy.
* @param {encoding.Encoder} encoder
* @param {any} update
*/
static encodeState (encoder, update) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved these to static.

A different pattern we could consider here is to instead instantiate a copy of this class and store it on an exported constant. I'm happy to change to that if you'd prefer.


export const testAwarenessWithBinary = testAwarenessWithEncoding(awareness.BinaryAwarenessStateEncoder, awareness.BinaryAwarenessStateEncoder)
export const testAwarenessWithDefault = testAwarenessWithEncoding(awareness.DefaultAwarenessStateEncoder, awareness.DefaultAwarenessStateEncoder)
export const testAwarenessBackwardsCompatDecoder = testAwarenessWithEncoding(awareness.DefaultAwarenessStateEncoder, undefined)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've swapped the original "default" test I had, and instead replaced it with two tests to verify that the default encoder is used if none is passed into the methods.

@@ -189,9 +237,10 @@ export const removeAwarenessStates = (awareness, clients, origin) => {
/**
* @param {Awareness} awareness
* @param {Array<number>} clients
* @param {typeof DefaultAwarenessStateEncoder|typeof BinaryAwarenessStateEncoder} stateEncoder The encoder to use for encoding and decoding each state entry
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't use jsdoc types a lot, but my understanding is that typeof Blah is the best way to describe a constructor.

Another way to type this would be to instead type the "interface" expected - but that would make changes to the requirements of the encoder a breaking change.

@Myrannas
Copy link
Author

Hey @dmonad, this PR is ready for a review when you have some time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants