2021-02-01 19:51:22 +01:00
|
|
|
<script>
|
|
|
|
import { getContext, setContext } from "svelte"
|
|
|
|
import { createContextStore } from "../store"
|
|
|
|
|
|
|
|
export let data
|
|
|
|
export let actions
|
2021-02-05 12:44:33 +01:00
|
|
|
export let key
|
2021-02-01 19:51:22 +01:00
|
|
|
|
|
|
|
// Clone and create new data context for this component tree
|
|
|
|
const context = getContext("context")
|
|
|
|
const component = getContext("component")
|
|
|
|
const newContext = createContextStore($context)
|
|
|
|
setContext("context", newContext)
|
2021-02-05 12:44:33 +01:00
|
|
|
$: providerKey = key || $component.id
|
2021-02-01 19:51:22 +01:00
|
|
|
|
|
|
|
// Add data context
|
2021-02-05 13:54:36 +01:00
|
|
|
$: data !== undefined && newContext.actions.provideData(providerKey, data)
|
2021-02-01 19:51:22 +01:00
|
|
|
|
|
|
|
// Add actions context
|
|
|
|
$: {
|
|
|
|
actions?.forEach(({ type, callback }) => {
|
2021-02-05 12:44:33 +01:00
|
|
|
newContext.actions.provideAction(providerKey, type, callback)
|
2021-02-01 19:51:22 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<slot />
|