Created
September 5, 2023 07:08
-
-
Save mythril/1c7b26daa250ee47adf1dbab85969308 to your computer and use it in GitHub Desktop.
Cyclic dependency, I think
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script lang="ts" context="module"> | |
import { writable } from "svelte/store"; | |
export type ObjectValues<T> = T[keyof T]; | |
export const Digit = { | |
Thumb: "Thumb", | |
Fore: "Fore", | |
Index: "Index", | |
Ring: "Ring", | |
Pinky: "Pinky", | |
} as const; | |
type Digits = Set<ObjectValues<typeof Digit>>; | |
class Person { | |
_leftFingersGloved: Digits = new Set(); | |
addSleeveToLeftGlove(d: ObjectValues<typeof Digit>) { | |
this._leftFingersGloved.add(d); | |
} | |
hasSleeveOnLeftGlove(d: ObjectValues<typeof Digit>) { | |
return this._leftFingersGloved.has(d); | |
} | |
deleteSleeveFromLeftGlove(d: ObjectValues<typeof Digit>) { | |
this._leftFingersGloved.delete(d); | |
} | |
_rightFingersGloved: Digits = new Set(); | |
addSleeveToRightGlove(d: ObjectValues<typeof Digit>) { | |
this._rightFingersGloved.add(d); | |
} | |
hasSleeveOnRightGlove(d: ObjectValues<typeof Digit>) { | |
return this._rightFingersGloved.has(d); | |
} | |
deleteSleeveFromRightGlove(d: ObjectValues<typeof Digit>) { | |
this._rightFingersGloved.delete(d); | |
} | |
} | |
export const person = writable(new Person()); | |
</script> | |
<script lang="ts"> | |
import LeftGlove from "./LeftGlove.svelte"; | |
import RightGlove from "./RightGlove.svelte"; | |
</script> | |
<LeftGlove /> | |
<RightGlove /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script lang="ts"> | |
import { Digit, person, type ObjectValues } from './+page.svelte'; | |
export let digitSleeves: (ObjectValues<typeof Digit>)[] = []; | |
$: { | |
let lSet = new Set(digitSleeves); | |
for (let digit of Object.values(Digit)) { | |
if (lSet.has(digit) && $person.hasSleeveOnLeftGlove(digit) === false) { | |
$person.addSleeveToLeftGlove(digit); | |
} | |
if (lSet.has(digit) === false && $person.hasSleeveOnLeftGlove(digit)) { | |
$person.deleteSleeveFromLeftGlove(digit); | |
} | |
} | |
$person = $person; | |
} | |
</script> | |
<h4>left hand glove</h4> | |
<div> | |
{#each Object.values(Digit) as digit} | |
<label><input type="checkbox" bind:group={digitSleeves} value={digit} />{digit}</label> | |
{/each} | |
</div> | |
<pre>{JSON.stringify(digitSleeves, undefined, 2)}</pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script lang="ts"> | |
import { Digit, person, type ObjectValues } from './+page.svelte'; | |
export let digitSleeves: (ObjectValues<typeof Digit>)[] = []; | |
$: { | |
let lSet = new Set(digitSleeves); | |
for (let digit of Object.values(Digit)) { | |
if (lSet.has(digit) && $person.hasSleeveOnRightGlove(digit) === false) { | |
$person.addSleeveToRightGlove(digit); | |
} | |
if (lSet.has(digit) === false && $person.hasSleeveOnRightGlove(digit)) { | |
$person.deleteSleeveFromRightGlove(digit); | |
} | |
} | |
$person = $person; | |
} | |
</script> | |
<h4>left hand glove</h4> | |
<div> | |
{#each Object.values(Digit) as digit} | |
<label><input type="checkbox" bind:group={digitSleeves} value={digit} />{digit}</label> | |
{/each} | |
</div> | |
<pre>{JSON.stringify(digitSleeves, undefined, 2)}</pre> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment