Skip to content

Commit

Permalink
Revise the codes
Browse files Browse the repository at this point in the history
  • Loading branch information
hackerwins committed Oct 23, 2024
1 parent 8a2eceb commit ae0e42e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
11 changes: 6 additions & 5 deletions packages/sdk/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ export class Client {
public attach<T, P extends Indexable>(
doc: Document<T, P>,
options: {
initialPresence?: P;
initialRoot?: T;
initialPresence?: P;
syncMode?: SyncMode;
} = {},
): Promise<Document<T, P>> {
Expand Down Expand Up @@ -369,11 +369,12 @@ export class Client {

const crdtObject = doc.getRootObject();
if (options.initialRoot) {
const initialRoot = options.initialRoot;
doc.update((root) => {
for (const [k, v] of Object.entries(options.initialRoot!)) {
if (!crdtObject.get(k)) {
// TODO(raararaara): Need a way to accurately infer the type of `k` for indexing.
(root as Record<string, unknown>)[k] = v;
for (const [k, v] of Object.entries<T>(initialRoot)) {
if (!crdtObject.has(k)) {
const key = k as keyof T;
root[key] = v as any;
}
}
});
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk/test/integration/document_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1259,20 +1259,20 @@ describe('Document', function () {
`${task.name}-${name}-${new Date().getTime()}`,
);

type docType = {
type DocType = {
tree?: Tree;
text?: Text;
counter?: Counter;
null?: null;
boolean?: boolean;
number?: number;
long?: Long;
object?: Object;
object?: { k: string };
array?: Array<JSONElement>;
bytes?: Uint8Array;
// date: Date;
};
const doc = new yorkie.Document<docType>(docKey);
const doc = new yorkie.Document<DocType>(docKey);

await c1.attach(doc, {
initialRoot: {
Expand Down

0 comments on commit ae0e42e

Please sign in to comment.