Skip to content

Reference->Lists code example is not in sync with comments describing the results of the operations #19

@pzel

Description

@pzel

The code example in the Lists section of the reference docs is misleading. The example transformations presented do not reflect what's written in the comments.

The code vs. comment discrepancy starts in this line

Which splices the list at idx 2 removing 2 elements:

// now doc.list is [0, 2, 4, 6.283185307179586]
doc.list.splice(2, 2, "automerge");
// now doc.list is [0, 'hello', 'automerge', 4]

It's impossible to arrive at the result list just by using splice.

Running the same sequence (truncated above) in my browser console gives me a very different list

>> Automerge.change(Automerge.init(), (d) => { d.list = []; d.list.push(2,3); d.list.unshift(0,1); d.list[3] = Math.PI; for (let i =0; i<d.list.length; i++) {d.list[i]*= 2}  ; d.list.splice(2,2,"automerge") ;   }).list

> Array(3) [ 0, 2, "automerge" ]

Subsequent lines make a bunch of further modifications, which are not self-explanatory, and we end up with

[0,'hello','world',2,4]

I tried rewriting this section locally to make a PR, but I'm not quite sure how to get from-here-to-there, i.e which operations (or comments) to re-write. So instead I'm just flagging this as a exposition/clarity bug in the docs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions