Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: dynamic register types#742

Open
okxiaoliang4 wants to merge 2 commits intoyjs:mainfrom
okxiaoliang4:feature/registerTypeRef
Open

feat: dynamic register types#742
okxiaoliang4 wants to merge 2 commits intoyjs:mainfrom
okxiaoliang4:feature/registerTypeRef

Conversation

@okxiaoliang4
Copy link

This pull request refactors how type references are managed in the ContentType module, moving from an array-based approach to a Map for better extensibility and safety. It also introduces a new utility function to allow dynamic registration of type references, and updates related exports accordingly.

Refactoring and extensibility improvements:

  • Replaced the typeRefs array with a Map for storing type reference IDs and their corresponding read functions, improving lookup efficiency and allowing dynamic registration.
  • Added the registerTypeRef function to enable safe, dynamic registration of new type reference handlers, throwing an error if a duplicate ref is registered.
  • Updated the readContentType function to use the new Map structure, with error handling for unknown type references.

Export changes:

  • Exported the new registerTypeRef function from src/index.js to make it available for use elsewhere in the codebase.

Cleanup:

  • Removed the old array-based typeRefs declaration and initialization.
import * as Y from 'yjs'
import { readYArrayLike, YArrayLike } from './YArrayLike'

Y.registerTypeRef(1000, readYArrayLike)

…and add registerTypeRef function for dynamic type registration
@okxiaoliang4
Copy link
Author

@dmonad Any suggestion?

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.

1 participant