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 aUB.connection.on(${entity}:changed
listener what change a local cache data when it's edited locally- after
subscribe
methodslookups.get
,lookups.getDescriptionById
,lookups.getEnum
can be used to get a value for description attribute (ar any other attribute added duringsubscribe
) 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
: stringEntity name
predicate
: number| Object| nullIn 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 entitydisplayAttribute
- if
// 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
# getEnum (eGroup: string, code: string) → string | null static
Get enum description by eGroup and code. Alias for .get('ubm_enum', { eGroup, code })
# getEnumItems (eGroup: string) → array static
Get all enum items enum by eGroup.
Arguments:
eGroup
: string
# refresh (entity: string, attrsopt: array.<string>, partitions: array.<(number | string)>) → Promise.<void> static
Refresh lookups associated with specified entity
# 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:
entity
: stringEntity name
Types
# LookupSubscription inner
Properties