Breaking changes to Document & createNode APIs #186
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR combines a few closely related changes, and is intended to streamline how new documents and nodes are created.
new YAML.Document(value, options?)
The Document constructor gets a new first argument
value
. This allows for much more ergonomic document creation:The
doc.schema
is now also left uninitialised only ifvalue === undefined
, and is automatically set ifcreateNode()
orcreatePair()
are called.doc.createNode(value, options?)
The methods
YAML.createNode()
anddoc.schema.createNode()
are replaced by a singledoc.createNode()
. Their non-value arguments are also collected into an options object:Unlike its precedents,
doc.createNode()
is able to support circular references, which were previously only supported byYAML.stringify()
.doc.createPair(key, value, options?)
The method
doc.schema.createPair()
is replaced bydoc.createPair()
, and also uses an options bag instead of named positional arguments.Internally,
doc.createPair()
is just sugar around two separatedoc.createNode()
calls and thePair
constructor.