WeavyHistory

Class for handling history states

Kind: global class

Instance members

.openUri(uri) ⇒ Promise

Try to open a weavy uri in the app where it belongs.

Kind: instance method of WeavyHistory
Resolved: When the uri successfully is opened
Rejected: When the uri can't be opened
ParamDescription
uri : weavyUri

String weavy Uri to open in a panel.


.getStateFromUri(weavyUris) ⇒ weavyState

Get a weavy state from one or more weavyUri uris.

Kind: instance method of WeavyHistory
Param
weavyUris : Array.<weavyUri>
Example
var weavyState = weavy.history.getStateFromUri("wvy://app-123@wvy-id/e/apps/123");
Example
var weavyUris = [
  "wvy://app-123@wvy-id/e/apps/123",
  "wvy://app-456/e/apps/456"
];

var weavyState = weavy.history.getStateFromUri(weavyUris);

.getStateFromPanel(panelId) ⇒ panelState

Gets the panel state from a specified panel. May also be accessed via {@WeavyPanels~panel#getState}

Kind: instance method of WeavyHistory
ParamDescription
panelId : string

The id of the panel


.getCurrentState() ⇒ weavyState

Gets the current state of the weavy instance, including all panel states.

Kind: instance method of WeavyHistory

.getBrowserState() ⇒ weavyState

Gets the global state for all weavy instances combined, stored in the browser history state. The state has the same structure as a single weavy instance state.

Kind: instance method of WeavyHistory

.setBrowserState(state, [action], [url])

Saves a weavy state to the browser history by either push or replace. Any existing state will be preserved and existing states from other weavy instances will be merged.

Kind: instance method of WeavyHistory
ParamDescription
state : weavyState

The state to add to any existing state

[action : string ]

If set to "replace", the current history state will be updated.

[url : any ]

Any new url to use for the state. If omitted, the current location will be reused.


.addState([action], [state]) ⇒ weavyState

Adds a state to the browser history, by either push or replace. This is usually used automatically by internal components.

Kind: instance method of WeavyHistory
Emits: {WeavyHistory#event:history}
ParamDescription
[action : string ]

"push" or "replace". Indicates if the state should generate a new history point or replace the existing.

[state : weavyState ]

The state to add. Defaults to the current state of the weavy instance.


.openState(state) ⇒ Promise

Restores all the matching panels in a weavy state. It will open or close the panels and restore their location. It will not genrate any new history.

Kind: instance method of WeavyHistory
ParamDescription
state : weavyState

The state to restore


Events

"history" ⇒ Object

Triggered when a weavy state is added or updated. The global weavy state will be stored in window.history.state.weavy unless default is prevented.

This is where you can modify the url or the state just before it will be pushed or replaced. If you call event.preventDefault() you need do save the state to the browser history by yourself.

Kind: event emitted by WeavyHistory
Category: events
Properties
NameDescription
state : weavyState

The state of the weavy instance

action : string

Indicates what the intention of the history state is "push" or "replace"

url : string

The url to set in the browser history.

globalState : weavyState

The current combined global state for all weavy instances.

Example
// Modify the history URL to include the last opened panel as a hash and return the data
weavy.on("history", function (e, history) {
    // Get only panels that has been interactively opened/closed (changedAt) and is currently open.
    var allOpenPanels = history.globalState.panels.filter(function (panelState) {
        return panelState.changedAt && panelState.isOpen;
    });
    var lastOpenPanel = allOpenPanels.pop();

    // Set the url
    if(lastOpenPanel) {
        // Set the hash to the last opened panel
        history.url = "#" + lastOpenPanel.weavyUri;
    } else {
        // Remove the hash if no changed panel is open
        history.url = history.url.split("#")[0];
    }

    // Return the modified data to apply it
    return history;
});

Inner members

~panelState : Object

The data for a panel state. Indicates which location the panel has and if it's open. The changedAt property is not set at the initial state load, only when the state changes. May be applied to a panel using setState.

Kind: inner typedef of WeavyHistory
Properties
NameDescription
id : string

The DOM id of the panel.

panelId : string

The internal id of the panel.

isOpen : boolean

Indicates whether the panel is open or not.

location : string

The relative current location for the panel.

statusCode : int

The http code of the location of the panel.

weavyId : string

The explicitly set weavy id. Null if id is not set in options.

: weavyUri

The Weavy Uri for the panel

changedAt : int

Timestamp if the state of the panel was changed since weavy loaded.

Example
var panelState = {
  id: "panel-app-123__wy-41d751e8",
  panelId: "app-123",
  isOpen: true,
  location: "/e/apps/123,
  statusCode: 200,
  weavyId: "wy-41d751e8",
  weavyUri: "wvy://app-123@wy-41d751e8/e/apps/123",
  changedAt: 1614596627434
}

~weavyUri : String

An Uri for a location in a specific panel. May be opened using openUri.

Kind: inner typedef of WeavyHistory
Example
"wvy://app-123@wvy-id/e/apps/123"

~weavyState : Object

The combined state of all panels in the weavy instance.

Kind: inner typedef of WeavyHistory
Properties
Name
panels : Array.<panelState>
Example
var weavyState = {
  panels: [
     panel1State,
     panel2State,
     ...
  ]
}