Options
All
  • Public
  • Public/Protected
  • All
Menu

Class DynamicView<T>

DynamicView class is a versatile 'live' view class which can have filters and sorts applied. Collection.addDynamicView(name) instantiates this DynamicView object and notifies it whenever documents are add/updated/removed so it can remain up-to-date. (chainable)

example

let mydv = mycollection.addDynamicView('test'); // default is non-persistent mydv.applyFind({ 'doors' : 4 }); mydv.applyWhere(function(obj) { return obj.name === 'Toyota'; }); let results = mydv.data();

extends

LokiEventEmitter

see

{@link Collection#addDynamicView} to construct instances of DynamicView

param

the data type

param

nested properties of data type

Type parameters

  • T: any

Hierarchy

Index

Type aliases

Static Filter

Filter: object | object

Static SortPriority

SortPriority: "passive" | "active"

Constructors

constructor

Properties

Protected _asyncListeners

_asyncListeners: boolean = false

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

Protected _events

_events: object

A map, with each property being an array of callbacks.

name

name: string

Methods

addListener

  • addListener(eventName: string | string[], listener: Function): Function

applyFilter

  • applyFilter(filter: Filter<T>): this
  • Adds or updates a filter in the DynamicView filter pipeline

    Parameters

    • filter: Filter<T>

      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 this

    this DynamicView object, for further chain ops.

applyFind

  • applyFind(query: object, uid?: string | number): this
  • applyFind() - Adds or updates a mongo-style query option in the DynamicView filter pipeline

    Parameters

    • query: object

      A mongo-style query object to apply to pipeline

    • Default value uid: string | number = ""

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

    Returns this

    this DynamicView object, for further chain ops.

applySimpleSort

  • Used to specify a property used for view translation.

    example

    dv.applySimpleSort("name");

    Parameters

    • field: keyof T

      the field name

    • Default value options: boolean | SimpleSortOptions = false

      boolean for sort descending or options object

    Returns this

    this DynamicView object, for further chain ops.

applySort

  • applySort(comparefun: function): this
  • 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; });

    Parameters

    • comparefun: function

      a javascript compare function used for sorting

        • (lhs: Doc<T>, rhs: Doc<T>): number
        • Parameters

          Returns number

    Returns this

    this DynamicView object, for further chain ops.

applySortByScoring

  • applySortByScoring(ascending?: boolean): this
  • Used to apply a sort by the latest full-text-search scoring.

    Parameters

    • Default value ascending: boolean = false

    Returns this

applySortCriteria

  • applySortCriteria(criteria: (keyof T | Object)[]): this
  • 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]]);

    Parameters

    • criteria: (keyof T | Object)[]

      array of property names or subarray of [propertyname, isdesc] used evaluate sort order

    Returns this

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

applyWhere

  • applyWhere(fun: function, uid?: string | number): this
  • Adds or updates a javascript filter function in the DynamicView filter pipeline

    Parameters

    • fun: function

      A javascript filter function to apply to pipeline

        • (obj: Doc<T>): boolean
        • Parameters

          Returns boolean

    • Optional uid: string | number

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

    Returns this

    this DynamicView object, for further chain ops.

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.

    Parameters

    • Optional transform: string | Transform<T>[]

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

    • Optional parameters: object

      optional parameters (if optional transform requires them)

    Returns ResultSet<T>

    A copy of the internal ResultSet for branched queries.

commit

  • commit(): this

count

  • count(): number
  • Returns the number of documents representing the current DynamicView contents.

    Returns number

    The number of documents representing the current DynamicView contents.

data

  • Resolves and pending filtering and sorting, then returns document array as result.

    Parameters

    • Default value options: DataOptions = {}

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

    Returns Doc<T>[]

    An array of documents representing the current DynamicView contents.

Protected emit

  • emit(eventName: string, ...data: any[]): void
  • 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)

    Parameters

    • eventName: string

      the name of the event

    • Rest ...data: any[]

      optional object passed with the event

    Returns void

getScoring

  • getScoring(): Scorer.ScoreResult[]

mapReduce

  • mapReduce<U1, U2>(mapFunction: function, reduceFunction: function): U2
  • Data transformation via user supplied functions

    Type parameters

    • U1

    • U2

    Parameters

    • mapFunction: function

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

        • (item: T, index: number, array: T[]): U1
        • Parameters

          • item: T
          • index: number
          • array: T[]

          Returns U1

    • reduceFunction: function

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

        • (array: U1[]): U2
        • Parameters

          • array: U1[]

          Returns U2

    Returns U2

    The output of your reduceFunction

on

  • on(eventName: string | string[], listener: Function): Function
  • Adds a listener to the queue of callbacks associated to an event

    Parameters

    • eventName: string | string[]

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

    • listener: Function

      callback function of listener to attach

    Returns Function

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

reapplyFilters

  • reapplyFilters(): this
  • Reapply all the filters in the current pipeline.

    Returns this

    this DynamicView object, for further chain ops.

removeFilter

  • removeFilter(uid: string | number): this
  • Remove the specified filter from the DynamicView filter pipeline

    Parameters

    • uid: string | number

      The unique ID of the filter to be removed.

    Returns this

    this DynamicView object, for further chain ops.

removeFilters

  • removeFilters(__namedParameters?: object): void
  • Used to clear pipeline and reset dynamic view to initial state. Existing options should be retained.

    Parameters

    • Default value __namedParameters: object = {}

    Returns void

removeListener

  • removeListener(eventName: string | string[], listener: Function): void
  • Removes the listener at position 'index' from the event 'eventName'

    Parameters

    • eventName: string | string[]

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

    • listener: Function

      the listener callback function to remove from emitter

    Returns void

rollback

  • rollback(): this

startTransaction

  • startTransaction(): this
  • Marks the beginning of a transaction.

    Returns this

    this DynamicView object, for further chain ops.

toJSON

Static fromJSONObject

Generated using TypeDoc