slab/delta

Clarification on insert(), delete(), retain()

Closed this issue · 2 comments

jsamr commented

I don't understand this extract from the official Quilljs website:

use the chainable insert(), delete(), and retain() methods to create new Deltas.

source: quilljs.com/docs/delta

Returns this for chainability.

source: github.com/quilljs/delta#insert

If this is returned, it's not a new instance. Hence, why the doc refers to new Deltas ?

The full text is

It is not recommended to construct Deltas by hand—rather use the chainable insert(), delete(), and retain() methods to create new Deltas.

The first part is important as it sets the context that the user is wanting to mold the Delta content to their desire, and to do that with these functions. It is not saying that the functions each individually literally return a new Delta instance.

jsamr commented

@jhchen I did thought after reading this line these methods returned new instances in an immutable, stateless way, and I still believe it is somehow confusing. But anyway, great library, thanks for the job :-)