com.phloxui
Version:
PhloxUI Ng2+ Framework
183 lines (182 loc) • 10.7 kB
TypeScript
import { INavigatee } from './INavigatee';
/**
* <p style="text-indent: 2em;">
* An interface for component class having navigation mechanism. For example, a menu bar having
* menu items to navigate through each page should implement this interface.
* </p>
*
* @typeparam T A type of <code>navigatee</code> item can be navigated by this <code>navigator</code>.
*
* @author shiorin, tee4cute
* @see [[INavigatee]]
*/
export interface INavigator<T extends INavigatee> {
/**
* <p style="text-indent: 1em;">
* Get <code>navigatee</code> ([[INavigatee]]) items can be navigated by this <code>navigator</code>.
* </p>
*
* @returns An array of <code>navigatee</code> ([[INavigatee]]) items can be navigated by this <code>navigator</code>.
*/
getItems(): T[];
/**
* <p style="text-indent: 1em;">
* Get number of <code>navigatee</code> ([[INavigatee]]) items can be navigated by this <code>navigator</code>.
* This must be the same value as [[getItems]]'s length.
* </p>
*
* @returns The <code>navigatee</code> ([[INavigatee]]) item count.
*/
getItemCount(): number;
/**
* <p style="text-indent: 1em;">
* Get current active <code>navigatee</code> ([[INavigatee]]) item. In most scenarios, this method should return the item
* representing the component (page) being displayed by this <code>navigator</code>.
* </p>
*
* @returns The current active <code>navigatee</code> ([[INavigatee]]) item being displayed by this <code>navigator</code>.
* Returns <code>null</code> if there is no current active item.
*/
getActiveItem(): T;
/**
* <p style="text-indent: 1em;">
* Get current active <code>navigatee</code> ([[INavigatee]]) item's index. The value returned from this method must be an
* index of array returning from method [[getItems]].
* </p>
*
* @returns The index of <code>navigatee</code> ([[INavigatee]]) item currently active. Returns <code>-1</code> if there is no
* current active item.
*/
getActiveIndex(): number;
/**
* <p style="text-indent: 1em;">
* Find the index of the given <code>navigatee</code> <code><b>item</b></code> in the items array returned from method [[getItems]].
* </p>
*
* @param item The <code>navigatee</code> item to find the index.
* @returns The index of the given <code><b>item</b></code>. Returns <code>-1</code> if not found.
*/
getItemIndex(item: T): number;
/**
* <p style="text-indent: 1em;">
* Find the index of <code>navigatee</code> item having <code>item name</code> ([[INavigatee.getName]]) matches the <code><b>name</b></code>
* passed as a parameter.
* </p>
*
* @param name The name of <code>navigatee</code> item to find the index.
* @returns The index of the <code>navigatee</code> item having <code>item name</code> ([[INavigatee.getName]]) matches the <code><b>name</b></code>
* passed as a parameter. Returns <code>-1</code> if not found.
*/
getItemIndexByName(name: string): number;
/**
* <p style="text-indent: 1em;">
* Get the <code>navigatee</code> item ([[INavigatee]]) by the given <code><b>idx</b></code>.
* </p>
*
* @param idx The <code>navigatee</code> item array index (starting from <code>0</code>).
* @returns The <code>navigatee</code> item ([[INavigatee]]) at the specified <code><b>idx</b></code>. If the specified <code><b>idx</b></code> is
* out of bound, this method will returns <code>null</code> without throwing any exceptions.
*/
getItemByIndex(idx: number): T;
/**
* <p style="text-indent: 1em;">
* Get the <code>navigatee</code> item ([[INavigatee]]) by the given item <code><b>name</b></code>.
* </p>
*
* @param name The name of <code>navigatee</code> item.
* @returns The <code>navigatee</code> item having the name ([[INavigatee.getName]]) matches the <code><b>name</b></code> passed as a parameter.
* Returns <code>null</code> if not found.
*/
getItemByName(name: string): T;
/**
* <p style="text-indent: 1em;">
* Set <code>navigatee</code> items ([[INavigatee]]) into this <code>navigator</code>.
* </p>
*
* @param items The <code>navigatee</code> items ([[INavigatee]]) to be set into this <code>navigator</code>.
*/
setItems(items: T[]): void;
/**
* <p style="text-indent: 1em;">
* Add a new <code>navigatee</code> <code><b>item</b></code> ([[INavigatee]]) into this <code>navigator</code>. This method will check that there already is the
* given <code><b>item</b></code> in this <code>navigator</code> or not. If yes, the <code><b>item</b></code> will not be added and this method
* will return <code>false</code>.
* </p>
*
* @param item A new <code>navigatee</code> item ([[INavigatee]]) to be added into this <code>navigator</code>.
* @returns Returns <code>true</code> if the given <code><b>item</b></code> is newly added into this <code>navigator</code>. Otherwise, returns
* <code>false</code>.
*/
addItem(item: T): boolean;
/**
* <p style="text-indent: 1em;">
* Remove the given <code>navigatee</code> <code><b>item</b></code> ([[INavigatee]]) from this <code>navigator</code>. If the given <code><b>item</b></code> is
* not currently in this <code>navigator</code>, this method will do nothing and return <code>false</code>.
* </p>
*
* @param item The <code>navigatee</code> item to be removed from this <code>navigator</code>.
* @returns Returns <code>true</code> if the given <code><b>item</b></code> is in this <code>navigator</code> and successfully removed. Otherwise, returns
* <code>false</code>.
*/
removeItem(item: T): boolean;
/**
* <p style="text-indent: 1em;">
* To check that the given <code>navigatee</code> <code><b>item</b></code> ([[INavigatee]]) is currently in this <code>navigator</code> or not.
* </p>
*
* @param item The <code>navigatee</code> item to be checked.
* @returns Returns <code>true</code> if the given <code><b>item</b></code> is currently in this <code>navigator</code>. Otherwise, returns <code>false</code>.
*/
containsItem(item: T): boolean;
/**
* <p style="text-indent: 1em;">
* Navigate this <code>navigator</code> to the given <code><b>item</b></code> ([[INavigatee]]). This method returns <code>Promise</code> to allow the navigation to be
* asynchronous. If the <code><b>item</b></code> is not in this <code>navigator</code>, this method will suddenly return resolved <code>Promise</code> having result value
* <code>"false"</code>. Otherwise, it'll return a <code>Promise</code> which will be resolved when the navigation is done with result value <code>"true"</code>. The
* navigated-to <code><b>item</b></code> will be set <code>active</code> flag to <code>true</code> and all other <code>navigatee</code> items in this <code>navigator</code>
* will be set <code>active</code> flag to <code>false</code>.
* </p>
*
* @param item The <code>navigatee</code> item to be navigated to.
* @param options The <code>options</code> object used for the navigation. This will depend on each navigator implementation.
* @returns A <code>Promise</code> which will be resolved when the navigation is done with result value <code>"true"</code>. If the given <code><b>item</b></code> is not
* in this <code>navigator</code>, this method will return a resolved <code>Promise</code> with result value <code>"false"</code>.
*/
navigateTo(item: T, options?: any): Promise<boolean>;
/**
* <p style="text-indent: 1em;">
* Navigate this <code>navigator</code> to the given <code>navigatee</code> item <code><b>idx</b></code>. This method returns <code>Promise</code> to allow the navigation to be
* asynchronous. If the given <code><b>idx</b></code> is out of bound, this method will suddenly return resolved <code>Promise</code> having result value <code>"false"</code>.
* Otherwise, it'll return a <code>Promise</code> which will be resolved when the navigation is done with result value <code>"true"</code>. The navigated-to <code><b>item</b></code>
* will be set <code>active</code> flag to <code>true</code> and all other <code>navigatee</code> items in this <code>navigator</code> will be set <code>active</code> flag to
* <code>false</code>.
* </p>
*
* @param idx The <code>navigatee</code> item <code><b>idx</b></code> to be navigated to.
* @param options The <code>options</code> object used for the navigation. This will depend on each navigator implementation.
* @returns A <code>Promise</code> which will be resolved when the navigation is done with result value <code>"true"</code>. If the given <code><b>idx</b></code> is out of
* bound, this method will return a resolved <code>Promise</code> with result value <code>"false"</code>.
*/
navigateToIndex(idx: number, options?: any): Promise<boolean>;
/**
* <p style="text-indent: 1em;">
* Navigate this <code>navigator</code> to the given <code>navigatee</code> item <code><b>name</b></code>. This method returns <code>Promise</code> to allow the navigation to be
* asynchronous. If the given item <code><b>name</b></code> does not exist, this method will suddenly return resolved <code>Promise</code> having result value <code>"false"</code>.
* Otherwise, it'll return a <code>Promise</code> which will be resolved when the navigation is done with result value <code>"true"</code>. The navigated-to <code><b>item</b></code>
* will be set <code>active</code> flag to <code>true</code> and all other <code>navigatee</code> items in this <code>navigator</code> will be set <code>active</code> flag to
* <code>false</code>.
* </p>
*
* @param name The <code>navigatee</code> item <code><b>name</b></code> to be navigated to.
* @param options The <code>options</code> object used for the navigation. This will depend on each navigator implementation.
* @returns A <code>Promise</code> which will be resolved when the navigation is done with result value <code>"true"</code>. If the given item <code><b>name</b></code> does not
* exist, this method will return a resolved <code>Promise</code> with result value <code>"false"</code>.
*/
navigateToName(name: string, options?: any): Promise<boolean>;
/**
* <p style="text-indent: 1em;">
* Reset this <code>navigator</code> to the original state.
* </p>
*/
reset(): void;
}