@ddd-qc/cell-proxy 0.9.3 → 0.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -59,20 +59,64 @@ A `ConductorAppProxy` can be created by providing an already existing `AppWebSoc
|
|
|
59
59
|
A subclass is expected to provide all the zome functions of a zome as directly callable methods.
|
|
60
60
|
Example: `profilesProxy.fetchAllProfiles()`
|
|
61
61
|
|
|
62
|
+
A `ZomeProxy` subclass must define the static field `DEFAULT_ZOME_NAME` which is the way to know at runtime for what zome this subclass is for.
|
|
62
63
|
|
|
63
|
-
|
|
64
|
+
|
|
65
|
+
# Example
|
|
66
|
+
|
|
67
|
+
Imagine you have a happ that has a dna that uses a profile zome.
|
|
68
|
+
|
|
69
|
+
## Example without subclassing ZomeProxy
|
|
70
|
+
```typescript
|
|
71
|
+
/** HCL of the role we want to use */
|
|
72
|
+
const hcl = new HCL("myHapp", "myRole");
|
|
73
|
+
/** Create AppProxy from provided local port */
|
|
74
|
+
const appProxy = await ConductorAppProxy.new(Number(process.env.HC_PORT));
|
|
75
|
+
/** Map out all the runnings cells for a Role in a happ. Required before calling createCellProxy */
|
|
76
|
+
await appProxy.fetchCells(hcl);
|
|
77
|
+
/** Create a CellProxy for the "myRole" role */
|
|
78
|
+
const profilesCellProxy = appProxy.createCellProxy(hcl);
|
|
79
|
+
/** Call zome function on the "profiles" zome */
|
|
80
|
+
const handles = await profilesCellProxy.callZome("profiles", "fetch_all_handles", null);
|
|
81
|
+
/** Dump all logs to console */
|
|
82
|
+
appProxy.dumpLogs();
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
## Example with ZomeProxy subclass
|
|
87
|
+
|
|
88
|
+
#### ZomeProxy subclass
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
export class ProfileZomeProxy extends ZomeProxy {
|
|
92
|
+
|
|
93
|
+
static readonly DEFAULT_ZOME_NAME: string = "profiles";
|
|
94
|
+
|
|
95
|
+
async getMyHandle(): Promise<string> {
|
|
96
|
+
return this.call('get_my_handle', null);
|
|
97
|
+
}
|
|
98
|
+
async setMyHandle(value: string): Promise<EntryHash> {
|
|
99
|
+
return this.callBlocking('set_my_handle', value);
|
|
100
|
+
}
|
|
101
|
+
async fetchAllHandles(): Promise<string[]> {
|
|
102
|
+
return this.call('fetch_all_handles', null);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
#### Use
|
|
64
108
|
|
|
65
109
|
```typescript
|
|
66
110
|
/** HCL of the cell we want to use */
|
|
67
|
-
const
|
|
111
|
+
const hcl = new HCL("myHapp", "myRole");
|
|
68
112
|
/** Create AppProxy from provided local port */
|
|
69
113
|
const appProxy = await ConductorAppProxy.new(Number(process.env.HC_PORT));
|
|
70
114
|
/** Map out all the runnings cells for a Role in a happ. Required before calling createCellProxy */
|
|
71
|
-
await appProxy.fetchCells(
|
|
115
|
+
await appProxy.fetchCells(hcl);
|
|
72
116
|
/** Create a CellProxy for the "profiles" role */
|
|
73
|
-
const
|
|
117
|
+
const cellProxy = appProxy.createCellProxy(hcl);
|
|
118
|
+
/** Create ZomeProxy */
|
|
119
|
+
const zomeProxy = ProfileZomeProxy(cellProxy);
|
|
74
120
|
/** Call zome function on the "profiles" zome */
|
|
75
|
-
const
|
|
76
|
-
/** Dump all logs to console */
|
|
77
|
-
appProxy.dumpLogs();
|
|
121
|
+
const handles = await zomeProxy.fetchAllHandles();
|
|
78
122
|
```
|