yorkie icon indicating copy to clipboard operation
yorkie copied to clipboard

Change the interface from `document.update()` to `document.change()`

Open chacha912 opened this issue 1 year ago • 2 comments

Description:

Currently, we use document.update() and document.subscribe() as shown below:

const doc = new yorkie.Document('example');
doc.update((root) => { 
  // modify the document contents... 
});

document.subscribe((event) => {
  // If the event type is `local-change` or `remote-change`
  for (const changeInfo of event.value) {
    // changeInfo represents the modifications made during a document update
    const {message, operationInfos} = changeInfo;
    for (const opInfo of operationInfos) { 
      // ex) { type: 'increase', value: 1, path: '$.counter' }
      switch (opInfo.type) {
        case 'increase':  
           // Do something...
           break;
      }
    }
  }
  }
});

When the event type is local-change or remote-change, the event value type is an array of ChangeInfo. ChangeInfo represents the modifications made during document.update. The different names, update and change, can be confusing when using the method. Therefore, it would be better to either change ChangeInfo to UpdateInfo or to unify the method name to change. Since Yorkie already uses the terms operation and change internally, it would be better to change the method name to change.

Why:

Using the term ChangeInfo to represent the modifications made during an doc.update can cause confusion. To maintain consistency, let's change the method name to change

chacha912 avatar Apr 05 '23 10:04 chacha912

I'd like to try this ... 😄

kongnayeon avatar Jul 29 '23 19:07 kongnayeon

@kongnayeon Good luck!

hackerwins avatar Jul 31 '23 05:07 hackerwins

Is it still good to change? 🤔 It would be good to close it for now and reopen this again later if necessary.

hackerwins avatar Jul 04 '24 08:07 hackerwins