LokiEventEmitter is a minimalist version of EventEmitter. It enables any constructor that inherits EventEmitter to emit events and trigger listeners that have been added to the event through the on(event, callback) method

Type Parameters

Hierarchy

Constructors

Properties

addListener: (<F>(eventName: string | string[], listener: F) => F) = ...

Type declaration

    • <F>(eventName: string | string[], listener: F): F
    • Alias of LokiEventEmitter.prototype.on addListener(eventName, listener) - adds a listener to the queue of callbacks associated to an event

      Returns

      the index of the callback in the array of listeners for a particular event

      Memberof

      LokiEventEmitter

      Type Parameters

      • F extends ((...args: any[]) => any)

      Parameters

      • eventName: string | string[]

        the name(s) of the event(s) to listen to

      • listener: F

        callback function of listener to attach

      Returns F

asyncListeners: boolean = false

Prop

boolean determines whether or not the callbacks associated with each event should happen in an async fashion or not Default is false, which means events are synchronous

Memberof

LokiEventEmitter

cachedresultset: ResultSet<DT>
collection: Collection<DT>
events: {
    filter: any[];
    rebuild: any[];
    sort: any[];
}

Prop

a hashmap, with each property being an array of callbacks

Memberof

LokiEventEmitter

Type declaration

  • filter: any[]
  • rebuild: any[]
  • sort: any[]
filterPipeline: {
    type: string;
    uid: string | number;
    val: unknown;
}[]
name: string
options: Partial<DynamicViewOptions>
rebuildPending: boolean
resultdata: unknown[]
resultsdirty: boolean
resultset: ResultSet<DT>
save: any
sortCriteria: string[]
sortCriteriaSimple: {
    options: boolean | Partial<{
        desc: boolean;
        disableIndexIntersect: boolean;
        forceIndexIntersect: boolean;
        useJavascriptSorting: boolean;
    }>;
    propname: string;
}

Type declaration

  • options: boolean | Partial<{
        desc: boolean;
        disableIndexIntersect: boolean;
        forceIndexIntersect: boolean;
        useJavascriptSorting: boolean;
    }>
  • propname: string
sortDirty: boolean
sortFunction: ((a: any, b: any) => number)

Type declaration

    • (a: any, b: any): number
    • Parameters

      • a: any
      • b: any

      Returns number

Methods

  • Implementation detail. _addFilter() - Add the filter object to the end of view's filter pipeline and apply the filter to the resultset.

    Parameters

    • filter: any

      The filter object. Refer to applyFilter() for extra details.

    Returns void

  • Implementation detail. _indexOfFilterWithId() - Find the index of a filter in the pipeline, by that filter's ID.

    Returns

    : index of the referenced filter in the pipeline; -1 if not found.

    Parameters

    • uid: any

      The unique ID of the filter.

    Returns number

  • applyFilter() - Adds or updates a filter in the DynamicView filter pipeline

    Returns

    this DynamicView object, for further chain ops.

    Memberof

    DynamicView

    Parameters

    • filter: any

      A filter object to add to the pipeline. The object is in the format { 'type': filter_type, 'val', filter_param, 'uid', optional_filter_id }

    Returns DynamicView<DT>

  • applyFind() - Adds or updates a mongo-style query option in the DynamicView filter pipeline

    Returns

    this DynamicView object, for further chain ops.

    Memberof

    DynamicView

    Parameters

    • query: any

      A mongo-style query object to apply to pipeline

    • Optional uid: string | number

      Optional: The unique ID of this filter, to reference it in the future.

    Returns DynamicView<DT>

  • applySimpleSort() - Used to specify a property used for view translation.

    Example

    dv.applySimpleSort("name");
    

    Returns

    this DynamicView object, for further chain ops.

    Memberof

    DynamicView

    Parameters

    • propname: any

      Name of property by which to sort.

    • Optional options: Partial<{
          desc: boolean;
          disableIndexIntersect: boolean;
          forceIndexIntersect: boolean;
          useJavascriptSorting: boolean;
      }>

      boolean for sort descending or options object

    Returns DynamicView<DT>

  • applySort() - Used to apply a sort to the dynamic view

    Example

    dv.applySort(function(obj1, obj2) {
    if (obj1.name === obj2.name) return 0;
    if (obj1.name > obj2.name) return 1;
    if (obj1.name < obj2.name) return -1;
    });

    Returns

    this DynamicView object, for further chain ops.

    Memberof

    DynamicView

    Parameters

    • comparefun: any

      a javascript compare function used for sorting

    Returns DynamicView<DT>

  • applySortCriteria() - Allows sorting a resultset based on multiple columns.

    Example

    // to sort by age and then name (both ascending)
    dv.applySortCriteria(['age', 'name']);
    // to sort by age (ascending) and then by name (descending)
    dv.applySortCriteria(['age', ['name', true]);
    // to sort by age (descending) and then by name (descending)
    dv.applySortCriteria(['age', true], ['name', true]);

    Returns

    Reference to this DynamicView, sorted, for future chain operations.

    Memberof

    DynamicView

    Parameters

    • criteria: any

    Returns DynamicView<DT>

  • applyWhere() - Adds or updates a javascript filter function in the DynamicView filter pipeline

    Returns

    this DynamicView object, for further chain ops.

    Memberof

    DynamicView

    Parameters

    • fun: any

      A javascript filter function to apply to pipeline

    • Optional uid: string | number

      Optional: The unique ID of this filter, to reference it in the future.

    Returns DynamicView<DT>

  • branchResultset() - Makes a copy of the internal resultset for branched queries. Unlike this dynamic view, the branched resultset will not be 'live' updated, so your branched query should be immediately resolved and not held for future evaluation.

    Returns

    A copy of the internal resultset for branched queries.

    Memberof

    DynamicView

    Example

    var db = new loki('test');
    var coll = db.addCollection('mydocs');
    var dv = coll.addDynamicView('myview');
    var tx = [
    {
    type: 'offset',
    value: '[%lktxp]pageStart'
    },
    {
    type: 'limit',
    value: '[%lktxp]pageSize'
    }
    ];
    coll.addTransform('viewPaging', tx);

    // add some records

    var results = dv.branchResultset('viewPaging', { pageStart: 10, pageSize: 10 }).data();

    Parameters

    • Optional transform: string | []

      Optional name of collection transform, or an array of transform steps

    • Optional parameters: Record<string, any>

      optional parameters (if optional transform requires them)

    Returns any

  • count() - returns the number of documents representing the current DynamicView contents.

    Returns

    The number of documents representing the current DynamicView contents.

    Memberof

    DynamicView

    Returns number

  • data() - resolves and pending filtering and sorting, then returns document array as result.

    Returns

    An array of documents representing the current DynamicView contents.

    Memberof

    DynamicView

    Parameters

    • Optional options: object

      optional parameters to pass to resultset.data() if non-persistent

    Returns unknown[]

  • emit(eventName, data) - emits a particular event with the option of passing optional parameters which are going to be processed by the callback provided signatures match (i.e. if passing emit(event, arg0, arg1) the listener should take two parameters)

    Memberof

    LokiEventEmitter

    Parameters

    • eventName: string

      the name of the event

    • Optional data: unknown

      optional object passed with the event

    • Optional arg: any

    Returns void

  • evaluateDocument() - internal method for (re)evaluating document inclusion. Called by : collection.insert() and collection.update().

    Parameters

    • objIndex: any

      index of document to (re)run through filter pipeline.

    • isNew: any

      true if the document was just added to the collection.

    Returns void

  • getSort() - used to get the current sort

    Returns

    function (sortFunction) or array (sortCriteria) or object (sortCriteriaSimple)

    Returns string[] | ((a: any, b: any) => number) | {
        options: boolean | Partial<{
            desc: boolean;
            disableIndexIntersect: boolean;
            forceIndexIntersect: boolean;
            useJavascriptSorting: boolean;
        }>;
        propname: string;
    }

  • mapReduce() - data transformation via user supplied functions

    Returns

    The output of your reduceFunction

    Memberof

    DynamicView

    Parameters

    • mapFunction: any

      this function accepts a single document for you to transform and return

    • reduceFunction: any

      this function accepts many (array of map outputs) and returns single value

    Returns any

  • on(eventName, listener) - adds a listener to the queue of callbacks associated to an event

    Returns

    the index of the callback in the array of listeners for a particular event

    Memberof

    LokiEventEmitter

    Type Parameters

    • F extends ((...args: any[]) => any)

    Parameters

    • eventName: string | string[]

      the name(s) of the event(s) to listen to

    • listener: F

      callback function of listener to attach

    Returns F

  • performSortPhase() - invoked synchronously or asynchronously to perform final sort phase (if needed)

    Parameters

    • Optional options: Record<string, any>

    Returns void

  • queueRebuildEvent() - When the view is not sorted we may still wish to be notified of rebuild events. This event will throttle and queue a single rebuild event when batches of updates affect the view.

    Returns void

  • queueSortPhase : If the view is sorted we will throttle sorting to either : (1) passive - when the user calls data(), or (2) active - once they stop updating and yield js thread control

    Returns void

  • rematerialize() - internally used immediately after deserialization (loading) This will clear out and reapply filterPipeline ops, recreating the view. Since where filters do not persist correctly, this method allows restoring the view to state where user can re-apply those where filters.

    Returns

    This dynamic view for further chained ops.

    Memberof

    DynamicView

    Fires

    DynamicView.rebuild

    Parameters

    • options: any

      (Optional) allows specification of 'removeWhereFilters' option

    Returns DynamicView<DT>

  • removeDocument() - internal function called on collection.delete()

    Parameters

    • objIndex: any

      index of document to (re)run through filter pipeline.

    Returns void

  • removeFilter() - Remove the specified filter from the DynamicView filter pipeline

    Returns

    this DynamicView object, for further chain ops.

    Memberof

    DynamicView

    Parameters

    • uid: any

      The unique ID of the filter to be removed.

    Returns DynamicView<DT>

  • removeFilters() - Used to clear pipeline and reset dynamic view to initial state. Existing options should be retained.

    Memberof

    DynamicView

    Parameters

    • options: Record<string, any> = {}

      configure removeFilter behavior

    Returns void

  • removeListener() - removes the listener at position 'index' from the event 'eventName'

    Memberof

    LokiEventEmitter

    Parameters

    • eventName: string | string[]

      the name(s) of the event(s) which the listener is attached to

    • listener: ((...args: any[]) => any)

      the listener callback function to remove from emitter

        • (...args: any[]): any
        • Parameters

          • Rest ...args: any[]

          Returns any

    Returns void

Generated using TypeDoc