Skip to content

Commit

Permalink
feat(reference): demo
Browse files Browse the repository at this point in the history
  • Loading branch information
njfamirm authored and alimd committed Dec 26, 2023
1 parent ff8ae62 commit ed82924
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions packages/store-reference/demo/collection.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import {createLogger} from '@alwatr/logger';
import {Region, StoreFileExtension} from '@alwatr/store-types';

import {CollectionReference} from '../dist/main.mjs';

const logger = createLogger('demo-collection');

function updateCollectionCallback(from) {
logger.logMethodArgs?.('updateCollectionCallback', from.id);
}

const collection = CollectionReference.newRefFromData(
{
name: 'user-order',
region: Region.PerUser,
ownerId: 'user_x_id',
extension: StoreFileExtension.Json,
},
updateCollectionCallback,
);

logger.logProperty?.('collection.id', collection.id);
logger.logProperty?.('collection.path', collection.path);

const orderId1 = 'order1';

logger.logProperty?.('order1.exists', collection.exists(orderId1));
collection.create(orderId1, {
itemList: ['item1', 'item2'],
price: 100,
});

logger.logProperty?.('order1.data', collection.get(orderId1));

collection.set(orderId1, {
itemList: ['item1', 'item2'],
price: 200,
});

logger.logProperty?.('order1.data', collection.get(orderId1));

collection.update(orderId1, {
price: 300,
});

logger.logProperty?.('order1.data', collection.get(orderId1));

logger.logProperty?.('order1.meta', collection.meta(orderId1));

collection.delete(orderId1);

collection.append({itemList: ['item3', 'item4'], price: 400});

logger.logProperty?.('user-order.values', collection.values());

0 comments on commit ed82924

Please sign in to comment.