| name | knotty |
| description | C# MVI state management framework. Use when working with KnottyStore, KnottyBus, IEffect, IntentHandlingStrategy, or "using Knotty;".
|
| triggers | ["KnottyStore","KnottyBus","IEffect","IntentHandlingStrategy","Knotty MVI","using Knotty;"] |
Knotty Framework โ Router
Decision Tree
๋ฌด์์ ๋ง๋ค๊ณ ์๋?
โ
โโ Store ์ ๊ท ์์ฑ โ Knotty.md
โโ DI ๋ฑ๋ก / ํ๋ซํผ bootstrapping โ Knotty.Setup.md
โโ View์ Store ๋ฐ์ธ๋ฉ โ Knotty.Binding.md
โโ XAML Command ์์ฑ / ๋ฐ์ธ๋ฉ โ Knotty.Command.md
โโ ๋ค๋น๊ฒ์ด์
/ Toast / Dialog โ Knotty.Effect.md
โโ ๊ฒ์ debounce / ์ทจ์ / ๋์ ์ฒ๋ฆฌ โ Knotty.IntentHandling.md
โโ ์๋ฌ ์ฒ๋ฆฌ / HasErrors / ๋กค๋ฐฑ โ Knotty.ErrorHandling.md
โโ Store ๊ฐ ํต์ (Bus) โ Knotty.Bus.md
โโ ๋๋ฒ๊น
/ ๋ก๊ทธ โ Knotty.Debugger.md
Golden Path โ ๊ธฐ๋ฅ ํ๋ ์ถ๊ฐํ ๋ ์์
1. State record ์ ์
public record MyState(int Count = 0);
2. Intent record ์ ์
public abstract record MyIntent
{
public record Increment : MyIntent;
}
3. Store ๊ตฌํ
public partial class MyStore : KnottyStore<MyState, MyIntent>
{
public MyStore() : base(new MyState()) { }
protected override async Task HandleIntent(MyIntent intent, CancellationToken ct) { ... }
}
4. DI ๋ฑ๋ก โ Knotty.Setup.md ์ฐธ๊ณ (ํ๋ซํผ๋ง๋ค ๋ค๋ฆ)
5. View์์ DataContext ์ค์ + Effect ๊ตฌ๋
โ Knotty.Binding.md ์ฐธ๊ณ
Quick Reference
Rules
Always
using Knotty; ํ๋๋ก ๋ชจ๋ ํ์
์ ๊ทผ ๊ฐ๋ฅ. ๋ค๋ฅธ Knotty ํ์ namespace ๋ถํ์.
- Source Generator ์ธ ๋๋ Store ํด๋์ค์
partial ํ์
HandleIntent ๋ด๋ถ ๋ชจ๋ await์ ct ์ ๋ฌ
- View์์ Effect ๊ตฌ๋
์
Unloaded/OnNavigatedFrom์์ ๋ฐ๋์ .Dispose()
Never
[ObservableProperty], [RelayCommand] โ CommunityToolkit๊ณผ ํผ์ฉ ๊ธ์ง
State.SomeProperty = value โ ์ง์ mutation. ๋ฐ๋์ State = State with { ... }
- State record ์์
bool ShowToast, string NavigateTo ๊ฐ์ ์ผํ์ฑ ํ๋๊ทธ
State ํ๋์ IEffect ์ธ์คํด์ค ์ ์ฅ
HandleIntent ์์์ _ = SomeAsync() fire-and-forget (ct ์ ํ ๋๊น)
Common Mistakes (์์ด์ ํธ๊ฐ ์์ฃผ ์ ์ง๋ฅด๋ ์ค์)
| ์ค์ | ์ฌ๋ฐ๋ฅธ ๋ฐฉ๋ฒ |
|---|
[ObservableProperty] public int Count { ... } | State record ํ๋๋ก ๊ด๋ฆฌ, Store๊ฐ INPC ์๋ ๊ตฌํ |
State.Count++ ์ง์ mutation | State = State with { Count = State.Count + 1 } |
await Task.Delay(1000) โ ct ์์ด | await Task.Delay(1000, ct) |
Store์ partial ์์ด [IntentCommand] ์ฌ์ฉ | public partial class MyStore : KnottyStore<...> |
Effect๋ฅผ bool IsDialogOpen์ผ๋ก State์ ๋ฃ์ | EmitEffect(new MyEffect.ShowDialog(...)) |
KnottyBus.Subscribe ์์ด Bus ๋ฉ์์ง ์์ ๊ธฐ๋ | ์์ฑ์์์ SubscribeToBus() ๋ช
์์ ํธ์ถ |