pureweb.client. ApplicationState

The ApplicationState class manages changes between the service and the client application.

Application state is an XML hierarchical tree of properties and values which resides on both the service and the client; it provides a synchronized data store between these components.

To maintain application state synchronicity, the differences in state are automatically transmitted between the client and the service; these differences are contained in a diff script, generated whenever PureWeb executes the difference method.

See also the XmlStateManager class, which provides methods for finer-grained interactions with application state.

Method Summary

clear
Empties the application state and clears any changes.
clearChanges
Clears any changes in application state.
copyState
Copies the state (at a specified path, optionally), and returns the element representing the current state.
difference
Compares the application state tree on the client with the application state tree on the service.
finishChanges
Ends the batch changes that were started using startChanges.
getStateManager
Returns an instance of XmlStateManager.
getValue
Returns the value of the element at the specified path in the application state tree.
initialize
Initializes application state to a copy of the specified value.
isChanged
Returns a Boolean value that indicates whether application state has changed.
isInitialized
Returns a Boolean value that indicates whether application state is initialized.
merge
Applies the specified diff script to the application state
onSynchronized
Called when the state is synchronized from the server.
setValue
Sets the value of the element at the specified path in the application state tree.
startChanges
Starts batch changes to application state.
stateChangeHandler
Handler function for a change to application state.
toString
Returns a string that represents the current stateManager object.

Constructor

new ApplicationState()

Initializes a new instance of ApplicationState.

Extends

  • pureweb.events.EventTarget

Method Detail

clear()

Empties the application state and clears any changes.

clearChanges()

Clears any changes in application state.

copyState(args) → {Element}

Copies the state (at a specified path, optionally), and returns the element representing the current state.
Parameters:
Name Type Description
args string An optional object containing a member called 'path' which is the path to copy.

difference() → {Element}

Compares the application state tree on the client with the application state tree on the service. Returns an XML script that describes the differences. At the end of the operation, all changes are cleared.

finishChanges()

Ends the batch changes that were started using startChanges. Any suppressed events will be fired.

getStateManager() → {pureweb.xml.XmlStateManager}

Returns an instance of XmlStateManager.

getValue(path) → {string}

Returns the value of the element at the specified path in the application state tree. Will return null if the element does not exist.
Parameters:
Name Type Description
path string The path in application state.

initialize(state)

Initializes application state to a copy of the specified value.
Parameters:
Name Type Description
state Node The state.

isChanged() → {boolean}

Returns a Boolean value that indicates whether application state has changed. Will return true if is has, otherwise will return false.

isInitialized() → {boolean}

Returns a Boolean value that indicates whether application state is initialized. Will return true if is has, otherwise will return false.

merge(diffScript)

Applies the specified diff script to the application state
Parameters:
Name Type Description
diffScript Element The element containing a script of the differences.

onSynchronized(sender, event)

Called when the state is synchronized from the server.
Parameters:
Name Type Description
sender Object What is bound to 'this' in the handler.
event Object The argument provided to the handler.

setValue(path, value)

Sets the value of the element at the specified path in the application state tree.
Parameters:
Name Type Description
path string The path in application state.
value string | number The value to set at the specified path.

startChanges()

Starts batch changes to application state. Events will be suppressed until finishChanges is called.

stateChangeHandler(args)

Handler function for a change to application state.
Parameters:
Name Type Description
args Object Optional arguments for the function handler.

toString() → {string}

Returns a string that represents the current stateManager object.