Skip to content

Commit f877fe0

Browse files
committed
Documenting lifecycle of hooks, hooks
1 parent 4a762f7 commit f877fe0

File tree

1 file changed

+37
-13
lines changed

1 file changed

+37
-13
lines changed

README.md

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ $ npm install verto-cace-interface
3535

3636
**Usage**:
3737
```typescript
38-
3938
import { fetchContract } from 'verto-cace-interface';
4039

4140
fetchContract('t9T7DIOGxx4VWXoCEeYYarFYeERTpWIC1V3y-BPZgKE').then((result) => {
@@ -55,7 +54,6 @@ fetchContract('t9T7DIOGxx4VWXoCEeYYarFYeERTpWIC1V3y-BPZgKE').then((result) => {
5554

5655
**Usage**:
5756
```typescript
58-
5957
import { fetchBalanceByUserAddress } from 'verto-cace-interface';
6058

6159
fetchBalanceByUserAddress('vxUdiv2fGHMiIoek5E4l3M5qSuKCZtSaOBYjMRc94JU').then((result) => {
@@ -96,7 +94,6 @@ fetchBalancesForAddress('vxUdiv2fGHMiIoek5E4l3M5qSuKCZtSaOBYjMRc94JU').then((res
9694

9795
**Usage**:
9896
```typescript
99-
10097
import { fetchBalancesInContract } from 'verto-cace-interface';
10198

10299
fetchBalancesInContract('bQGRi3eO4p7S583mYYXDeVn5EvGPFMiMWd5WBWatteY').then((result) => {
@@ -118,7 +115,6 @@ fetchBalancesInContract('bQGRi3eO4p7S583mYYXDeVn5EvGPFMiMWd5WBWatteY').then((res
118115

119116
**Usage**:
120117
```typescript
121-
122118
import { fetchCollectionById } from 'verto-cace-interface';
123119

124120
fetchCollectionById('GirFtyB_PI4oQXhEFrHZLpFUqincHrDdDxPaQ1M8r00').then((result) => {
@@ -141,7 +137,6 @@ fetchCollectionById('GirFtyB_PI4oQXhEFrHZLpFUqincHrDdDxPaQ1M8r00').then((result)
141137

142138
**Usage**:
143139
```typescript
144-
145140
import { fetchContractsInUser } from 'verto-cace-interface';
146141

147142
fetchContractsInUser('vxUdiv2fGHMiIoek5E4l3M5qSuKCZtSaOBYjMRc94JU').then((result) => {
@@ -160,7 +155,6 @@ fetchContractsInUser('vxUdiv2fGHMiIoek5E4l3M5qSuKCZtSaOBYjMRc94JU').then((result
160155

161156
**Usage**:
162157
```typescript
163-
164158
import { fetchOwnershipByUsername } from 'verto-cace-interface';
165159

166160
fetchOwnershipByUsername('t8').then((result) => {
@@ -180,7 +174,6 @@ fetchOwnershipByUsername('t8').then((result) => {
180174

181175
**Usage**:
182176
```typescript
183-
184177
import { fetchTokenMetadata } from 'verto-cace-interface';
185178

186179
fetchTokenMetadata('bQGRi3eO4p7S583mYYXDeVn5EvGPFMiMWd5WBWatteY').then((result) => {
@@ -200,7 +193,6 @@ fetchTokenMetadata('bQGRi3eO4p7S583mYYXDeVn5EvGPFMiMWd5WBWatteY').then((result)
200193

201194
**Usage**:
202195
```typescript
203-
204196
import { fetchTokenStateMetadata } from 'verto-cace-interface';
205197

206198
fetchTokenStateMetadata('bQGRi3eO4p7S583mYYXDeVn5EvGPFMiMWd5WBWatteY').then((result) => {
@@ -222,7 +214,6 @@ fetchTokenStateMetadata('bQGRi3eO4p7S583mYYXDeVn5EvGPFMiMWd5WBWatteY').then((res
222214
**Usage**:
223215

224216
```typescript
225-
226217
import { fetchTokens } from 'verto-cace-interface';
227218

228219
fetchTokens().then((result) => {
@@ -245,7 +236,6 @@ fetchTokens().then((result) => {
245236

246237
**Usage**:
247238
```typescript
248-
249239
import { fetchRandomArtwork } from 'verto-cace-interface';
250240

251241
fetchRandomArtwork().then((result) => {
@@ -269,7 +259,6 @@ fetchRandomArtwork().then((result) => {
269259

270260
**Usage**:
271261
```typescript
272-
273262
import { fetchUserCreations } from 'verto-cace-interface';
274263

275264
fetchUserCreations('t8').then((result) => {
@@ -288,7 +277,6 @@ fetchUserCreations('t8').then((result) => {
288277

289278
**Usage**:
290279
```typescript
291-
292280
import { fetchUserMetadataByUsername } from 'verto-cace-interface';
293281

294282
fetchUserMetadataByUsername('t8').then((result) => {
@@ -304,7 +292,6 @@ fetchUserMetadataByUsername('t8').then((result) => {
304292

305293
**Usage**:
306294
```typescript
307-
308295
import { fetchUsers } from 'verto-cace-interface';
309296

310297
fetchUsers().then((result) => {
@@ -319,3 +306,40 @@ fetchUsers().then((result) => {
319306
})
320307
```
321308

309+
310+
## Hooks
311+
Hooks are a way to invoke functions and then invoke certain behaviors inside the cache system.
312+
313+
314+
### `cacheContractHook`
315+
316+
**Signature**:
317+
`cacheContractHook = async (action: () => Promise<any> | any,
318+
contractId?: string,
319+
refreshCommunityContract?: boolean)`
320+
321+
**Parameters**:
322+
*action*: Action to be called inside before executing the hook
323+
*contractId*: Contract to be cached right after `action` has finished its execution
324+
*refreshCommunityContract*: Whether the community contract should be updated after `action` has finished its execution
325+
326+
**Usage**:
327+
328+
```typescript
329+
import { cacheContractHook } from 'verto-cace-interface';
330+
331+
const currentContract: string = 'ABCD1234'
332+
333+
const executeOrder = await cacheContractHook(async () => {
334+
// Execute an order inside the exchange
335+
// Or do something different, maybe buy a car.
336+
return 'ORDER_SENT';
337+
}, currentContract, true);
338+
339+
assert(executeOrder === 'ORDER_SENT');
340+
```
341+
342+
**Lifecycle**:
343+
1) Execute `action` (if asynchronous, it will be awaited)
344+
2) Call Cache API to invoke caching of `contractId`
345+
3) if `refreshCommunityContract` is `true`, call Cache API to invoke caching of community contract

0 commit comments

Comments
 (0)