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
Allow arbitrary awareness fields in Collaboration plugin #4507
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, Attila. @acywatson and @zurfyx . Could you give it a look as well.
I don't think this works since map is not json serializeable, should be plain object like remaining of awareness data. Personal opinion: naming looks a bit odd, as usage will be awareness.getLocalState().awarenessFields, maybe data or extraData would do better, no strong opinion tho. Also can add a unit test (see Collaboration.test), as collab is quite sensitive for changes, so it's better to get it covered |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
~
@fantactuka Thanks for the review! I have changed the type from Map to object and added unit test. |
expect(client1.awareness.getLocalState().awarenessFields).toEqual( | ||
awarenessFields1, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use awareness.getStates() instead, to ensure that client1 has proper awareness from client2 and vise versa?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like here the mock for getStates() only inserts the current client's awareness state. That's why I opted for the getLocalState(). However, I have manually tested and between two collaborating users the awareness is sync correctly.
@@ -225,27 +229,41 @@ export function useYjsFocusTracking( | |||
provider: Provider, | |||
name: string, | |||
color: string, | |||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | |||
awarenessFields?: object, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we can use { ... }
here and remove eslint comment above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, we don't need the eslint comments anymore - any
is not used anymore. Removed all of them.
Thanks for updates! @acywatson @zurfyx thoughts on naming? |
I like having awareness in the name, but fields is probably wrong. "awarenessData" or "extraAwaresnessData" seems fine. doc block on the interface would help people know what it's for. |
Renamed the parameter to |
@@ -62,7 +63,8 @@ class Client { | |||
_listeners: Map<string, Set<(data: unknown) => void>>; | |||
_updates: Uint8Array[]; | |||
awareness: { | |||
getLocalState(): void; | |||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | |||
getLocalState(): any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this better? Besides the object
prop what other types we don't know?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added types for getLocalState(), getStates(), setLocalState(), etc.
Thanks for checking!
packages/lexical-yjs/src/index.ts
Outdated
): void { | ||
provider.awareness.setLocalState({ | ||
anchorPos: null, | ||
awarenessData: awarenessData, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awarenessData: awarenessData, | |
awarenessData, |
Similar one below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the change.
Co-authored-by: Attila Novak <anovak8@bloomberg.net>
Summary
This change allows arbitrary data (for example 3rd party UUID) to be added to awareness. Right now user name and color is hard coded in Collaboration plugin. The new parameter
awarenessData
is optional.Usage example
We can specify our arbitrary data like this:
With the new parameter, we can send down our arbitrary data: