dizmojs.Storage

Storage

new Storage(prefix)

dizmojs.Storage Class. Do not call this by itself, but rather let the Dizmo and Viewer class handle it.
Parameters:
Name Type Description
prefix

String

The prefix for the path

Methods

getProperty(path, options) → {String}

Return the value or child node names stored in the given path/property. If value is set to true (or the options parameter is omitted) the value stored in the node is given back. If nodes is set to true, the names of all child nodes (direct descendants, not recursive) is given back.
Parameters:
Name Type Description
path

String

The path to the stored value
options

Object

Several possible options. String can not be set with nodes.
{
nodes {Boolean} If one wants to get sub node names of the given path
string {Boolean} If one wants to get the value directly as a string
fallback {mixed} Can be anything, will be returned when the property is not defined
}
defaults to: {nodes: false, string: false, fallback: undefined}
Throws:
  • If the path provided is not a relative path
    Type

    TreePathError

  • If the provided path is neither a string nor undefined
    Type

    NotAStringError

Returns:
The value stored in the given path
Type

String

setProperty(path, value, options)

Set, or create, a new property at the provided path
Parameters:
Name Type Description
path

String

The path of the property
value

String

The value the property should be set to
options

Object

Several possible options. String can not be set with file.
{
file {Boolean} If one wants to write a file to the storage
timeout {Number} Only used if file is set to true. The amount of time given to
dizmoViewer to save the file.
string {Boolean} If one wants to set the value directly as a string
}
defaults to: {nodes: false, string: false}
Throws:
  • If the path provided is not a relative path
    Type

    TreePathError

  • If the provided path is not a string
    Type

    NotAStringError

  • If the value is not a valid javascript type or undefiend
    If the provided options parameter is not an object or undefined
    If the provided timeout is not a number or undefined
    If the provided timeout is a number but below 0
    Type

    IllegalParameterError

deleteProperty(path)

Remove the path provided and all children
Parameters:
Name Type Description
path

String

The path to the property which should be deleted
Throws:
  • If the provided path is absolute
    If the provided path is an empty string
    Type

    TreePathError

  • If the provided path is neither a string nor undefined
    Type

    NotAStringError

subscribeToProperty(path, callback, options, subscribedCallback) → {String}

Subscribe to changes that happen on the provided path (not recursive!)
Parameters:
Name Type Argument Description
path

String

The path to listen for changes
callback

function

The function to call when a change occurs
options

Object

Several possible options. Nodes can not be set with nodes and any other value set to true.
{
nodes {Boolean} If one wants to subscribe to node change
recursive {Boolean} If one should be listening recursive through the tree
string {Boolean} If the value returned should be a string or a javascript type
}
defaults to: {value: true, nodes: false, recursive: false, string: false}
subscribedCallback

dizmojs.Storage~onSubscriptionRegisteredCallback

<optional>

The function called once the subscription is registered
Throws:
  • If the path is not a relative path
    Type

    TreePathError

  • If the callback is not a function
    Type

    NotAFunctionError

  • If the provided path is neither a string nor undefined
    Type

    NotAStringError

Returns:
The id of the subscription
Type

String

unsubscribeProperty(subscriptionId)

Unsubscribe the given subscription id. This stops any calls to the callback which is associated with that ID.
Parameters:
Name Type Description
subscriptionId

String

The subscription id retrieved from a subscribeTo or subscribeToRecursive call
Throws:
If the provided subscription id is not a string
Type

NotAStringError

beginUpdate(path)

Stop all subscribed functions under the path from being called until an endUpdate on that path has been called
Parameters:
Name Type Description
path

String

The path under which all subscribed methods should not be called anymore
Throws:
  • If the path is not a relative path
    Type

    TreePathError

  • If the provided path is neither a string nor undefined
    Type

    NotAStringError

endUpdate(path)

Immediately fire all calls that have been beginUpdate and endUpdate.
Parameters:
Name Type Description
path

String

The path under which all subscribed methods should be fired again
Throws:
  • If the path is not a relative path
    Type

    TreePathError

  • If the provided path is neither a string nor undefined
    Type

    NotAStringError

Type Definitions

onSubscriptionRegisteredCallback()

A callback that is called as soon as the subscription has been registered in the dizmoViewer.