Skip to content

Commit

Permalink
Add docs for RepeatView
Browse files Browse the repository at this point in the history
  • Loading branch information
neilsarkar committed Jul 20, 2020
1 parent fbca9ce commit 8d59080
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ using Dispatch;
[System.Serializable]
public class UIState : State {
public int nice;
public List<string> bugs = new List<string> () { "wasp", "ant" } ;

}
```

Expand All @@ -31,6 +33,7 @@ public static class UIActions {
```

## View

```csharp
using VioletUI;

Expand Down Expand Up @@ -68,4 +71,32 @@ public class AddButtonView : MyBaseView {
dispatcher.Run(UIActions.Set(0));
}
}
```

## RepeatView

```csharp
public abstract class BaseRepeatView<T> : RepeatView<UIState, T> {
protected override UIState State => UIStateMB.Singleton.State;
protected override UIState LastState => UIStateMB.Singleton.LastState;
}

public abstract class BaseChildView<T> : ChildView<UIState, T> {
protected override UIState State => UIStateMB.Singleton.State;
protected override UIState LastState => UIStateMB.Singleton.LastState;
}

public class BugsView : BaseRepeatView<string> () {
public override List<string> Items => State?.bugs;
public override List<string> LastItems => LastState?.bugs;
}

public class BugView : BaseView {
public override void Render(UIState state, UIState lastState) {
if (lastState != null && Item == LastItem) { return; }

print($"I am bug number {Index} and my name changed from {LastItem} to {Item}");
}
}

```
2 changes: 1 addition & 1 deletion Runtime/Views/RepeatView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal override void OnShowInternal() {
}

internal override void RenderInternal(TState state, TState lastState) {
if (Items.Count == LastItems?.Count) { return; }
if (lastState != null && Items.Count == LastItems?.Count) { return; }
if (ViewPrefab == null) { return; }

RenderChildren();
Expand Down

0 comments on commit 8d59080

Please sign in to comment.