Show:

Q.Tree Class

Module: Q

Creates a Q.Tree object

Constructor

Q.Tree

(
  • [linked={}]
)

Parameters:

  • [linked={}] Object optional

    If supplied, then this object is used as the internal tree that Tree operates on.

Methods

breadthFirst

(
  • callback
  • [context=null]
)

Traverse the tree breadth-first and call the callback

Parameters:

  • callback Function

    Will receive (path, value, tree, context)

  • [context=null] Mixed optional

    To propagate some context to the callback

clear

(
  • [keys=null]
)
Boolean

Clears the value of a field, removing that key from the tree

Parameters:

  • [keys=null] String | Array optional

    A key or an array of keys for traversing the tree. If null, clears entire tree.

Returns:

Boolean:

Returns whether the field to be cleared was found

depthFirst

(
  • callback
  • [context=null]
)

Traverse the tree depth-first and call the callback

Parameters:

  • callback Function

    Will receive (path, value, tree, context)

  • [context=null] Mixed optional

    To propagate some context to the callback

diff

(
  • tree
)
Q.Tree

Calculates a diff between this tree and another tree

Parameters:

Returns:

Q.Tree:

This tree holds the results of the diff

get

(
  • [keys=[]
  • [def=undefined]
)
Mixed

Gets the value of a field in the tree

Parameters:

  • [keys=[] String | Array optional

    A key or an array of keys for traversing the tree.

  • [def=undefined] Mixed optional

    The value to return if the field is not found. Defaults to undefined.

Returns:

Mixed:

The field if it is found, otherwise def or undefined.

getAll

() Object

Gets the entire tree of parameters

Returns:

load

(
  • filename
  • [callback=null]
)

Loads data into a tree from a file.

Parameters:

  • filename String

    The filename of the file to load.

  • [callback=null] Function optional

    Function to call back, with params (err, data)

merge

(
  • second
  • [under=false]
)
Object

Merges a tree over the top of an existing tree

Parameters:

  • second Q.Tree | Object

    The Object or Q.Tree to merge over the existing tree.

  • [under=false] Boolean optional

    If true, merges the second under this tree, instead of over it. By default, second is merged on top of this tree.

Returns:

Object:

Returns the resulting tree, modified by the merge.

save

(
  • filename
  • [arrayPath=[]
  • [prefixPath=[]
  • [callback=null]
)

Saves a (sub)tree of parameters to a file

Parameters:

  • filename String

    The filename to save into. If tree was loaded from a single file, you can leave this blank to update that file.

  • [arrayPath=[] Array optional

    Array of keys identifying the path of the subtree to save

  • [prefixPath=[] Array optional

    Array of keys identifying the prefix path of the subtree to save

  • [callback=null] Function optional

    Function to call back, with params (err)

set

(
  • keys
  • value
)
Q.Tree chainable

Sets the value of a field in the tree. If only one argument is given, it is assigned as tree value

Parameters:

  • keys String | Array

    A key or an array of keys for traversing the tree.

  • value Mixed

    The value to set for that field.

Returns:

Q.Tree:

Returns itself for chaining