Skip to content

Commit

Permalink
fixed some more yjs binding types
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviergonz committed Feb 10, 2025
1 parent 2895769 commit e117a7b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions packages/mobx-keystone-yjs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 1.5.3

- Fixed some types.

## 1.5.2

- Just renamed some internal types.
Expand Down
2 changes: 1 addition & 1 deletion packages/mobx-keystone-yjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mobx-keystone-yjs",
"version": "1.5.2",
"version": "1.5.3",
"description": "Yjs bindings for mobx-keystone",
"keywords": [
"mobx",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function convertJsonToYjsData(v: PlainValue): YjsData {
}

if (isPlainArray(v)) {
const arr = new Y.Array()
const arr = new Y.Array<YjsData>()
applyJsonArrayToYArray(arr, v)
return arr as YjsData
}
Expand All @@ -48,7 +48,7 @@ export function convertJsonToYjsData(v: PlainValue): YjsData {
return text
}

const map = new Y.Map()
const map = new Y.Map<YjsData>()
applyJsonObjectToYMap(map, v)
return map as YjsData
}
Expand All @@ -59,14 +59,14 @@ export function convertJsonToYjsData(v: PlainValue): YjsData {
/**
* Applies a JSON array to a Y.Array, using the convertJsonToYjsData to convert the values.
*/
export function applyJsonArrayToYArray(dest: Y.Array<unknown>, source: PlainArray) {
export function applyJsonArrayToYArray(dest: Y.Array<YjsData>, source: PlainArray) {
dest.push(source.map(convertJsonToYjsData))
}

/**
* Applies a JSON object to a Y.Map, using the convertJsonToYjsData to convert the values.
*/
export function applyJsonObjectToYMap(dest: Y.Map<unknown>, source: PlainObject) {
export function applyJsonObjectToYMap(dest: Y.Map<YjsData>, source: PlainObject) {
Object.entries(source).forEach(([k, v]) => {
dest.set(k, convertJsonToYjsData(v))
})
Expand Down

0 comments on commit e117a7b

Please sign in to comment.