Use store
This commit is contained in:
parent
bfd52b6c50
commit
8515221cdf
|
@ -52,7 +52,7 @@ export const API = createAPIClient({
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
navigation.actions.goTo(
|
get(navigation).goto(
|
||||||
`${updatingUrl}?returnUrl=${encodeURIComponent(window.location)}`
|
`${updatingUrl}?returnUrl=${encodeURIComponent(window.location)}`
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,33 +1,27 @@
|
||||||
import { writable } from "svelte/store"
|
import { writable } from "svelte/store"
|
||||||
|
|
||||||
export function createNavigationStore() {
|
export function createNavigationStore() {
|
||||||
const { subscribe } = writable([])
|
const store = writable({
|
||||||
|
initialisated: false,
|
||||||
|
goto: undefined,
|
||||||
|
})
|
||||||
|
const { set, subscribe, get } = store
|
||||||
|
|
||||||
let initialisated = false
|
const init = gotoFunc => {
|
||||||
let _goTo
|
if (typeof gotoFunc !== "function") {
|
||||||
|
throw new Error('A valid "gotoFunc" must be provided')
|
||||||
const init = goToFunc => {
|
|
||||||
initialisated = true
|
|
||||||
if (typeof goToFunc !== "function") {
|
|
||||||
throw new Error('A valid "goToFunc" must be provided')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_goTo = goToFunc
|
set({
|
||||||
}
|
initialisated: true,
|
||||||
|
goto: gotoFunc,
|
||||||
const goTo = (...params) => {
|
})
|
||||||
if (!initialisated) {
|
|
||||||
throw new Error("You need to call navigation.init first")
|
|
||||||
}
|
|
||||||
|
|
||||||
_goTo(...params)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
subscribe,
|
subscribe,
|
||||||
actions: {
|
actions: {
|
||||||
init,
|
init,
|
||||||
goTo,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue