enter the new updux
This commit is contained in:
parent
42b81e2128
commit
cdb7e8ee35
18
src/lib/components/ShipEdit.story.svelte
Normal file
18
src/lib/components/ShipEdit.story.svelte
Normal file
@ -0,0 +1,18 @@
|
||||
<Hst.Story>
|
||||
<ShipEdit {ship} />
|
||||
</Hst.Story>
|
||||
|
||||
<script>
|
||||
import { setContext } from "svelte";
|
||||
import ShipEdit from "./ShipEdit.svelte";
|
||||
import { createApi } from "$lib/store/api";
|
||||
|
||||
export let Hst;
|
||||
|
||||
const api = createApi();
|
||||
setContext("api", api);
|
||||
|
||||
let ship = api.getState();
|
||||
|
||||
api.subscribe(() => (ship = api.getState()));
|
||||
</script>
|
19
src/lib/components/ShipEdit.svelte
Normal file
19
src/lib/components/ShipEdit.svelte
Normal file
@ -0,0 +1,19 @@
|
||||
<main>
|
||||
<Identification {...ship.identification} />
|
||||
</main>
|
||||
|
||||
<script>
|
||||
import Identification from "./ShipEdit/Identification.svelte";
|
||||
|
||||
export let ship = {
|
||||
identification: {},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style>
|
||||
main {
|
||||
width: var(--main-width);
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
</style>
|
@ -33,8 +33,7 @@
|
||||
$: if (shipTypes.length > 0 && !shipTypes.includes(shipType))
|
||||
shipType = shipTypes[0];
|
||||
|
||||
$: api?.dispatch?.setShipType?.(shipType);
|
||||
$: api?.dispatch?.setShipClass?.(shipClass);
|
||||
$: api?.dispatch?.updateIdentification?.({ shipType, shipClass });
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
@ -33,7 +33,9 @@
|
||||
$: massUnused = mass - usedMass;
|
||||
$: withinBudget = massUnused >= 0;
|
||||
|
||||
$: api?.dispatch?.setShipMass?.(mass);
|
||||
$: api?.dispatch?.updateIdentification?.({
|
||||
reqs: { mass },
|
||||
});
|
||||
|
||||
/* const change_tonnage = ({ target: { value } }) => */
|
||||
/* ship.dispatch(ship.actions.set_ship_mass(parseInt(value))); */
|
||||
|
9
src/lib/store/api.ts
Normal file
9
src/lib/store/api.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import ship from "./ship";
|
||||
|
||||
export type Api = ReturnType<typeof ship.createStore>;
|
||||
|
||||
export const createApi = () => {
|
||||
const api = ship.createStore();
|
||||
console.log(api);
|
||||
return api;
|
||||
};
|
11
src/lib/store/ship.ts
Normal file
11
src/lib/store/ship.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import Updux from "updux";
|
||||
|
||||
import identification from "./ship/identification";
|
||||
|
||||
const shipDux = new Updux({
|
||||
subduxes: {
|
||||
identification,
|
||||
},
|
||||
});
|
||||
|
||||
export default shipDux;
|
29
src/lib/store/ship/identification.ts
Normal file
29
src/lib/store/ship/identification.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import Updux, { createAction, withPayload } from "updux";
|
||||
import u from "@yanick/updeep-remeda";
|
||||
|
||||
const initial = {
|
||||
shipType: "",
|
||||
shipClass: "",
|
||||
isCarrier: false,
|
||||
reqs: {
|
||||
mass: 10,
|
||||
cost: 0,
|
||||
usedMass: 0,
|
||||
},
|
||||
};
|
||||
|
||||
const setShipClass = createAction("setShipClass", withPayload<string>());
|
||||
const updateIdentification = createAction("updateIdentification");
|
||||
|
||||
export const dux = new Updux({
|
||||
initial,
|
||||
actions: {
|
||||
setShipClass,
|
||||
updateIdentification,
|
||||
},
|
||||
});
|
||||
|
||||
dux.addMutation(setShipClass, (shipClass) => u({ shipClass }));
|
||||
dux.addMutation(updateIdentification, (update) => u(update));
|
||||
|
||||
export default dux;
|
Loading…
Reference in New Issue
Block a user