Webanizr Logo
Open / sluit menu
Module pathState

v the form of chats, folled outs or multipath forms. The pathState has a collect aswell as an send method.

syntax (collect)

webanizr.collect('pathState', parameters, callback)

The collect function can be used to add an listener to a specific path. Adding multiple collects on a pathState you create a state machine defining the response to each state.

parameters

The collect method of pathState accepts the following parameters.

id__system (required)

pathState you be used for several different state machines on the same page. The id__system parameters tells the module which of the state machines your targeting.

paths__listener (required)

The path you want this state to respond to. This is an array of strings. In each string you can specify the exact paths, i.e. "/" or "/one/two". You can also use the following parameters to make a broad match:

{one__steps}

You can use this option to match exactly one step. For instance "/one/{one__steps}/three" will match /one/two/three.

{multiple__steps}

You can use this option to match one or more steps. For instance "/a/{mulitple__steps}/z" will match /a/b/c and /a/b/c/d/e/f/z but not /a/z.

{optional__steps}

You can use this option to match zero or more steps. For instance "/a/{optional__steps}z" will match  /a/b/c, /a/b/c/d/e/f/z and /a/z.It is imported to notice that {optional__steps} is not followed by a /.

vars__action (optional)

The global vars that are set when the path is reached. You could also use webanizr.setVars in the callback function, this is simply a shorthand option.

callback

The callback function that is called when the state is reached. At this point no data is send to the callback function, this might change in the future.

syntax (send)

webanizr.send('pathState', data, parameters, callback)

The send function can be used to change the current path and therefore the state of the addressed state machine.

data

In the data section the following attributes could be processed:

element__path

Element__path contains the string which is used to manipulate the current path. It is used by the add and set parameters.

parameters 

The send method of pathState accepts the following parameters:

id__system (required)

The state machine you want to change the path of.

type__action (required)

The type of action you want to perform on the current path:

add

Add the value of element__path from data to the current path. The value should not contain a opening or trailing /.

set

Replace the current value of the current path.

callback

The callback function that is called after the actions are performed. The callback function is called with the unaltered data.

global vars

The following global vars are maintained by this module:

currentpath__<systemid>

Where <systemid> is the value set by id__system. In this value the value of the path of the system.

pathlength__<systemid>

Where <systemid> is the value set by id__system. In this value the number of elements in the path of this system is kept up-to-date.

demo

A simple scripted chat:

https://cdn.cpmodules.webanizr.com/demo/path-state-demo/index.html