generated from LankyMoose/pnpm-monorepo-package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix: keyed FC children should now handle reordering correctly, ref…
…actor E2E tests
- Loading branch information
1 parent
8f04715
commit 63c8ebf
Showing
10 changed files
with
157 additions
and
70 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { useState } from "kaioken" | ||
|
||
export function KeyedList() { | ||
const [counters, setCounters] = useState<string[]>( | ||
"abcdefghijklmnopqrstuvwxyz".split("") | ||
) | ||
|
||
const randomize = () => { | ||
const newCounters = [...counters] | ||
newCounters.sort(() => Math.random() - 0.5) | ||
setCounters(newCounters) | ||
} | ||
const remove = (id: string) => { | ||
setCounters(counters.filter((c) => c !== id)) | ||
} | ||
|
||
return ( | ||
<div id="keyed-list"> | ||
<ul> | ||
{counters.map((c) => ( | ||
<li key={"item-" + c} data-key={c} className="flex gap-2"> | ||
<KeyedCounterItem id={c} remove={() => remove(c)} /> | ||
</li> | ||
))} | ||
</ul> | ||
|
||
<button id="randomize" onclick={randomize}> | ||
Randomize | ||
</button> | ||
</div> | ||
) | ||
} | ||
|
||
interface KeyedCounterProps { | ||
id: string | ||
remove: () => void | ||
} | ||
|
||
function KeyedCounterItem({ id, remove }: KeyedCounterProps) { | ||
const [count, setCount] = useState(0) | ||
return ( | ||
<> | ||
id : {id} | ||
<div className="flex gap-2 px-2 bg-black bg-opacity-30"> | ||
<button | ||
className="increment btn btn-primary" | ||
onclick={() => setCount((c) => c + 1)} | ||
> | ||
{count} | ||
</button> | ||
</div> | ||
<button className="remove btn btn-primary" onclick={remove}> | ||
Remove | ||
</button> | ||
</> | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { useModel, useState } from "kaioken" | ||
|
||
export function TodoList() { | ||
const [inputRef, inputValue, setInputValue] = useModel("") | ||
const [items, setItems] = useState<{ text: string }[]>([ | ||
{ text: "buy coffee" }, | ||
{ text: "walk the dog" }, | ||
{ text: "push the latest commits" }, | ||
]) | ||
|
||
function addItem() { | ||
setItems((items) => [...items, { text: inputValue }]) | ||
setInputValue("") | ||
} | ||
|
||
return ( | ||
<div id="todos"> | ||
<input ref={inputRef} /> | ||
<button onclick={addItem} /> | ||
<ul> | ||
{items.map((item) => ( | ||
<li>{item.text}</li> | ||
))} | ||
</ul> | ||
</div> | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { memo, useState } from "kaioken" | ||
|
||
export function MemoTest() { | ||
const [count, setCount] = useState(0) | ||
return ( | ||
<div id="memo"> | ||
<span>Count: {count}</span> | ||
<button onclick={() => setCount((prev) => prev + 1)}>Increment</button> | ||
<WhenPropsChangeMemo count={1} /> | ||
{count % 2 === 0 && <DynamicRenderMemo />} | ||
</div> | ||
) | ||
} | ||
|
||
let renders = 0 | ||
const DynamicRenderMemo = memo(() => { | ||
return ( | ||
<div id="memo-dynamic" className="flex flex-col"> | ||
<span className="text-red-500">Render Count: {++renders}</span> | ||
</div> | ||
) | ||
}) | ||
|
||
let renders2 = 0 | ||
const WhenPropsChangeMemo = memo(({ count }: { count: number }) => { | ||
return ( | ||
<div id="memo-props" className="flex flex-col"> | ||
<div>Memo Demo {count}</div> | ||
<span>Render Count: {++renders2}</span> | ||
</div> | ||
) | ||
}) |
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
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