change the way I propagate actions

main
Yanick Champoux 2020-07-26 12:19:52 -04:00
parent 1dd6be4b1a
commit a9e1c4e50a
2 changed files with 7 additions and 4 deletions

View File

@ -43,6 +43,8 @@
const set_screens = ({detail}) => ship.dispatch.set_screens(detail);
const ship_dispatch = ({detail}) => ship.dispatch(detail);
</script>
<main>
@ -82,7 +84,7 @@
</Section>
<Section label="misc">
<Cargo {...$ship.cargo} />
<Cargo {...$ship.cargo} on:set_cargo={ship_dispatch}/>
</Section>
</main>

View File

@ -8,17 +8,18 @@
import get from 'lodash/get';
import ShipItem from '~C/ShipItem/index.svelte';
import Field from '~C/Field/index.svelte';
import dux from '~/dux/cargo';
import {getContext} from 'svelte';
import {getContext, createEventDispatcher} from 'svelte';
const ship = getContext('ship');
export let space = 0;
export let cost = 0;
export let mass = 0;
export let set_cargo = get(ship,'dispatch.set_cargo',() => {});
$: set_cargo( space );
const dispatch = createEventDispatcher();
$: dispatch( 'set_cargo', dux.actions.set_cargo( space ) );
</script>