@ddd-qc/lit-happ 0.14.2 → 0.15.0
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/dist/DnaViewModel.d.ts +3 -1
- package/dist/DnaViewModel.js +5 -3
- package/dist/DnaViewModel.js.map +1 -1
- package/dist/ViewModel.d.ts +1 -1
- package/dist/ViewModel.js +2 -1
- package/dist/ViewModel.js.map +1 -1
- package/dist/ZomeViewModel.d.ts +6 -2
- package/dist/ZomeViewModel.js +10 -1
- package/dist/ZomeViewModel.js.map +1 -1
- package/package.json +1 -1
package/dist/DnaViewModel.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ declare const DnaViewModel_base: (abstract new (...args: any[]) => {
|
|
|
27
27
|
/**
|
|
28
28
|
* Abstract ViewModel for a DNA.
|
|
29
29
|
* It holds the CellProxy and all the ZomeViewModels of the DNA.
|
|
30
|
-
*
|
|
30
|
+
* It is expected to derive this class for each DNA and add extra logic at the DNA level.
|
|
31
31
|
* TODO: Split into RoleViewModel and CellViewModel (e.g. have call logs separated by role)
|
|
32
32
|
*/
|
|
33
33
|
export declare abstract class DnaViewModel extends DnaViewModel_base implements IDnaViewModel {
|
|
@@ -55,6 +55,8 @@ export declare abstract class DnaViewModel extends DnaViewModel_base implements
|
|
|
55
55
|
/** */
|
|
56
56
|
protected probeAllInner(): void;
|
|
57
57
|
/** */
|
|
58
|
+
zvmChanged(zvm: ZomeViewModel): void;
|
|
59
|
+
/** */
|
|
58
60
|
initializePerspectiveOffline(): Promise<void>;
|
|
59
61
|
/** */
|
|
60
62
|
initializePerspectiveOnline(): Promise<void>;
|
package/dist/DnaViewModel.js
CHANGED
|
@@ -6,7 +6,7 @@ import { RoleMixin } from "./roleMixin";
|
|
|
6
6
|
/**
|
|
7
7
|
* Abstract ViewModel for a DNA.
|
|
8
8
|
* It holds the CellProxy and all the ZomeViewModels of the DNA.
|
|
9
|
-
*
|
|
9
|
+
* It is expected to derive this class for each DNA and add extra logic at the DNA level.
|
|
10
10
|
* TODO: Split into RoleViewModel and CellViewModel (e.g. have call logs separated by role)
|
|
11
11
|
*/
|
|
12
12
|
export class DnaViewModel extends CellMixin(RoleMixin(ViewModel)) {
|
|
@@ -35,10 +35,10 @@ export class DnaViewModel extends CellMixin(RoleMixin(ViewModel)) {
|
|
|
35
35
|
for (const zvmDef of zvmDefs) {
|
|
36
36
|
let zvm;
|
|
37
37
|
if (Array.isArray(zvmDef)) {
|
|
38
|
-
zvm = new zvmDef[0](this._cellProxy, zvmDef[1]);
|
|
38
|
+
zvm = new zvmDef[0](this._cellProxy, this, zvmDef[1]);
|
|
39
39
|
}
|
|
40
40
|
else {
|
|
41
|
-
zvm = new zvmDef(this._cellProxy);
|
|
41
|
+
zvm = new zvmDef(this._cellProxy, this);
|
|
42
42
|
}
|
|
43
43
|
// TODO check zvm.zomeName exists in _cellProxy
|
|
44
44
|
this._zomeViewModels[zvm.zomeName] = zvm;
|
|
@@ -90,6 +90,8 @@ export class DnaViewModel extends CellMixin(RoleMixin(ViewModel)) {
|
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
/** */
|
|
93
|
+
zvmChanged(zvm) { }
|
|
94
|
+
/** */
|
|
93
95
|
async initializePerspectiveOffline() {
|
|
94
96
|
const all = [];
|
|
95
97
|
for (const [_name, zvm] of Object.entries(this._zomeViewModels)) {
|
package/dist/DnaViewModel.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DnaViewModel.js","sourceRoot":"","sources":["../src/DnaViewModel.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AACtC,OAAO,EAEL,oBAAoB,GAGrB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAGL,GAAG,EACS,SAAS,EACtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAC,SAAS,EAAe,MAAM,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AAG,GAAG,EAAE,CAAC;QACf,KAAK,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE;YAC/D,MAAM,CAAC,GAAG,GAAG,CAAC,2BAA2B,EAAE,CAAC;YAC5C,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACb;QACD,MAAM,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IAGD,iGAAiG;IACjG,KAAK,CAAC,iBAAiB;QACrB,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE;YACrD,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;YAC9B,IAAI;gBACF,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,gBAAgB;gBAC5E,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAA;aACpC;YAAC,OAAO,CAAC,EAAE;gBACV,OAAO,CAAC,IAAI,CAAC,0CAA0C,QAAQ,iEAAiE,CAAC,CAAA;gBACjI,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;aACnC;SACF;QACD,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAID,MAAM;IACN,QAAQ,CAAC,QAAmB;QAC1B,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACnC,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC;IAChC,CAAC;CACF","sourcesContent":["import {ZomeViewModel} from \"./ZomeViewModel\";\nimport {ReactiveElement} from \"lit\";\nimport {ViewModel} from \"./ViewModel\";\nimport {\n AdminWebsocket,\n GrantedFunctionsType,\n InstalledAppId,\n ZomeName,\n} from \"@holochain/client\";\nimport {DnaModifiersOptions, ZvmDef} from \"./definitions\";\nimport {createContext} from \"@lit-labs/context\";\nimport {\n CellProxy,\n ConductorAppProxy,\n HCL,\n Dictionary, CellMixin\n} from \"@ddd-qc/cell-proxy\";\nimport {RoleMixin, RoleSpecific} from \"./roleMixin\";\nimport {ContextKey} from \"@lit-labs/context/src/lib/context-key\";\n\n\n//export type IDnaViewModel = _DnaViewModel & ICellDef & typeof RoleSpecific;\n\n/** Interface specific to DnaViewModel class */\ninterface IDnaViewModel {\n dumpLogs(zomeName?: ZomeName): void;\n fetchAllEntryDefs(): Promise<Dictionary<[string, boolean][]>>;\n //get entryTypes(): Dictionary<[string, boolean][]>;\n //getZomeEntryDefs(zomeName: ZomeName): [string, boolean][] | undefined;\n //getZomeViewModel(zomeName: ZomeName): ZomeViewModel | undefined\n}\n\nexport type DvmConstructor = typeof RoleSpecific & {DNA_MODIFIERS: DnaModifiersOptions} & {\n new(host: ReactiveElement, proxy: ConductorAppProxy, idOrHcl: HCL | InstalledAppId): DnaViewModel;\n};\n\n\n/**\n * Abstract ViewModel for a DNA.\n * It holds the CellProxy and all the ZomeViewModels of the DNA.\n * A DNA is expected to derive this class and add extra logic at the DNA level.\n * TODO: Split into RoleViewModel and CellViewModel (e.g. have call logs separated by role)\n */\nexport abstract class DnaViewModel extends CellMixin(RoleMixin(ViewModel)) implements IDnaViewModel {\n\n /* private */ static ZVM_DEFS: ZvmDef[];\n static DNA_MODIFIERS: DnaModifiersOptions;\n\n /** Ctor */\n constructor(public readonly host: ReactiveElement, conductorAppProxy: ConductorAppProxy, idOrHcl: HCL | InstalledAppId) {\n super();\n if (typeof idOrHcl === 'object') {\n this.baseRoleName = idOrHcl.baseRoleName;\n this.hcl = idOrHcl;\n } else {\n this.hcl = new HCL(idOrHcl, this.baseRoleName);\n }\n const dvmCtor = (this.constructor as typeof DnaViewModel)\n const zvmDefs = dvmCtor.ZVM_DEFS;\n this._cellProxy = conductorAppProxy.getCellProxy(this.hcl); // WARN can throw error\n this._cell = this._cellProxy.cell;\n console.log(`DVM.ctor of ${this.baseRoleName}`, this._cellProxy.cell);\n /** Create all ZVMs for this DNA */\n for (const zvmDef of zvmDefs) {\n let zvm;\n if (Array.isArray(zvmDef)) {\n zvm = new zvmDef[0](this._cellProxy, zvmDef[1]);\n } else {\n zvm = new zvmDef(this._cellProxy);\n }\n // TODO check zvm.zomeName exists in _cellProxy\n this._zomeViewModels[zvm.zomeName] = zvm;\n this._zomeNames[zvmDef.constructor.name] = zvm.zomeName;\n }\n this.provideContext(host); // TODO move this to host.connectedCallback? e.g. change ViewModel to a ReactiveController\n }\n\n\n /** -- Fields -- */\n\n protected _cellProxy: CellProxy;\n /* ZomeName -> Zvm */\n protected _zomeViewModels: Dictionary<ZomeViewModel> = {};\n /* ZvmCtorName -> ZomeName */\n protected _zomeNames: Dictionary<ZomeName> = {};\n private _allEntryDefs: Dictionary<[string, boolean][]> = {};\n\n public readonly hcl: HCL;\n\n\n /** -- Getters -- */\n\n getZomeEntryDefs(zomeName: ZomeName): [string, boolean][] | undefined {return this._allEntryDefs[zomeName]}\n getZomeViewModel(zomeName: ZomeName): ZomeViewModel | undefined {return this._zomeViewModels[zomeName]}\n getZomeName(zvm: typeof ZomeViewModel): ZomeName | undefined { return this._zomeNames[zvm.constructor.name]}\n\n /** -- Methods -- */\n\n /** Override so we can provide context of all zvms */\n /*private*/ provideContext(host: ReactiveElement): void {\n //console.log(\"DVM.provideContext()\", host, this)\n super.provideContext(host);\n for (const zvm of Object.values(this._zomeViewModels)) {\n zvm.provideContext(host)\n }\n }\n\n\n getContext(): ContextKey<unknown, unknown> {return createContext<typeof this>('dvm/' + this.cell.name)};\n\n\n /** */\n async authorizeZomeCalls(adminWs: AdminWebsocket): Promise<void> {\n let allFnNames = [];\n for (const [_zomeName, zvm] of Object.entries(this._zomeViewModels)) {\n allFnNames = allFnNames.concat(zvm.zomeProxy.fnNames)\n }\n const grantedFns = { [GrantedFunctionsType.Listed]: allFnNames }\n try {\n console.log(\"authorizeSigningCredentials: \" + this.cell.hcl().toString(), allFnNames);\n await adminWs.authorizeSigningCredentials(this.cell.id, grantedFns);\n } catch(e) {\n console.warn(\"authorizeSigningCredentials FAILED.\", e);\n }\n // this._signingProps = getSigningCredentials(this.cellId);\n // console.log({signProps: this._signingProps})\n //\n // for (const [zomeName, zvm] of Object.entries(this._zomeViewModels)) {\n // zvm.zomeProxy.setSigningProps(this._signingProps);\n // }\n }\n\n\n /** */\n protected probeAllInner(): void {\n for (const [_name, zvm] of Object.entries(this._zomeViewModels)) {\n //console.log(\"Dvm.probeAll()\", name)\n zvm.probeAll();\n }\n }\n\n\n /** */\n async initializePerspectiveOffline(): Promise<void> {\n const all = [];\n for (const [_name, zvm] of Object.entries(this._zomeViewModels)) {\n const p = zvm.initializePerspectiveOffline();\n all.push(p);\n }\n await Promise.all(all);\n }\n\n\n /** */\n async initializePerspectiveOnline(): Promise<void> {\n const all = [];\n for (const [_name, zvm] of Object.entries(this._zomeViewModels)) {\n const p = zvm.initializePerspectiveOnline();\n all.push(p);\n }\n await Promise.all(all);\n }\n\n\n /** Maybe useless since the entry defs are in the integrity zome which is not represented here */\n async fetchAllEntryDefs(): Promise<Dictionary<[string, boolean][]>> {\n for (const zvm of Object.values(this._zomeViewModels)) {\n const zomeName = zvm.zomeName;\n try {\n const defs = await this._cellProxy.callEntryDefs(zomeName); // TODO optimize\n this._allEntryDefs[zomeName] = defs\n } catch (e) {\n console.warn(`Calling \"entry_defs()\" failed on zome \"${zomeName}\". Possibly because zome does not have any entry types defined.`)\n this._allEntryDefs[zomeName] = [];\n }\n }\n return this._allEntryDefs;\n }\n\n\n\n /** */\n dumpLogs(zomeName?: ZomeName): void {\n this._cellProxy.dumpLogs(zomeName);\n this._cellProxy.dumpSignals();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"DnaViewModel.js","sourceRoot":"","sources":["../src/DnaViewModel.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AACtC,OAAO,EAEL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AAC;QACnC,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC;IAChC,CAAC;CACF","sourcesContent":["import {ZomeViewModel} from \"./ZomeViewModel\";\nimport {ReactiveElement} from \"lit\";\nimport {ViewModel} from \"./ViewModel\";\nimport {\n AdminWebsocket,\n GrantedFunctionsType,\n InstalledAppId,\n ZomeName,\n} from \"@holochain/client\";\nimport {DnaModifiersOptions, ZvmDef} from \"./definitions\";\nimport {createContext} from \"@lit-labs/context\";\nimport {\n CellProxy,\n ConductorAppProxy,\n HCL,\n Dictionary, CellMixin\n} from \"@ddd-qc/cell-proxy\";\nimport {RoleMixin, RoleSpecific} from \"./roleMixin\";\nimport {ContextKey} from \"@lit-labs/context/src/lib/context-key\";\n\n\n//export type IDnaViewModel = _DnaViewModel & ICellDef & typeof RoleSpecific;\n\n/** Interface specific to DnaViewModel class */\ninterface IDnaViewModel {\n dumpLogs(zomeName?: ZomeName): void;\n fetchAllEntryDefs(): Promise<Dictionary<[string, boolean][]>>;\n //get entryTypes(): Dictionary<[string, boolean][]>;\n //getZomeEntryDefs(zomeName: ZomeName): [string, boolean][] | undefined;\n //getZomeViewModel(zomeName: ZomeName): ZomeViewModel | undefined\n}\n\nexport type DvmConstructor = typeof RoleSpecific & {DNA_MODIFIERS: DnaModifiersOptions} & {\n new(host: ReactiveElement, proxy: ConductorAppProxy, idOrHcl: HCL | InstalledAppId): DnaViewModel;\n};\n\n\n/**\n * Abstract ViewModel for a DNA.\n * It holds the CellProxy and all the ZomeViewModels of the DNA.\n * It is expected to derive this class for each DNA and add extra logic at the DNA level.\n * TODO: Split into RoleViewModel and CellViewModel (e.g. have call logs separated by role)\n */\nexport abstract class DnaViewModel extends CellMixin(RoleMixin(ViewModel)) implements IDnaViewModel {\n\n /* private */ static ZVM_DEFS: ZvmDef[];\n static DNA_MODIFIERS: DnaModifiersOptions;\n\n /** Ctor */\n constructor(public readonly host: ReactiveElement, conductorAppProxy: ConductorAppProxy, idOrHcl: HCL | InstalledAppId) {\n super();\n if (typeof idOrHcl === 'object') {\n this.baseRoleName = idOrHcl.baseRoleName;\n this.hcl = idOrHcl;\n } else {\n this.hcl = new HCL(idOrHcl, this.baseRoleName);\n }\n const dvmCtor = (this.constructor as typeof DnaViewModel)\n const zvmDefs = dvmCtor.ZVM_DEFS;\n this._cellProxy = conductorAppProxy.getCellProxy(this.hcl); // WARN can throw error\n this._cell = this._cellProxy.cell;\n console.log(`DVM.ctor of ${this.baseRoleName}`, this._cellProxy.cell);\n /** Create all ZVMs for this DNA */\n for (const zvmDef of zvmDefs) {\n let zvm;\n if (Array.isArray(zvmDef)) {\n zvm = new zvmDef[0](this._cellProxy, this, zvmDef[1]);\n } else {\n zvm = new zvmDef(this._cellProxy, this);\n }\n // TODO check zvm.zomeName exists in _cellProxy\n this._zomeViewModels[zvm.zomeName] = zvm;\n this._zomeNames[zvmDef.constructor.name] = zvm.zomeName;\n }\n this.provideContext(host); // TODO move this to host.connectedCallback? e.g. change ViewModel to a ReactiveController\n }\n\n\n /** -- Fields -- */\n\n protected _cellProxy: CellProxy;\n /* ZomeName -> Zvm */\n protected _zomeViewModels: Dictionary<ZomeViewModel> = {};\n /* ZvmCtorName -> ZomeName */\n protected _zomeNames: Dictionary<ZomeName> = {};\n private _allEntryDefs: Dictionary<[string, boolean][]> = {};\n\n public readonly hcl: HCL;\n\n\n /** -- Getters -- */\n\n getZomeEntryDefs(zomeName: ZomeName): [string, boolean][] | undefined {return this._allEntryDefs[zomeName]}\n getZomeViewModel(zomeName: ZomeName): ZomeViewModel | undefined {return this._zomeViewModels[zomeName]}\n getZomeName(zvm: typeof ZomeViewModel): ZomeName | undefined { return this._zomeNames[zvm.constructor.name]}\n\n /** -- Methods -- */\n\n /** Override so we can provide context of all zvms */\n /*private*/ provideContext(host: ReactiveElement): void {\n //console.log(\"DVM.provideContext()\", host, this)\n super.provideContext(host);\n for (const zvm of Object.values(this._zomeViewModels)) {\n zvm.provideContext(host)\n }\n }\n\n\n getContext(): ContextKey<unknown, unknown> {return createContext<typeof this>('dvm/' + this.cell.name)};\n\n\n /** */\n async authorizeZomeCalls(adminWs: AdminWebsocket): Promise<void> {\n let allFnNames = [];\n for (const [_zomeName, zvm] of Object.entries(this._zomeViewModels)) {\n allFnNames = allFnNames.concat(zvm.zomeProxy.fnNames)\n }\n const grantedFns = { [GrantedFunctionsType.Listed]: allFnNames }\n try {\n console.log(\"authorizeSigningCredentials: \" + this.cell.hcl().toString(), allFnNames);\n await adminWs.authorizeSigningCredentials(this.cell.id, grantedFns);\n } catch(e) {\n console.warn(\"authorizeSigningCredentials FAILED.\", e);\n }\n // this._signingProps = getSigningCredentials(this.cellId);\n // console.log({signProps: this._signingProps})\n //\n // for (const [zomeName, zvm] of Object.entries(this._zomeViewModels)) {\n // zvm.zomeProxy.setSigningProps(this._signingProps);\n // }\n }\n\n\n /** */\n protected probeAllInner(): void {\n for (const [_name, zvm] of Object.entries(this._zomeViewModels)) {\n //console.log(\"Dvm.probeAll()\", name)\n zvm.probeAll();\n }\n }\n\n /** */\n zvmChanged(zvm: ZomeViewModel): void {}\n\n\n /** */\n async initializePerspectiveOffline(): Promise<void> {\n const all = [];\n for (const [_name, zvm] of Object.entries(this._zomeViewModels)) {\n const p = zvm.initializePerspectiveOffline();\n all.push(p);\n }\n await Promise.all(all);\n }\n\n\n /** */\n async initializePerspectiveOnline(): Promise<void> {\n const all = [];\n for (const [_name, zvm] of Object.entries(this._zomeViewModels)) {\n const p = zvm.initializePerspectiveOnline();\n all.push(p);\n }\n await Promise.all(all);\n }\n\n\n /** Maybe useless since the entry defs are in the integrity zome which is not represented here */\n async fetchAllEntryDefs(): Promise<Dictionary<[string, boolean][]>> {\n for (const zvm of Object.values(this._zomeViewModels)) {\n const zomeName = zvm.zomeName;\n try {\n const defs = await this._cellProxy.callEntryDefs(zomeName); // TODO optimize\n this._allEntryDefs[zomeName] = defs\n } catch (e) {\n console.warn(`Calling \"entry_defs()\" failed on zome \"${zomeName}\". Possibly because zome does not have any entry types defined.`)\n this._allEntryDefs[zomeName] = [];\n }\n }\n return this._allEntryDefs;\n }\n\n\n\n /** */\n dumpLogs(zomeName?: ZomeName): void {\n this._cellProxy.dumpLogs(zomeName);\n this._cellProxy.dumpSignals();\n }\n}\n"]}
|
package/dist/ViewModel.d.ts
CHANGED
package/dist/ViewModel.js
CHANGED
|
@@ -78,11 +78,12 @@ export class ViewModel {
|
|
|
78
78
|
/** */
|
|
79
79
|
notifySubscribers() {
|
|
80
80
|
if (!this.hasChanged())
|
|
81
|
-
return;
|
|
81
|
+
return false;
|
|
82
82
|
for (const [host, propName] of this._providedHosts) {
|
|
83
83
|
host[propName] = this.perspective;
|
|
84
84
|
}
|
|
85
85
|
this._previousPerspective = this.perspective;
|
|
86
|
+
return true;
|
|
86
87
|
}
|
|
87
88
|
}
|
|
88
89
|
//# sourceMappingURL=ViewModel.js.map
|
package/dist/ViewModel.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ViewModel.js","sourceRoot":"","sources":["../src/ViewModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAKlD,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGpC,IAAK,mBAKJ;AALD,WAAK,mBAAmB;IACtB,sDAA+B,CAAA;IAC/B,kEAA2C,CAAA;IAC3C,gEAAyC,CAAA;IACzC,kDAA2B,CAAA;AAC7B,CAAC,EALI,mBAAmB,KAAnB,mBAAmB,QAKvB;AAED;;;;;;;;;;GAUG;AACF,MAAM,OAAgB,SAAS;IAA/B;QAIW,mBAAc,GAA4C,EAAE,CAAC;QAG7D,yBAAoB,GAAwB,mBAAmB,CAAC,aAAa,CAAC;QAG9E,gBAAW,GAAG,IAAI,KAAK,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"ViewModel.js","sourceRoot":"","sources":["../src/ViewModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,m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;IAC9E,CAAC;IAED,6BAA6B;IAE7B,MAAM;IACN,SAAS,CAAC,YAAoC,EAAE,QAAqB;QAChE,YAAoB,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC;QACnD,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC,CAAA;IACtD,CAAC;IAED,MAAM;IACN,WAAW,CAAC,SAAiC;QACzC,IAAI,KAAK,GAAI,CAAC,CAAC;QACf,KAAK,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,IAAI,CAAC,cAAc,EAAE;YACjD,IAAI,IAAI,KAAK,SAAS;gBAAE,MAAM;YAC9B,KAAK,IAAI,CAAC,CAAC;SACd;QACD,IAAI,KAAK,GAAG,CAAC,CAAC,EAAE;YACZ,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;SACxC;IACL,CAAC;IAED,MAAM;IACI,iBAAiB;QACzB,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;YAAE,OAAO,KAAK,CAAC;QACrC,KAAK,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,IAAI,CAAC,cAAc,EAAE;YACjD,IAAY,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC;SAC5C;QACD,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,WAAW,CAAA;QAC5C,OAAO,IAAI,CAAC;IACd,CAAC;CAEF","sourcesContent":["import {ContextProvider} from \"@lit-labs/context\";\nimport {ReactiveControllerHost, ReactiveElement} from \"lit\";\nimport {AppSignalCb} from \"@holochain/client\";\nimport {ContextKey} from \"@lit-labs/context/src/lib/context-key\";\n\nimport { Mutex } from 'async-mutex';\n\n\nenum InitializationState {\n Uninitialized = \"Uninitialized\",\n InitializingOffline = \"InitializingOffline\",\n InitializingOnline = \"InitializingOnline\",\n Initialized = \"Initialized\",\n}\n\n/**\n * ABC of a ViewModel.\n * It mediates the interaction between a View (CustomElements) and a Model (Zome / DNA).\n * It is an Observable meant to be observed by (Lit) ReactiveElements.\n * It is meant to be a singleton passed around by a (Lit) Context.\n * The ViewModel contains a perspective: All the data that a view can observe.\n * To update subscribers, it makes use of Lit's reactive properties.\n * When subscribing, a host must provide a reactive property that has the ViewModel's perspestives's type.\n * Hosts can trigger probing in order to get an updated perspective.\n * The perspective can be automatically updated by internal events.\n */\n export abstract class ViewModel {\n\n /** -- Fields -- */\n protected _previousPerspective?: unknown;\n protected _providedHosts: [ReactiveControllerHost, PropertyKey][] = [];\n protected _provider?: unknown; // FIXME type: ContextProvider<this.getContext()>;\n\n protected _initializationState: InitializationState = InitializationState.Uninitialized;\n\n\n protected _probeMutex = new Mutex();\n\n /** -- Abstract fields -- */\n\n abstract signalHandler?: AppSignalCb;\n\n\n /** -- Abstract methods -- */\n\n abstract getContext(): ContextKey<unknown, unknown>;\n /* Child class should implement with specific type */\n abstract get perspective(): unknown;\n\n /* (optional) Set perspective with data from the source-chain only */\n async initializePerspectiveOffline(): Promise<void> {}\n /* (optional) Set perspective with data from the DHT */\n async initializePerspectiveOnline(): Promise<void> {}\n /* (optional) Lets the observer trigger probing into the network in order to get an updated perspective */\n protected probeAllInner(): void {};\n\n /**\n * Mutex wrapping of probeAllInner: Don't call probeAll() during a probeAll()\n * Should not be async as we expect this to be long, so happs are expected to use signals instead if something changed.\n */\n probeAll(): void {\n // if (this._initializationState !== InitializationState.Initialized) {\n // console.warn(\"probeAll() called on unitialized ViewModel\");\n // return;\n // }\n if (this._probeMutex.isLocked()) {\n console.log(\"probeAll() call skipped. Reason: Already running.\");\n return;\n }\n this._probeMutex\n .acquire()\n .then(async (release) => {\n this.probeAllInner();\n release();\n });\n }\n\n /**\n * Return true if the perspective has changed. This will trigger an update on the observers\n * Child classes are expected to compare their latest constructed perspective (the one returned by this.perspective())\n * with this._previousPerspective.\n */\n protected abstract hasChanged(): boolean;\n\n\n /** -- Final methods -- */\n\n /** Set ContextProvider for host */\n provideContext(providerHost: ReactiveElement): void {\n console.log(`\\t\\tProviding context \"${this.getContext()}\" | in host `, providerHost);\n this._provider = new ContextProvider(providerHost, this.getContext(), this);\n }\n\n /** -- Observer pattern -- */\n\n /** */\n subscribe(providedHost: ReactiveControllerHost, propName: PropertyKey): void {\n (providedHost as any)[propName] = this.perspective;\n this._providedHosts.push([providedHost, propName])\n }\n\n /** */\n unsubscribe(candidate: ReactiveControllerHost): void {\n let index = 0;\n for (const [host, _propName] of this._providedHosts) {\n if (host === candidate) break;\n index += 1;\n }\n if (index > -1) {\n this._providedHosts.splice(index, 1);\n }\n }\n\n /** */\n protected notifySubscribers(): boolean {\n if (!this.hasChanged()) return false;\n for (const [host, propName] of this._providedHosts) {\n (host as any)[propName] = this.perspective;\n }\n this._previousPerspective = this.perspective\n return true;\n }\n\n}\n"]}
|
package/dist/ZomeViewModel.d.ts
CHANGED
|
@@ -2,8 +2,9 @@ import { CellProxy, ZomeProxy, ZomeProxyConstructor } from "@ddd-qc/cell-proxy";
|
|
|
2
2
|
import { ViewModel } from "./ViewModel";
|
|
3
3
|
import { AppSignalCb, ZomeName } from "@holochain/client";
|
|
4
4
|
import { ContextKey } from "@lit-labs/context/src/lib/context-key";
|
|
5
|
+
import { DnaViewModel } from "./DnaViewModel";
|
|
5
6
|
export type ZvmConstructor = {
|
|
6
|
-
new (proxy: CellProxy, zomeName?: ZomeName): ZomeViewModel;
|
|
7
|
+
new (proxy: CellProxy, dvmParent: DnaViewModel, zomeName?: ZomeName): ZomeViewModel;
|
|
7
8
|
};
|
|
8
9
|
/** (EXPERIMENTAL) Class Decorator */
|
|
9
10
|
export declare function zvm(zProxyCtor: typeof ZomeProxy): (ctor: Function) => void;
|
|
@@ -28,8 +29,11 @@ export declare abstract class ZomeViewModel extends ZomeViewModel_base {
|
|
|
28
29
|
/** Zome name */
|
|
29
30
|
static get DEFAULT_ZOME_NAME(): string;
|
|
30
31
|
zomeName: ZomeName;
|
|
32
|
+
private _dvmParent;
|
|
31
33
|
/** Ctor */
|
|
32
|
-
constructor(cellProxy: CellProxy, zomeName?: ZomeName);
|
|
34
|
+
constructor(cellProxy: CellProxy, dvmParent: DnaViewModel, zomeName?: ZomeName);
|
|
35
|
+
/** Notify DVM parent */
|
|
36
|
+
protected notifySubscribers(): boolean;
|
|
33
37
|
/** Filter signal by zome name */
|
|
34
38
|
private handleZomeSignal;
|
|
35
39
|
/** */
|
package/dist/ZomeViewModel.js
CHANGED
|
@@ -27,8 +27,9 @@ export class ZomeViewModel extends CellMixin(ViewModel) {
|
|
|
27
27
|
return this.ZOME_PROXY.DEFAULT_ZOME_NAME;
|
|
28
28
|
}
|
|
29
29
|
/** Ctor */
|
|
30
|
-
constructor(cellProxy, zomeName) {
|
|
30
|
+
constructor(cellProxy, dvmParent, zomeName) {
|
|
31
31
|
super();
|
|
32
|
+
this._dvmParent = dvmParent;
|
|
32
33
|
const zProxyCtor = this.getProxyConstructor();
|
|
33
34
|
if (!zProxyCtor) {
|
|
34
35
|
throw Error("ZOME_PROXY static field undefined in ZVM subclass " + this.constructor.name);
|
|
@@ -44,6 +45,14 @@ export class ZomeViewModel extends CellMixin(ViewModel) {
|
|
|
44
45
|
this._cell = cellProxy.cell;
|
|
45
46
|
cellProxy.addSignalHandler((signal) => this.handleZomeSignal(signal));
|
|
46
47
|
}
|
|
48
|
+
/** Notify DVM parent */
|
|
49
|
+
notifySubscribers() {
|
|
50
|
+
const hasChanged = super.notifySubscribers();
|
|
51
|
+
if (hasChanged) {
|
|
52
|
+
this._dvmParent.zvmChanged(this);
|
|
53
|
+
}
|
|
54
|
+
return hasChanged;
|
|
55
|
+
}
|
|
47
56
|
/** Filter signal by zome name */
|
|
48
57
|
handleZomeSignal(signal) {
|
|
49
58
|
//console.log("handleZomeSignal()", this.signalHandler, this.zomeName, signal.zome_name)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ZomeViewModel.js","sourceRoot":"","sources":["../src/ZomeViewModel.ts"],"names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,CAAC;YACzB,IAAI,CAAC,UAAU,GAAG,IAAI,UAAU,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;SAC9D;aAAM;YACH,IAAI,CAAC,UAAU,GAAG,IAAI,UAAU,CAAC,SAAS,CAAC,CAAC;YAC5C,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC;SACnD;QACD,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC;QAC5B,SAAS,CAAC,gBAAgB,CAAE,CAAC,MAAiB,EAAE,EAAE,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC;IACtF,CAAC;IAGD,wBAAwB;IACd,iBAAiB;QACvB,MAAM,UAAU,GAAG,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC7C,IAAI,UAAU,EAAE;YACZ,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;SACpC;QACD,OAAO,UAAU,CAAC;IACtB,CAAC;IAED,iCAAiC;IACzB,gBAAgB,CAAC,MAAiB;QACtC,wFAAwF;QACxF,IAAI,IAAI,CAAC,aAAa,IAAI,MAAM,CAAC,SAAS,IAAI,IAAI,CAAC,QAAQ,EAAE;YACzD,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;SAC9B;IACL,CAAC;IAED,MAAM;IACN,UAAU;QACN,MAAM,OAAO,GAAG,aAAa,CAAc,MAAM,GAAE,IAAI,CAAC,UAAU,CAAC,eAAe,GAAE,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAC5G,4CAA4C;QAC5C,OAAO,OAAO,CAAA;IAClB,CAAC;CACJ","sourcesContent":["import {createContext} from \"@lit-labs/context\";\nimport {CellProxy, ZomeProxy, ZomeProxyConstructor, CellMixin} from \"@ddd-qc/cell-proxy\";\nimport {ViewModel} from \"./ViewModel\";\nimport {AppSignalCb, ZomeName} from \"@holochain/client\";\nimport {AppSignal} from \"@holochain/client/lib/api/app/types\";\nimport {ContextKey} from \"@lit-labs/context/src/lib/context-key\";\nimport {DnaViewModel} from \"./DnaViewModel\";\n\nexport type ZvmConstructor = {new(proxy: CellProxy, dvmParent: DnaViewModel, zomeName?: ZomeName): ZomeViewModel} /*& typeof ZomeSpecific;*/\n\n/** (EXPERIMENTAL) Class Decorator */\nexport function zvm(zProxyCtor: typeof ZomeProxy) {\n return (ctor: Function) => {\n //let zvmCtor = (ctor as typeof ZomeViewModel);\n (ctor as any).ZOME_PROXY = zProxyCtor;\n //get zomeProxy(): DummyZomeProxy {return this._zomeProxy as DummyZomeProxy;}\n //(ctor as any).zomeProxy = function() {return (ctor as any)._zomeProxy as typeof zProxyFactory;}\n //(ctor as any).zomeProxy = (ctor as any)._zomeProxy as typeof zProxyFactory;\n }\n}\n\n\n/**\n * Abstract ViewModel for a Zome.\n * It extends a ViewModel by adding a ZomeProxy.\n * Views are required to use this in order to interact with the ZomeProxy.\n * The perspective is the data from the Zome that is transformed and enhanced in order to be consumed by a View.\n * It can be automatically updated by Signals or the Zome Scheduler.\n */\nexport abstract class ZomeViewModel extends CellMixin(ViewModel) {\n\n /** Zome proxy constructor */\n static ZOME_PROXY: ZomeProxyConstructor;\n protected _zomeProxy: ZomeProxy;\n /* Child class should implement with child proxy class as return type */\n abstract get zomeProxy(): ZomeProxy;\n getProxyConstructor(): ZomeProxyConstructor {\n return (this.constructor as typeof ZomeViewModel).ZOME_PROXY;\n }\n\n signalHandler?: AppSignalCb;\n\n /** Zome name */\n static get DEFAULT_ZOME_NAME(): string {\n return this.ZOME_PROXY.DEFAULT_ZOME_NAME;\n }\n zomeName!: ZomeName;\n\n private _dvmParent: DnaViewModel;\n\n /** Ctor */\n constructor(cellProxy: CellProxy, dvmParent: DnaViewModel, zomeName?: ZomeName) {\n super();\n this._dvmParent = dvmParent;\n const zProxyCtor = this.getProxyConstructor();\n if (!zProxyCtor) {\n throw Error(\"ZOME_PROXY static field undefined in ZVM subclass \" + this.constructor.name);\n }\n if (zomeName) {\n this.zomeName = zomeName;\n this._zomeProxy = new zProxyCtor(cellProxy, this.zomeName);\n } else {\n this._zomeProxy = new zProxyCtor(cellProxy);\n this.zomeName = this._zomeProxy.defaultZomeName;\n }\n this._cell = cellProxy.cell;\n cellProxy.addSignalHandler( (signal: AppSignal) => this.handleZomeSignal(signal));\n }\n\n\n /** Notify DVM parent */\n protected notifySubscribers(): boolean {\n const hasChanged = super.notifySubscribers();\n if (hasChanged) {\n this._dvmParent.zvmChanged(this);\n }\n return hasChanged;\n }\n\n /** Filter signal by zome name */\n private handleZomeSignal(signal: AppSignal) {\n //console.log(\"handleZomeSignal()\", this.signalHandler, this.zomeName, signal.zome_name)\n if (this.signalHandler && signal.zome_name == this.zomeName) {\n this.signalHandler(signal);\n }\n }\n\n /** */\n getContext(): ContextKey<unknown, unknown> {\n const context = createContext<typeof this>('zvm/'+ this._zomeProxy.defaultZomeName +'/' + this.cell.dnaHash)\n //console.log({contextType: typeof context})\n return context\n }\n}\n\n"]}
|