Options
All
  • Public
  • Public/Protected
  • All
Menu

Class QuerySet<T>

Type parameters

  • T

Hierarchy

  • QuerySet

Index

Constructors

constructor

  • new QuerySet(key?: (a: T) => string): QuerySet

Properties

currentTimestamp

currentTimestamp: integer = 0

Used to determine are the queries dirty or not.

data

data: Set<T> | Map<string, T>

Optional keyFn

keyFn: (a: T) => string

Type declaration

    • (a: T): string
    • Parameters

      • a: T

      Returns string

queries

queries: Map<string, QueryCache<T>> = new Map<string, QueryCache<T>>()

Methods

addItem

  • addItem(item: T, failCallback?: mRTypes.FailCallback<T>): boolean
  • Add an item to this QuerySet.

    Parameters

    • item: T

      The item needs to be added

    • Optional failCallback: mRTypes.FailCallback<T>

      Callback if the item was already in this QuerySet. This callback takes the item (inside the QuerySet) as input and returns whether the item in this QuerySet is modified or not by the callback function (e.g. buffs might want to +1 stack if already exists), and updates currentTimeStep if modification was done.

    Returns boolean

    If the item has been added (no duplicates).

addQuery

  • addQuery(name: string, filter?: mRTypes.FilterFunc<T>, sort?: mRTypes.CompareFunc<T>): void
  • Add a query to the QuerySet.

    Parameters

    • name: string

      Name for this query, will be used in query() function.

    • Optional filter: mRTypes.FilterFunc<T>

      filtering function as in Array.filter. It defines a criteia that whether an element in the query should be keeped or discarded. Returns false to filter out that element.

    • Optional sort: mRTypes.CompareFunc<T>

      compareFunction as in Array.sort. You want to return a negative value if lhs < rhs and vice versa. The result then will come with an ascending order if you do so (smaller first).

    Returns void

getAll

  • getAll(): IterableIterator<T>

has

  • has(item: T): boolean

liveQuery

  • liveQuery(filter?: mRTypes.FilterFunc<T>, sort?: mRTypes.CompareFunc<T>): Array<T>
  • Perform an online query with input functions.

    Parameters

    • Optional filter: mRTypes.FilterFunc<T>

      Filter function

    • Optional sort: mRTypes.CompareFunc<T>

      Compare function

    Returns Array<T>

query

  • query(name: string): Array<T>
  • Apply a query and return the results.

    Parameters

    • name: string

      The query needs to be performed.

    Returns Array<T>

    An array contains a sorted query results.

removeItem

  • removeItem(item: T): boolean

Generated using TypeDoc