WeavyHistory
Class for handling history states
Kind: global classInstance members
.openUri(uri) ⇒ Promise
Try to open a weavy uri in the app where it belongs.
Kind: instance method ofWeavyHistory
Resolved: When the uri successfully is opened
Rejected: When the uri can't be opened
Param | Description |
---|---|
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 ofWeavyHistory
Param |
---|
weavyUris : Array.<weavyUri>
|
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 ofWeavyHistory
Param | Description |
---|---|
panelId : string
| The id of the panel |
.getCurrentState() ⇒ weavyState
Gets the current state of the weavy instance, including all panel states.
Kind: instance method ofWeavyHistory
.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 ofWeavyHistory
.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 ofWeavyHistory
Param | Description |
---|---|
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 ofWeavyHistory
Emits:
{WeavyHistory#event:history}
Param | Description |
---|---|
[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 ofWeavyHistory
Param | Description |
---|---|
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 byWeavyHistory
Category: events
Properties
Name | Description |
---|---|
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. |
// 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.
WeavyHistory
Properties
Name | Description |
---|---|
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. |
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 ofWeavyHistory
Example
"wvy://app-123@wvy-id/e/apps/123"
~weavyState : Object
The combined state of all panels in the weavy instance.
Kind: inner typedef ofWeavyHistory
Properties
Name |
---|
panels : Array.<panelState>
|
var weavyState = {
panels: [
panel1State,
panel2State,
...
]
}