-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbasics.ts
36 lines (28 loc) · 1.24 KB
/
basics.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import type { Debugger, EvaluateCollectionType } from '../lib'
import { ClubRecord, DMap, FirestoreCollection, ID } from '../lib'
export const basicExampleSnippet = async (debug: Debugger) => {
/*
This example demonstrates the basic usages of lab resources.
By utilising Resource Control Class ex. Collection()
and Data Controls ex. ClubRecord() and DMap()
*/
// Initialise data collection
const evalColl = new FirestoreCollection<EvaluateCollectionType>('evaluate')
// Load data from the local cache and fetch if there was no cache.
const evalData = await evalColl.readFromCache(true)
if (!evalData) return
const evalRecords = new ClubRecord(evalData.getRecord())
// Compare keys with systemClubs using keyDiff() method.
const missing = ID.systemClubs.keyDiff(evalRecords.keys())
debug.dump(missing)
// Merge all sub clubs to main clubs.
const mainClubRecords = evalRecords.transformToMainClubs()
/*
Accessing a key using get() method
Note: get() method arg should be suggested by the editor (In this case is clubID).
*/
const clubEvalData = mainClubRecords.get('ก30901')
if (!clubEvalData) return
// Encapsulate the record with DMap and access its utility methods.
debug.dump(new DMap(clubEvalData).size())
}