Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: node_js
node_js: node
branches:
only:
- master
16 changes: 10 additions & 6 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
/// <reference types="@nextcloud/typings" />
export function loadState<T>(app, key): T {
const elem = <HTMLInputElement>document.querySelector(`#initial-state-${app}-${key}`)
if (elem === null) {
throw new Error(`Could not find initial state ${key} of ${app}`)
}

type OCP16to17 = Nextcloud.v16.OCP | Nextcloud.v17.OCP
declare var OCP: OCP16to17;

export function loadState<T>(appId: string, key: string): T {
return OCP.InitialState.loadState<T>(appId, key)
try {
return JSON.parse(atob(elem.value))
} catch (e) {
throw new Error(`Could not parse initial state ${key} of ${app}`)
}
}
Loading