A reactive (in terms of Vue reactivity) entities data cache. To be used for entities with small (< 2000 rows) amount of data to lookup a display value for specified ID.

Module is injected into Vue.prototype as $lookups and exported as @unitybase/adminui-vue.lookups.

The flow:

  • subscribe method loads entity data (ID, description attribute and optionally addition attributes specified in attr array) to the reactive client-side store, and adds a UB.connection.on(${entity}:changed listener what change a local cache data when it's edited locally
  • after subscribe methods lookups.get, lookups.getDescriptionById, lookups.getEnum can be used to get a value for description attribute (ar any other attribute added during subscribe) by entity ID value (or by combination of entity attributes values)
  • when data for entity no longer needed unsubscribe should be called to free a resources

NOTE: lookups subscribes to ubm_enum on initialization, so lookups.getEnum can be used without addition to subscribe('umb_enum')

Methods

# get (entitystring, predicatenumber | Object | null, resultIsRecordoptboolean) → * static

Search for cached record inside in-memory entity values cache using predicate

Arguments:
  • entity: string

    Entity name

  • predicate: number| Object| null

    In case predicate is of type number - search by ID - O(1) In case predicate is Object - search for record what match all predicate attributes - O(N)

  • resultIsRecord = false: boolean

    • if true then return record as a result, in other cases - value of entity displayAttribute

  
      // get description attribute value for tst_dictionary with ID=123
   // since second argument is number perform O(1) lookup by ID
   const dictD = lookups.get('tst_dictionary', 123)
   // get description attribute value for tst_dictionary with code='code10'
   // if code is not unique - returns FIRST occurrence
   // complexity is O(N) where n is entity row count
   const dictCode10D = lookups.get('tst_dictionary', {code: 'code10'})
   // search predicate can be complex
   lookups.get('ubm_enum', {eGroup: 'AUDIT_ACTION', code: 'INSERT'})
   // if third parameter specified - use it as attribute name for returned value instead of description attribute
   const dict123UserName = lookups.get('tst_dictionary', 123, 'userID.fullName')
   // if third parameter is `true` - return an object with all attributes specified during `subscribe`
   const objWithAllSubscribedAttrs = lookups.get('tst_dictionary', 245671369782, true)
  

# getDescriptionById (entitystring, IDnumber) → string static

Fast O(1) lookup by ID. The same as lookups.get('entity_code', idAsNumber) but returns '---' in case row with specified ID is not found

Return:

Value if description attribute or '---' in case record not found

Arguments:

# getEnum (eGroupstring, codestring) → string | null static

Get enum description by eGroup and code. Alias for .get('ubm_enum', { eGroup, code })

Arguments:

# getEnumItems (eGroupstring) → array static

Get all enum items enum by eGroup.

Arguments:

# refresh (entitystring, attrsoptarray.<string>, partitionsarray.<(number | string)>) → Promise.<void> static

Refresh lookups associated with specified entity

Arguments:

# subscribe (entitystring, attrsoptarray.<string>, partitionsoptarray.<(number | string)>) → Promise.<void> static

Subscribes to the local (in the current browser) entity changes. First call to subscribe for entity loads it data into client

Arguments:
  
      const App = require('@unitybase/adminui-vue')
   await App.lookups.subscribe('tst_dictionary', ['code', 'userID'])
  

# unsubscribe (entitystring) static

Unsubscribe from entity changes. In case this is a last subscriber, data cache for entity is cleaned

Arguments:

Types

# LookupSubscription inner

Properties