Node

Classes

Node

Members

[undefined][undefined]

Immediately apply updates.
Source:

Methods

(static) create(configopt) → {Node}

Creates a new Node instance without using `new`.
Parameters:
Name Type Attributes Description
config Object <optional>
The constructor configuration object.
Source:
Returns:
- The new node instance.
Type
Node

(static) from(object) → {Node}

Turns a normal object into a Node instance. Properties to be imported must be enumerable and cannot be inherited via prototype.
Parameters:
Name Type Description
object Object Any enumerable object.
Source:
Returns:
- A node interface constructed from the object.
Type
Node

(static) source(object) → {Node}

Take an object and use it as the data source for a new node. This method is used with properly formatted objects, such as stringified, then parsed node instances.
Parameters:
Name Type Description
object Object The preformatted object.
Source:
Returns:
- A new node instance.
Type
Node
Example
const original = Node.create()
original.merge({ data: 'intact' })
const serialized = JSON.stringify(original)
const parsed = JSON.parse(serialized)

const node = Node.source(parsed)
node.value('data') // 'intact'

merge(incoming) → {Object}

Merges an update into the current node.
Parameters:
Name Type Description
incoming Node The node to merge from. If a plain object is passed, it will be upgraded to a node using `Node.from`.
Source:
Returns:
- A collection of changes caused by the merge.
Type
Object

meta(fieldopt) → {Object|null}

Read metadata, either on a field, or on the entire object.
Parameters:
Name Type Attributes Description
field String <optional>
The property to read metadata from.
Source:
Returns:
- If metadata is found, it returns the object. Otherwise `null` is given.
Type
Object | null

new() → {Node}

Creates an empty instance with the same configuration.
Source:
Returns:
- A new node instance with the same properties.
Type
Node

overlap(target) → {Node}

Calculates the intersection between two nodes.
Parameters:
Name Type Description
target Node Any other node.
Source:
Returns:
- A collection of fields common to both nodes.
Type
Node

rebase(target) → {Node}

Takes the changes from the current node and plays them after the changes in the target node. Similar to git rebase, but without the conflicts.
Parameters:
Name Type Description
target Node Preceding state.
Source:
Returns:
- A new, rebased node.
Type
Node

setMetadata(field, metadata) → {Object}

Sets metadata for a field, bumping the current state.
Parameters:
Name Type Description
field String A field to update.
metadata Object What metadata the field should contain.
Source:
Returns:
- The metadata object (not the same one given).
Type
Object

snapshot() → {Object}

Takes a snapshot of the current state.
Source:
Returns:
- Every key and value (currently) in the node.
Type
Object

state(field) → {Number}

Get the current state of a property.
Parameters:
Name Type Description
field String Property name.
Source:
Returns:
- Current lamport state (or 0).
Type
Number

value(field) → {Mixed}

Show the value of a node's property.
Parameters:
Name Type Description
field String The name of the property to retrieve.
Source:
Returns:
- The value of the property, or undefined if it doesn't exist. Cannot be called on reserved fields (like "@object").
Type
Mixed