Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ShouldRender logic #159

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions Plk.Blazor.DragDrop/DragDropService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,9 @@ internal class DragDropService<T>
/// </summary>
public void Reset()
{
ShouldRender = true;
ActiveItem = default;
ActiveSpacerId = null;
Items = null;
DragTargetItem = default;

StateHasChanged?.Invoke(this, EventArgs.Empty);
}

public bool ShouldRender { get; set; } = true;

// Notify subscribers that there is a need for rerender
public EventHandler StateHasChanged { get; set; }
}
1 change: 0 additions & 1 deletion Plk.Blazor.DragDrop/Dropzone.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@typeparam TItem
@inject DragDropService<TItem> DragDropService
@using System.Text
@implements IDisposable

<div id="@Id" class="@GetClassesForDropzone()" @ondragover:preventDefault @ondragover="()=> { }" @ondragenter:preventDefault @ondragenter="()=> { }" @ondrop="()=>OnDrop()" @ondrop:preventDefault ondragstart="event.dataTransfer.setData('text', event.target.id);"
@ondrop:stopPropagation
Expand Down
34 changes: 0 additions & 34 deletions Plk.Blazor.DragDrop/Dropzone.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,6 @@ private bool IsValidItem()
{
return DragDropService.ActiveItem != null;
}

protected override bool ShouldRender()
{
return DragDropService.ShouldRender;
}

private void ForceRender(object sender, EventArgs e)
{
StateHasChanged();
}

protected override void OnInitialized()
{
DragDropService.StateHasChanged += ForceRender;
base.OnInitialized();
}

public string CheckIfDraggable(TItem item)
{
if (AllowsDrag == null)
Expand Down Expand Up @@ -134,27 +117,17 @@ public void OnDragEnter(TItem item)
{
Swap(DragDropService.DragTargetItem, activeItem);
}

DragDropService.ShouldRender = true;
StateHasChanged();
DragDropService.ShouldRender = false;
}

public void OnDragLeave()
{
DragDropService.DragTargetItem = default;
DragDropService.ShouldRender = true;
StateHasChanged();
DragDropService.ShouldRender = false;
}

public void OnDragStart(TItem item)
{
DragDropService.ShouldRender = true;
DragDropService.ActiveItem = item;
DragDropService.Items = Items;
StateHasChanged();
DragDropService.ShouldRender = false;
}

public string CheckIfItemIsInTransit(TItem item)
Expand Down Expand Up @@ -334,7 +307,6 @@ private bool IsDropAllowed()

private void OnDrop()
{
DragDropService.ShouldRender = true;
if (!IsDropAllowed())
{
DragDropService.Reset();
Expand Down Expand Up @@ -391,7 +363,6 @@ private void OnDrop()
}

DragDropService.Reset();
StateHasChanged();
OnItemDrop.InvokeAsync(activeItem);
}

Expand Down Expand Up @@ -424,9 +395,4 @@ private void Swap(TItem draggedOverItem, TItem activeItem)
Items.Insert(indexDraggedOverItem, tmp);
}
}

public void Dispose()
{
DragDropService.StateHasChanged -= ForceRender;
}
}