@ddd-qc/lit-happ 0.20.1 → 0.20.7

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/ViewModel.js CHANGED
@@ -79,7 +79,8 @@ export class ViewModel {
79
79
  notifySubscribers() {
80
80
  if (!this.hasChanged())
81
81
  return false;
82
- this._previousPerspective = structuredClone(this.perspective);
82
+ //this._previousPerspective = structuredClone(this.perspective);
83
+ this._previousPerspective = this.perspective;
83
84
  for (const [host, propName] of this._providedHosts) {
84
85
  host[propName] = this._previousPerspective;
85
86
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ViewModel.js","sourceRoot":"","sources":["../src/ViewModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,eAAe,EAAC,MAAM,cAAc,CAAC;AAItD,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;QAGvE,0FAA0F;QAGhF,gBAAW,GAAG,IAAI,KAAK,EAAE,CAAC;IAuFtC,CAAC;IA1EC,qEAAqE;IACrE,KAAK,CAAC,4BAA4B,KAAmB,CAAC;IACtD,uDAAuD;IACvD,KAAK,CAAC,2BAA2B,KAAmB,CAAC;IACrD,0GAA0G;IAChG,aAAa,KAAU,CAAC;IAAA,CAAC;IAEnC;;;OAGG;IACH,QAAQ;QACN,uEAAuE;QACvE,gEAAgE;QAChE,YAAY;QACZ,IAAI;QACJ,IAAI,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,EAAE;YAC/B,OAAO,CAAC,GAAG,CAAC,mDAAmD,CAAC,CAAC;YAC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CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,IAAI,CAAC,cAAc,EAAE;YACjD,IAAY,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,oBAAoB,CAAC;SACrD;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CAEF","sourcesContent":["import {Context, ContextProvider} from \"@lit/context\";\nimport {ReactiveControllerHost, ReactiveElement} from \"lit\";\nimport {AppSignalCb} from \"@holochain/client\";\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(): Context<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 this._previousPerspective = structuredClone(this.perspective);\n for (const [host, propName] of this._providedHosts) {\n (host as any)[propName] = this._previousPerspective;\n }\n return true;\n }\n\n}\n"]}
1
+ {"version":3,"file":"ViewModel.js","sourceRoot":"","sources":["../src/ViewModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,eAAe,EAAC,MAAM,cAAc,CAAC;AAItD,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGpC,IAAK,mBAKJ;AALD,WAAK,mBAAmB;IACtB,sDAA+B,CAAA;IAC/B,kEAA2C,CAAA;IAC3C,gEA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AAY,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;QACnC,gEAAgE;QAChE,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,WAAW,CAAC;QAC7C,KAAK,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,IAAI,CAAC,cAAc,EAAE;YACnD,IAAY,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,oBAAoB,CAAC;SACrD;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CAEF","sourcesContent":["import {Context, ContextProvider} from \"@lit/context\";\nimport {ReactiveControllerHost, ReactiveElement} from \"lit\";\nimport {AppSignalCb} from \"@holochain/client\";\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(): Context<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 //this._previousPerspective = structuredClone(this.perspective);\n this._previousPerspective = this.perspective;\n for (const [host, propName] of this._providedHosts) {\n (host as any)[propName] = this._previousPerspective;\n }\n return true;\n }\n\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ddd-qc/lit-happ",
3
- "version": "0.20.1",
3
+ "version": "0.20.7",
4
4
  "description": "MVVM Framework for holochain apps using Lit",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",