Skip to content

Commit

Permalink
fix(crdt-yjs): fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
pluvrt committed Feb 11, 2024
1 parent c0ecc67 commit 1376df8
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/crdt-yjs/src/array/CrdtYjsArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class CrdtYjsArray<T extends unknown> extends AbstractCrdtType<

this.initialValue = initialValue;
this.value = new YArray<InferYjsType<T>>();
this.push(...initialValue.slice());
this.push(...value);
}

public get length(): number {
Expand Down
7 changes: 0 additions & 7 deletions packages/crdt-yjs/src/constants.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/crdt-yjs/src/map/CrdtYjsMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { toYjsValue } from "../shared";
import type { InferYjsJson, InferYjsType } from "../types";

export class CrdtYjsMap<T extends unknown> extends AbstractCrdtType<
YMap<T>,
YMap<InferYjsType<T>>,
Record<string, InferYjsJson<T>>
> {
public initialValue: readonly (readonly [
key: string,
value: InferYjsType<T>,
])[];
public value: YMap<T>;
public value: YMap<InferYjsType<T>>;

constructor(value: readonly (readonly [key: string, value: T])[] = []) {
super();
Expand Down
11 changes: 4 additions & 7 deletions packages/crdt-yjs/src/object/CrdtYjsObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@ export class CrdtYjsObject<
constructor(value: T = {} as T) {
super();

this.initialValue = Object.entries(value).map(
([k, v]) =>
[k, toYjsValue(v)] as readonly [
key: string,
value: InferYjsType<T[keyof T]>,
],
);
this.initialValue = Object.entries(value).map(([k, v]) => [
k,
toYjsValue(v),
]);
this.value = new YMap(this.initialValue);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/crdt-yjs/src/xmlElement/CrdtYjsXmlElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class CrdtYjsXmlElement extends AbstractCrdtType<YXmlElement, string> {
this.initialValue = children.map((item) => item.value);
this.name = name;
this.value = new YXmlElement(name);
this.value.push(this.initialValue.slice());
this.push(...children);
}

public get length(): number {
Expand Down
2 changes: 1 addition & 1 deletion packages/crdt-yjs/src/xmlFragment/CrdtYjsXmlFragment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class CrdtYjsXmlFragment extends AbstractCrdtType<YXmlFragment, string> {

this.initialValue = children.map((item) => item.value);
this.value = new YXmlFragment();
this.value.push(this.initialValue.slice());
this.push(...children);
}

public get length(): number {
Expand Down

0 comments on commit 1376df8

Please sign in to comment.