API Docs for: 3.18.1

HistoryBase Class

Module: history-base
Parent Module: history

Provides global state management backed by an object, but with no browser history integration. For actual browser history integration and back/forward support, use the history-html5 or history-hash modules.

Item Index

Properties

Methods

add

(
  • state
  • options
)
chainable

Adds a state entry with new values for the specified keys. By default, the new state will be merged into the existing state, and new values will override existing values. Specifying a null or undefined value will cause that key to be removed from the new state entry.

Parameters:

  • state Object

    Object hash of key/value pairs.

  • options Object

    (optional) Zero or more of the following options:

    merge (Boolean)

    If true (the default), the new state will be merged into the existing state. New values will override existing values, and null or undefined values will be removed from the state.

    If false, the existing state will be discarded as a whole and the new state will take its place.

addValue

(
  • key
  • value
  • options
)
chainable

Adds a state entry with a new value for a single key. By default, the new value will be merged into the existing state values, and will override an existing value with the same key if there is one. Specifying a null or undefined value will cause the key to be removed from the new state entry.

Parameters:

  • key String

    State parameter key.

  • value String

    New value.

  • options Object

    (optional) Zero or more options. See add() for a list of supported options.

get

(
  • key
)
Object | String

Returns the current value of the state parameter specified by key, or an object hash of key/value pairs for all current state parameters if no key is specified.

Parameters:

  • key String

    (optional) State parameter key.

Returns:

Object | String:

Value of the specified state parameter, or an object hash of key/value pairs for all current state parameters.

replace

(
  • state
  • options
)
chainable

Same as add() except that a new browser history entry will not be created. Instead, the current history entry will be replaced with the new state.

Parameters:

  • state Object

    Object hash of key/value pairs.

  • options Object

    (optional) Zero or more options. See add() for a list of supported options.

replaceValue

(
  • key
  • value
  • options
)
chainable

Same as addValue() except that a new browser history entry will not be created. Instead, the current history entry will be replaced with the new state.

Parameters:

  • key String

    State parameter key.

  • value String

    New value.

  • options Object

    (optional) Zero or more options. See add() for a list of supported options.

Properties

force

Boolean

If true, a history:change event will be fired whenever the URL changes, even if there is no associated state change.

Default: false

html5

Boolean static

Whether or not this browser supports the HTML5 History API.

NAME

String static

Name of this component.

nativeHashChange

Boolean static

Whether or not this browser supports the window.onhashchange event natively. Note that even if this is true, you may still want to use HistoryHash's synthetic hashchange event since it normalizes implementation differences and fixes spec violations across various browsers.

SRC_ADD

String final static

Constant used to identify state changes originating from the add() method.

SRC_REPLACE

String final static

Constant used to identify state changes originating from the replace() method.

Events

[key]Change

Dynamic event fired when an individual history item is added or changed. The name of this event depends on the name of the key that changed. To listen to change events for a key named "foo", subscribe to the fooChange event; for a key named "bar", subscribe to barChange, etc.

Key-specific events are only fired for instance-level changes; that is, changes that were made via the same History instance on which the event is subscribed. To be notified of changes made by other History instances, subscribe to the global history:change event.

Event Payload:

  • e EventFacade

    Event facade with the following additional properties:

    newVal (mixed)
    The new value of the item after the change.
    prevVal (mixed)
    The previous value of the item before the change, or undefined if the item was just added and has no previous value.
    src (String)
    The source of the event. This can be used to selectively ignore events generated by certain sources.

[key]Remove

Dynamic event fired when an individual history item is removed. The name of this event depends on the name of the key that was removed. To listen to remove events for a key named "foo", subscribe to the fooRemove event; for a key named "bar", subscribe to barRemove, etc.

Key-specific events are only fired for instance-level changes; that is, changes that were made via the same History instance on which the event is subscribed. To be notified of changes made by other History instances, subscribe to the global history:change event.

Event Payload:

  • e EventFacade

    Event facade with the following additional properties:

    prevVal (mixed)
    The value of the item before it was removed.
    src (String)
    The source of the event. This can be used to selectively ignore events generated by certain sources.

history:change

Fired when the state changes. To be notified of all state changes regardless of the History or YUI instance that generated them, subscribe to this event on Y.Global. If you would rather be notified only about changes generated by this specific History instance, subscribe to this event on the instance.

Event Payload:

  • e EventFacade

    Event facade with the following additional properties:

    changed (Object)
    Object hash of state items that have been added or changed. The key is the item key, and the value is an object containing newVal and prevVal properties representing the values of the item both before and after the change. If the item was newly added, prevVal will be undefined.
    newVal (Object)
    Object hash of key/value pairs of all state items after the change.
    prevVal (Object)
    Object hash of key/value pairs of all state items before the change.
    removed (Object)
    Object hash of key/value pairs of state items that have been removed. Values are the old values prior to removal.
    src (String)
    The source of the event. This can be used to selectively ignore events generated by certain sources.