Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a23f459
Use initial source as dynamic pagination source for other pages
devnatan Sep 9, 2023
6a34685
Rename pagination's isDynamic to isLazy
devnatan Sep 9, 2023
6c595d8
Reuse dynamic pagination
devnatan Sep 10, 2023
0612425
Switch pageChanged state immediately after update
devnatan Sep 10, 2023
419ab87
Fix isLazy check on constructor
devnatan Sep 10, 2023
2bdac31
Remove NotNull annotations from constructor
devnatan Sep 10, 2023
ba9e3d9
Minor optimizations
devnatan Sep 10, 2023
a2ae4f6
Lock child interactions while page is being updated
devnatan Sep 10, 2023
7a3bf8d
Inherit ItemComponent visibility from root
devnatan Sep 10, 2023
f408417
Pagination own visibility state
devnatan Sep 10, 2023
38f9f36
Remove manual visibility switch from ItemComponent's clear()
devnatan Sep 10, 2023
872f099
Use ArrayList for components and optimize reuse
devnatan Sep 10, 2023
dcb7305
Expose pagination page split function
devnatan Sep 10, 2023
bd35b80
Documentation to isStatic and isLazy
devnatan Sep 10, 2023
38c96c8
Rename PaginationElementConsumer to PaginationValueConsumer
devnatan Sep 11, 2023
9073e38
Explicit computed pagination state
devnatan Sep 11, 2023
37393e8
Update visibility of pagination component
devnatan Sep 11, 2023
693c73d
Call update interceptor only if context is rendered
devnatan Sep 11, 2023
8f7a7cd
Use non-deprecated versions of buildComputedState
devnatan Sep 11, 2023
b107adc
Use parent context as subject to context clear
devnatan Sep 11, 2023
c14b0fc
Fix isLazy assignment
devnatan Sep 11, 2023
754a1f7
Drop computedState with Supplier and add async ones
devnatan Sep 11, 2023
06c7056
Optimize lazy source assignment by splitting it properly on initial i…
devnatan Sep 11, 2023
6a90bb0
Re-assign page count only in reuse of non-lazy pagination
devnatan Sep 11, 2023
a9327fe
Make changes binary incompatible
devnatan Sep 11, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ public interface Component extends VirtualView {
// TODO Needs documentation
boolean shouldRender(IFContext context);

/**
* Updates this component.
*/
void update();

/**
* Checks if two components area intersects with each other.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,15 @@ public void updated(@NotNull IFSlotRenderContext context) {
@Override
public void clear(@NotNull IFContext context) {
((IFRenderContext) context).getContainer().removeItem(getPosition());
}

@Override
public void update() {
if (isManagedExternally())
throw new IllegalStateException(
"This component is externally managed by another component and cannot be updated directly");

setVisible(false);
if (root instanceof IFContext) ((IFContext) root).updateComponent(this);
}

@Override
Expand All @@ -193,6 +200,8 @@ public void clicked(@NotNull Component component, @NotNull IFSlotClickContext co

@Override
public boolean isVisible() {
if (root instanceof Component) return ((Component) root).isVisible() && isVisible;

return isVisible;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package me.devnatan.inventoryframework.component;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import me.devnatan.inventoryframework.state.StateValue;
import me.devnatan.inventoryframework.state.StateValueHost;
import org.jetbrains.annotations.ApiStatus;
Expand Down Expand Up @@ -128,20 +132,103 @@ public interface Pagination extends ComponentComposition, StateValue {
char getLayoutTarget();

/**
* Lazy pagination usually have a {@link java.util.function.Function} as source provider and
* this provider is only called again to set the current internal source when an explicit
* update is called. This kind of pagination is used to replicate a static-like pagination since
* it can use a Function to provide some information to composite the source that'll be built
* but will never change again.
* <p>
* So, when this method returns <code>true</code> the only way to update the current source as a
* whole is triggering an update somehow e.g. by calling {@link #update()}.
* <p>
* Page switches will not trigger the source provider to re-apply the current internal source.
* <p>
* <b><i> This is an internal inventory-framework API that should not be used from outside of
* this library. No compatibility guarantees are provided. </i></b>
*/
@ApiStatus.Internal
boolean isDynamic();
boolean isLazy();

/**
* If the pagination data is being loaded or not.
* Static pagination is a type of pagination that usually have a {@link java.util.Collection} or
* something else as source provider and this source provider is called only on first render to
* set the current source as a whole, and never called again on the entire Pagination lifecycle.
* <p>
* Only changes if {@link #isDynamic()} is true.
* <b><i> This is an internal inventory-framework API that should not be used from outside of
* this library. No compatibility guarantees are provided. </i></b>
*/
@ApiStatus.Internal
boolean isStatic();

/**
* Computed pagination usually have a {@link java.util.function.Function}-like as source provider
* and this provider is called each time this component is updated or the page is changed so the
* current as a whole will always be the result of the source provider, regardless the {@link #currentPage() current page}.
* <p>
* <b><i> This is an internal inventory-framework API that should not be used from outside of
* this library. No compatibility guarantees are provided. </i></b>
*/
@ApiStatus.Internal
boolean isComputed();

/**
* Asynchronous pagination can have a mix of all others {@link #isStatic() static}, {@link #isLazy() lazy} and {@link #isComputed() computed}
* types of pagination source, that is:
* <ul>
* <li>Have a CompletableFuture as source? Then it's static.</li>
* <li>Have a Function or Supplier as source? Type will be defined by implementation.</li>
* </ul>
* <p>
* {@link java.util.concurrent.CompletableFuture} is the type of the source provider or something
* that results in a CompletableFuture. Pagination source type is defined by the implementation.
* <p>
* Internally asynchronous pagination also have a {@link #isLoading() loading state} that
* tracks the loading state of the future and changes based on future completion.
* <p>
* <b><i> This is an internal inventory-framework API that should not be used from outside of
* this library. No compatibility guarantees are provided. </i></b>
*/
@ApiStatus.Internal
boolean isAsync();

/**
* If the pagination data is being loaded.
*
* <p><b><i> This API is experimental and is not subject to the general compatibility guarantees
* such API may be changed or may be removed completely in any further release. </i></b>
*
* @return Loading state of the pagination.
* Always <code>false</code> when {@link #isStatic()} is <code>true</code>.
*/
@ApiStatus.Experimental
boolean isLoading();

/**
* Gets all elements in a given page index based of the specified source.
*
* @param index The page index.
* @param pageSize Number of elements that each page can have.
* @param pagesCount Pre-calculated total number of pages available (set zero if not available).
* @param src The source to split.
* @return All elements in a page.
* @throws IndexOutOfBoundsException If the specified index is {@code < 0} or
* exceeds the pages count.
*/
static List<?> splitSourceForPage(int index, int pageSize, int pagesCount, List<?> src) {
if (src.isEmpty()) return Collections.emptyList();

if (src.size() <= pageSize) return new ArrayList<>(src);
if (index < 0 || (pagesCount > 0 && index > pagesCount))
throw new IndexOutOfBoundsException(String.format(
"Page index must be between the range of 0 and %d. Given: %d", pagesCount - 1, index));

final List<Object> contents = new LinkedList<>();
final int base = index * pageSize;
int until = base + pageSize;
if (until > src.size()) until = src.size();

for (int i = base; i < until; i++) contents.add(src.get(i));

return contents;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
import org.jetbrains.annotations.NotNull;

/**
* Represents an pagination element mapping operation that accepts three arguments and returns no result.
* Represents a pagination element mapping operation that accepts three arguments and returns no result.
* <p>
* This is a {@link FunctionalInterface functional interface} whose functional method is {@link #accept(Object, Object, int, Object)}.
* @param <Context> The type of the pagination context
* @param <Builder> The builder used to build the paginated element
*
* @param <C> The type of the pagination context
* @param <B> The builder used to build the paginated element
* @param <V> The value that represents the current element being paginated
*/
@FunctionalInterface
public interface PaginationElementConsumer<Context, Builder, V> {
public interface PaginationValueConsumer<C, B, V> {

/**
* Performs this operation on the given arguments.
Expand All @@ -20,5 +22,5 @@ public interface PaginationElementConsumer<Context, Builder, V> {
* @param index The index of the element being paginated in the pagination
* @param value The value that represents the current element being paginated
*/
void accept(@NotNull Context context, @NotNull Builder builder, int index, @NotNull V value);
void accept(@NotNull C context, @NotNull B builder, int index, @NotNull V value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,6 @@ public interface IFContext extends VirtualView, StateValueHost {
*/
void update();

/**
* Checks if a component positioned in a given index is marked for removal.
* <p>
* <b><i> This is an internal inventory-framework API that should not be used from outside of
* this library. No compatibility guarantees are provided. </i></b>
*
* @param componentIndex The index of the component to be checked if it's marked for removal.
* @return If the component in the specified index (if any) is marked for removal.
*/
@ApiStatus.Internal
boolean isMarkedForRemoval(int componentIndex);

/**
* Data defined when a context is created, usually this is data set when the context is
* opened for a viewer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,11 @@ public interface IFRenderContext extends IFConfinedContext {
*/
@NotNull
ViewContainer getContainer();

/**
* <b><i> This is an internal inventory-framework API that should not be used from outside of
* this library. No compatibility guarantees are provided. </i></b>
*/
@ApiStatus.Internal
boolean isRendered();
}

This file was deleted.

Loading