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 (entity:  string, predicate:  number | Object | null, resultIsRecordopt:  boolean) → * 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 (entity:  string, ID:  number) → 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 (eGroup:  string, code:  string) → string | null static

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

Arguments:

# getEnumItems (eGroup:  string) → array static

Get all enum items enum by eGroup.

Arguments:

# isTruncated (entity:  string) → boolean static

Whether the cached data of a subscribed entity is truncated to UB.LIMITS.lookupMaxRows records, so get can return nothing for a record which exists on the server. For a partitioned entity the cached data contains only the subscribed partitions.

Return:

false for an entity which has no loaded subscription

Arguments:
  
      const { lookups } = require('@unitybase/adminui-vue')
   if (lookups.isTruncated('tst_dictionary')) {
     // select the records absent in the cache from the server
   }
  

# refresh (entity:  string, attrsopt:  array.<string>, partitions:  array.<(number | string)>) → Promise.<void> static

Refresh lookups associated with specified entity

Arguments:

# subscribe (entity:  string, attrsopt:  array.<string>, partitionsopt:  array.<(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 (entity:  string) static

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

Arguments:

Types

# LookupSubscription inner

Properties

  • subscribes :  number

    Subscribe counter

  • onEntityChanged :  function

    Client local changes listener

  • attrs :  Set.<string>

    Lookup attributes

  • partitions opt :  Set.<string>

    Lookup partitions

  • data :  array.<object>

    Lookup data

  • mapById :  object
  • descriptionAttrName :  string
  • isTruncated :  boolean

    data of the last load is limited to UB.LIMITS.lookupMaxRows records