diff --git a/flake.lock b/flake.lock index a925c72..eb9465f 100644 --- a/flake.lock +++ b/flake.lock @@ -1088,18 +1088,12 @@ } }, "crane_4": { - "inputs": { - "nixpkgs": [ - "holonix", - "nixpkgs" - ] - }, "locked": { - "lastModified": 1724537630, - "narHash": "sha256-gpqINM71zp3kw5XYwUXa84ZtPnCmLLnByuFoYesT1bY=", + "lastModified": 1725125250, + "narHash": "sha256-CB20rDD5eHikF6mMTTJdwPP1qvyoiyyw1RDUzwIaIF8=", "owner": "ipetkov", "repo": "crane", - "rev": "3e08f4b1fc9aaede5dd511d8f5f4ef27501e49b0", + "rev": "96fd12c7100e9e05fa1a0a5bd108525600ce282f", "type": "github" }, "original": { @@ -2365,11 +2359,11 @@ "nixpkgs-lib": "nixpkgs-lib_4" }, "locked": { - "lastModified": 1722555600, - "narHash": "sha256-XOQkdLafnb/p9ij77byFQjDf5m5QYl9b2REiVClC+x4=", + "lastModified": 1725234343, + "narHash": "sha256-+ebgonl3NbiKD2UD0x4BszCZQ6sTfL4xioaM49o5B3Y=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "8471fe90ad337a8074e957b69ca4d0089218391d", + "rev": "567b938d64d4b4112ee253b9274472dc3a346eb6", "type": "github" }, "original": { @@ -6269,11 +6263,11 @@ "rust-overlay": "rust-overlay_4" }, "locked": { - "lastModified": 1724935136, - "narHash": "sha256-TAxGCtBJXv/B6gdBD/TNisuRAs7tC9ati89DZr73ddo=", + "lastModified": 1725284617, + "narHash": "sha256-69pXRYx+Ipn2gZjgrKMcyrtE2L22eJPhcDsbotIMHQg=", "owner": "holochain", "repo": "holonix", - "rev": "f1a543d4188adbe6ff1cd9229120d5fe3cb96103", + "rev": "8ea11db1da23a4c02def11230de4ff4cad4cdda4", "type": "github" }, "original": { @@ -7797,14 +7791,14 @@ }, "nixpkgs-lib_4": { "locked": { - "lastModified": 1722555339, - "narHash": "sha256-uFf2QeW7eAHlYXuDktm9c25OxOyCoUOQmh5SZ9amE5Q=", + "lastModified": 1725233747, + "narHash": "sha256-Ss8QWLXdr2JCBPcYChJhz4xJm+h/xjl4G0c0XlP6a74=", "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/a5d394176e64ab29c852d03346c1fc9b0b7d33eb.tar.gz" + "url": "https://github.com/NixOS/nixpkgs/archive/356624c12086a18f2ea2825fed34523d60ccc4e3.tar.gz" }, "original": { "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/a5d394176e64ab29c852d03346c1fc9b0b7d33eb.tar.gz" + "url": "https://github.com/NixOS/nixpkgs/archive/356624c12086a18f2ea2825fed34523d60ccc4e3.tar.gz" } }, "nixpkgs-lib_40": { @@ -8671,11 +8665,11 @@ "webkitgtknixpkgs": "webkitgtknixpkgs" }, "locked": { - "lastModified": 1725284224, - "narHash": "sha256-AOAFmvp9MiulwPpzN7JGFPYwt/aYfSgRzgsAHN4XMqk=", + "lastModified": 1725288938, + "narHash": "sha256-d33FBrYCUjqM9WMI5MyLiw+L2eBo4KbqKasv78JsWoM=", "owner": "darksoil-studio", "repo": "p2p-shipyard", - "rev": "bfdaaae76cbada8b1ee722ef599b4b9becbac94a", + "rev": "ac810ad8a7aaa6a3515c02abd07b13906cd4cd90", "type": "github" }, "original": { @@ -9130,11 +9124,11 @@ "scaffolding": "scaffolding_9" }, "locked": { - "lastModified": 1725283608, - "narHash": "sha256-UuTu8rFvRSKznxWCXzGLzw1LqVlP8VXCDwh/F0JFJIA=", + "lastModified": 1725287721, + "narHash": "sha256-HRnj0Idoi/Kche+MyMFVMks6hg7orsV+VS8ypACZmGc=", "owner": "darksoil-studio", "repo": "roles", - "rev": "0447285387f203bb769631f6aeebdb4d6dc632f6", + "rev": "b6eb55cff89657597d4e456c1e4e3f91f75a5cfb", "type": "github" }, "original": { @@ -9948,11 +9942,11 @@ ] }, "locked": { - "lastModified": 1724898214, - "narHash": "sha256-4yMO9+Lsr3zqTf4clAGGag/bfNTmc/ITOXbJQcOEok4=", + "lastModified": 1725243956, + "narHash": "sha256-0A5ZP8uDCyBdYUzayZfy6JFdTefP79oZVAjyqA/yuSI=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "0bc2c784e3a6ce30a2ab1b9f47325ccbed13039f", + "rev": "a10c8092d5f82622be79ed4dd12289f72011f850", "type": "github" }, "original": { @@ -10237,11 +10231,11 @@ "scaffolding": "scaffolding_13" }, "locked": { - "lastModified": 1725274274, - "narHash": "sha256-VqL210AzzgjCbMrMFSElNlTDVybpki0RXhCtuJe6IAc=", + "lastModified": 1725284996, + "narHash": "sha256-inapUdMMvyEYFZ1v46ADfXdkg944URio7p9YZp6Oxak=", "owner": "holochain-open-dev", "repo": "templates", - "rev": "3284d285315ffb200a24ae20e9eea34aa992c415", + "rev": "5996a71e7a497d7e44b8e61824635ac81bbbc583", "type": "github" }, "original": { @@ -10712,11 +10706,11 @@ "scaffolding": "scaffolding_18" }, "locked": { - "lastModified": 1725284016, - "narHash": "sha256-gzpFgPLq2/WztyrbUvzw9vNUueDX7lEf8/jQrsdRGuw=", + "lastModified": 1725287262, + "narHash": "sha256-auAQ5b0mnvnU1HSXdRv9nuZi1o5xH3BZO2eXaGJeut4=", "owner": "darksoil-studio", "repo": "tasks", - "rev": "f059d7ba4852d6087704341fea6bcd653a19357a", + "rev": "dbf6bde9a904e56e72d6e3307b075c340899e2b4", "type": "github" }, "original": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 041a5f1..c623e0b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -145,8 +145,8 @@ importers: specifier: github:darksoil-studio/notifications#d23ad31d94ad18a7bd140272102c78fca96365cc&path:ui version: https://codeload.github.com/darksoil-studio/notifications/tar.gz/d23ad31d94ad18a7bd140272102c78fca96365cc#path:ui(@types/react@18.3.3) '@darksoil-studio/roles': - specifier: github:darksoil-studio/roles#0447285387f203bb769631f6aeebdb4d6dc632f6&path:ui - version: https://codeload.github.com/darksoil-studio/roles/tar.gz/0447285387f203bb769631f6aeebdb4d6dc632f6#path:ui(@types/react@18.3.3) + specifier: github:darksoil-studio/roles#b6eb55cff89657597d4e456c1e4e3f91f75a5cfb&path:ui + version: https://codeload.github.com/darksoil-studio/roles/tar.gz/b6eb55cff89657597d4e456c1e4e3f91f75a5cfb#path:ui(@types/react@18.3.3) '@holochain-open-dev/profiles': specifier: github:holochain-open-dev/profiles#6000dc6c04194429f2768517670366c411c4a03a&path:ui version: https://codeload.github.com/holochain-open-dev/profiles/tar.gz/6000dc6c04194429f2768517670366c411c4a03a#path:ui(@types/react@18.3.3) @@ -181,11 +181,11 @@ importers: specifier: github:darksoil-studio/notifications#d23ad31d94ad18a7bd140272102c78fca96365cc&path:ui version: https://codeload.github.com/darksoil-studio/notifications/tar.gz/d23ad31d94ad18a7bd140272102c78fca96365cc#path:ui(@types/react@18.3.3) '@darksoil-studio/roles': - specifier: github:darksoil-studio/roles#0447285387f203bb769631f6aeebdb4d6dc632f6&path:ui - version: https://codeload.github.com/darksoil-studio/roles/tar.gz/0447285387f203bb769631f6aeebdb4d6dc632f6#path:ui(@types/react@18.3.3) + specifier: github:darksoil-studio/roles#b6eb55cff89657597d4e456c1e4e3f91f75a5cfb&path:ui + version: https://codeload.github.com/darksoil-studio/roles/tar.gz/b6eb55cff89657597d4e456c1e4e3f91f75a5cfb#path:ui(@types/react@18.3.3) '@darksoil-studio/tasks': - specifier: github:darksoil-studio/tasks#f059d7ba4852d6087704341fea6bcd653a19357a&path:ui - version: https://codeload.github.com/darksoil-studio/tasks/tar.gz/f059d7ba4852d6087704341fea6bcd653a19357a#path:ui(@types/react@18.3.3) + specifier: github:darksoil-studio/tasks#dbf6bde9a904e56e72d6e3307b075c340899e2b4&path:ui + version: https://codeload.github.com/darksoil-studio/tasks/tar.gz/dbf6bde9a904e56e72d6e3307b075c340899e2b4#path:ui(@types/react@18.3.3) '@holochain-open-dev/elements': specifier: ^0.300.1 version: 0.300.1(@types/react@18.3.3) @@ -347,20 +347,16 @@ packages: '@dabh/diagnostics@2.0.3': resolution: {integrity: sha512-hrlQOIi7hAfzsMqlGSFyVucrx38O+j6wiGOf//H2ecvIEqYN4ADBSS2iLMh5UFyDunCNniUIPk/q3riFv45xRA==} - '@darksoil-studio/notifications@https://codeload.github.com/darksoil-studio/notifications/tar.gz/7b7ed790b6cb8a84a4b7c9911a532854c95c1049#path:ui': - resolution: {path: ui, tarball: https://codeload.github.com/darksoil-studio/notifications/tar.gz/7b7ed790b6cb8a84a4b7c9911a532854c95c1049} - version: 0.1.0 - '@darksoil-studio/notifications@https://codeload.github.com/darksoil-studio/notifications/tar.gz/d23ad31d94ad18a7bd140272102c78fca96365cc#path:ui': resolution: {path: ui, tarball: https://codeload.github.com/darksoil-studio/notifications/tar.gz/d23ad31d94ad18a7bd140272102c78fca96365cc} version: 0.1.0 - '@darksoil-studio/roles@https://codeload.github.com/darksoil-studio/roles/tar.gz/0447285387f203bb769631f6aeebdb4d6dc632f6#path:ui': - resolution: {path: ui, tarball: https://codeload.github.com/darksoil-studio/roles/tar.gz/0447285387f203bb769631f6aeebdb4d6dc632f6} + '@darksoil-studio/roles@https://codeload.github.com/darksoil-studio/roles/tar.gz/b6eb55cff89657597d4e456c1e4e3f91f75a5cfb#path:ui': + resolution: {path: ui, tarball: https://codeload.github.com/darksoil-studio/roles/tar.gz/b6eb55cff89657597d4e456c1e4e3f91f75a5cfb} version: 0.1.0 - '@darksoil-studio/tasks@https://codeload.github.com/darksoil-studio/tasks/tar.gz/f059d7ba4852d6087704341fea6bcd653a19357a#path:ui': - resolution: {path: ui, tarball: https://codeload.github.com/darksoil-studio/tasks/tar.gz/f059d7ba4852d6087704341fea6bcd653a19357a} + '@darksoil-studio/tasks@https://codeload.github.com/darksoil-studio/tasks/tar.gz/dbf6bde9a904e56e72d6e3307b075c340899e2b4#path:ui': + resolution: {path: ui, tarball: https://codeload.github.com/darksoil-studio/tasks/tar.gz/dbf6bde9a904e56e72d6e3307b075c340899e2b4} version: 0.1.0 '@esbuild/aix-ppc64@0.21.5': @@ -674,10 +670,6 @@ packages: resolution: {path: ui, tarball: https://codeload.github.com/holochain-open-dev/profiles/tar.gz/6000dc6c04194429f2768517670366c411c4a03a} version: 0.300.0 - '@holochain-open-dev/profiles@https://codeload.github.com/holochain-open-dev/profiles/tar.gz/f604eab07a69bb822bef2eafcddace5d5234d321#path:ui': - resolution: {path: ui, tarball: https://codeload.github.com/holochain-open-dev/profiles/tar.gz/f604eab07a69bb822bef2eafcddace5d5234d321} - version: 0.300.0 - '@holochain-open-dev/signals@0.300.6': resolution: {integrity: sha512-59szV9r2JARGfxbYA59ft9+CdlhiL/BEPNBxsBv7KEqfBZsRJq7gJZlhbV6dvD+ks5yDNtrxCEcmqQP6JSbktw==} @@ -2790,24 +2782,6 @@ snapshots: enabled: 2.0.0 kuler: 2.0.0 - '@darksoil-studio/notifications@https://codeload.github.com/darksoil-studio/notifications/tar.gz/7b7ed790b6cb8a84a4b7c9911a532854c95c1049#path:ui(@types/react@18.3.3)': - dependencies: - '@holochain-open-dev/elements': 0.300.1(@types/react@18.3.3) - '@holochain-open-dev/profiles': https://codeload.github.com/holochain-open-dev/profiles/tar.gz/f604eab07a69bb822bef2eafcddace5d5234d321#path:ui(@types/react@18.3.3) - '@holochain-open-dev/signals': 0.300.7(@types/react@18.3.3) - '@holochain-open-dev/utils': 0.300.2 - '@holochain/client': 0.17.1 - '@lit/context': 1.1.2 - '@lit/localize': 0.12.1 - '@mdi/js': 7.4.47 - '@msgpack/msgpack': 2.8.0 - '@shoelace-style/shoelace': 2.16.0(@types/react@18.3.3) - lit: 3.1.4 - transitivePeerDependencies: - - '@types/react' - - bufferutil - - utf-8-validate - '@darksoil-studio/notifications@https://codeload.github.com/darksoil-studio/notifications/tar.gz/d23ad31d94ad18a7bd140272102c78fca96365cc#path:ui(@types/react@18.3.3)': dependencies: '@holochain-open-dev/elements': 0.300.1(@types/react@18.3.3) @@ -2826,7 +2800,7 @@ snapshots: - bufferutil - utf-8-validate - '@darksoil-studio/roles@https://codeload.github.com/darksoil-studio/roles/tar.gz/0447285387f203bb769631f6aeebdb4d6dc632f6#path:ui(@types/react@18.3.3)': + '@darksoil-studio/roles@https://codeload.github.com/darksoil-studio/roles/tar.gz/b6eb55cff89657597d4e456c1e4e3f91f75a5cfb#path:ui(@types/react@18.3.3)': dependencies: '@darksoil-studio/notifications': https://codeload.github.com/darksoil-studio/notifications/tar.gz/d23ad31d94ad18a7bd140272102c78fca96365cc#path:ui(@types/react@18.3.3) '@holochain-open-dev/elements': 0.300.1(@types/react@18.3.3) @@ -2845,11 +2819,11 @@ snapshots: - bufferutil - utf-8-validate - '@darksoil-studio/tasks@https://codeload.github.com/darksoil-studio/tasks/tar.gz/f059d7ba4852d6087704341fea6bcd653a19357a#path:ui(@types/react@18.3.3)': + '@darksoil-studio/tasks@https://codeload.github.com/darksoil-studio/tasks/tar.gz/dbf6bde9a904e56e72d6e3307b075c340899e2b4#path:ui(@types/react@18.3.3)': dependencies: - '@darksoil-studio/notifications': https://codeload.github.com/darksoil-studio/notifications/tar.gz/7b7ed790b6cb8a84a4b7c9911a532854c95c1049#path:ui(@types/react@18.3.3) + '@darksoil-studio/notifications': https://codeload.github.com/darksoil-studio/notifications/tar.gz/d23ad31d94ad18a7bd140272102c78fca96365cc#path:ui(@types/react@18.3.3) '@holochain-open-dev/elements': 0.300.1(@types/react@18.3.3) - '@holochain-open-dev/profiles': https://codeload.github.com/holochain-open-dev/profiles/tar.gz/f604eab07a69bb822bef2eafcddace5d5234d321#path:ui(@types/react@18.3.3) + '@holochain-open-dev/profiles': https://codeload.github.com/holochain-open-dev/profiles/tar.gz/6000dc6c04194429f2768517670366c411c4a03a#path:ui(@types/react@18.3.3) '@holochain-open-dev/signals': 0.300.7(@types/react@18.3.3) '@holochain-open-dev/utils': 0.300.2 '@holochain/client': 0.17.1 @@ -3087,23 +3061,6 @@ snapshots: - bufferutil - utf-8-validate - '@holochain-open-dev/profiles@https://codeload.github.com/holochain-open-dev/profiles/tar.gz/f604eab07a69bb822bef2eafcddace5d5234d321#path:ui(@types/react@18.3.3)': - dependencies: - '@holochain-open-dev/elements': 0.300.1(@types/react@18.3.3) - '@holochain-open-dev/signals': 0.300.7(@types/react@18.3.3) - '@holochain-open-dev/utils': 0.300.2 - '@holochain/client': 0.17.1 - '@lit/context': 1.1.2 - '@lit/localize': 0.12.1 - '@mdi/js': 7.4.47 - '@msgpack/msgpack': 2.8.0 - '@shoelace-style/shoelace': 2.16.0(@types/react@18.3.3) - lit: 3.1.4 - transitivePeerDependencies: - - '@types/react' - - bufferutil - - utf-8-validate - '@holochain-open-dev/signals@0.300.6(@types/react@18.3.3)': dependencies: '@holochain-open-dev/utils': 0.300.2 diff --git a/tests/package.json b/tests/package.json index 04be2e8..9bc058a 100644 --- a/tests/package.json +++ b/tests/package.json @@ -6,7 +6,7 @@ }, "dependencies": { "@darksoil-studio/notifications": "github:darksoil-studio/notifications#d23ad31d94ad18a7bd140272102c78fca96365cc&path:ui", - "@darksoil-studio/roles": "github:darksoil-studio/roles#0447285387f203bb769631f6aeebdb4d6dc632f6&path:ui", + "@darksoil-studio/roles": "github:darksoil-studio/roles#b6eb55cff89657597d4e456c1e4e3f91f75a5cfb&path:ui", "@holochain-open-dev/profiles": "github:holochain-open-dev/profiles#6000dc6c04194429f2768517670366c411c4a03a&path:ui", "@holochain-open-dev/signals": "^0.300.7", "@holochain-open-dev/utils": "^0.300.2", diff --git a/ui/package.json b/ui/package.json index 76128c7..df9a7ee 100644 --- a/ui/package.json +++ b/ui/package.json @@ -13,8 +13,8 @@ }, "dependencies": { "@darksoil-studio/notifications": "github:darksoil-studio/notifications#d23ad31d94ad18a7bd140272102c78fca96365cc&path:ui", - "@darksoil-studio/roles": "github:darksoil-studio/roles#0447285387f203bb769631f6aeebdb4d6dc632f6&path:ui", - "@darksoil-studio/tasks": "github:darksoil-studio/tasks#f059d7ba4852d6087704341fea6bcd653a19357a&path:ui", + "@darksoil-studio/roles": "github:darksoil-studio/roles#b6eb55cff89657597d4e456c1e4e3f91f75a5cfb&path:ui", + "@darksoil-studio/tasks": "github:darksoil-studio/tasks#dbf6bde9a904e56e72d6e3307b075c340899e2b4&path:ui", "@holochain-open-dev/elements": "^0.300.1", "@holochain-open-dev/file-storage": "github:holochain-open-dev/file-storage#c503070441d29a1c448abf1b0949762fe4ef314d&path:ui", "@holochain-open-dev/profiles": "github:holochain-open-dev/profiles#6000dc6c04194429f2768517670366c411c4a03a&path:ui", diff --git a/ui/src/overlay-page.ts b/ui/src/overlay-page.ts index 627e7db..a477250 100644 --- a/ui/src/overlay-page.ts +++ b/ui/src/overlay-page.ts @@ -40,11 +40,17 @@ export class OverlayPage extends SignalWatcher(LitElement) { > ${this.title} -
- +
+
+
+
+ +
+
+
`; diff --git a/ui/src/plenty/orders/elements/create-producer-delivery.ts b/ui/src/plenty/orders/elements/create-producer-delivery.ts index a31d232..b54a5ca 100644 --- a/ui/src/plenty/orders/elements/create-producer-delivery.ts +++ b/ui/src/plenty/orders/elements/create-producer-delivery.ts @@ -97,7 +97,7 @@ export class CreateProducerDelivery extends SignalWatcher(LitElement) { callback(items, items.length); }; return html` -
+
{ const householdProductOrdersForThisProduct = new HoloHashMap< ActionHash, - ProductOrder + [number, ProductOrder] >(); - for (const [householdHash, householdOrder] of Array.from( + for (const [householdOrderHash, householdOrder] of Array.from( householdOrders.entries(), )) { for (const product of householdOrder.entry.products) { @@ -82,10 +82,19 @@ export class HouseholdsOrdersSummary extends SignalWatcher(LitElement) { encodeHashToBase64(product.original_product_hash) === encodeHashToBase64(productHash) ) { - householdProductOrdersForThisProduct.set( - householdHash, - product, - ); + const previousProductOrder = + householdProductOrdersForThisProduct.get( + householdOrder.entry.household_hash, + ); + if ( + !previousProductOrder || + previousProductOrder[0] < householdOrder.action.timestamp + ) { + householdProductOrdersForThisProduct.set( + householdOrder.entry.household_hash, + [householdOrder.action.timestamp, product], + ); + } } } } @@ -102,7 +111,7 @@ export class HouseholdsOrdersSummary extends SignalWatcher(LitElement) { householdProductOrdersForThisProduct.entries(), ).map(([householdHash, productOrder]) => ({ name: households.get(householdHash)!.entry.name, - amount: productOrder.amount, + amount: productOrder[1].amount, // total_price: ( // Math.round(productOrder.amount * price_with_vat * 100) / 100 // ).toFixed(2), @@ -110,7 +119,7 @@ export class HouseholdsOrdersSummary extends SignalWatcher(LitElement) { const amount = Array.from( householdProductOrdersForThisProduct.values(), - ).reduce((acc, next) => acc + next.amount, 0); + ).reduce((acc, next) => acc + next[1].amount, 0); return { name: product.entry.name, packaging: product.entry.packaging, @@ -307,11 +316,15 @@ export class HouseholdsOrdersSummary extends SignalWatcher(LitElement) { if (householdOrdersLatestVersion.status !== "completed") return householdOrdersLatestVersion; + const householdHashes = uniquify( + Array.from(householdOrdersLatestVersion.value.values()).map( + (ho) => ho.entry.household_hash, + ), + ); + const householdsLatestVersion = joinAsyncMap( - mapValues(householdOrdersLatestVersion.value, (ho) => - this.householdsStore.households - .get(ho.entry.household_hash) - .latestVersion.get(), + mapValues(slice(this.householdsStore.households, householdHashes), (h) => + h.latestVersion.get(), ), ); if (householdsLatestVersion.status !== "completed") diff --git a/ui/src/plenty/orders/elements/my-household-order.ts b/ui/src/plenty/orders/elements/my-household-order.ts index fbf334c..e2b6d29 100644 --- a/ui/src/plenty/orders/elements/my-household-order.ts +++ b/ui/src/plenty/orders/elements/my-household-order.ts @@ -334,22 +334,22 @@ export class MyHouseholdOrder extends SignalWatcher(LitElement) { .header=${msg("Maximum Available")} path="maximum_available" > - { - if (!model.value) - model.value = productsRandom.get(model.item.productHash); - - // TODO: actually set the value here - render( - html``, - root, - ); - }} - > + if (!model.value) + model.value = productsRandom.get(model.item.productHash); + + // TODO: actually set the value here + render( + html``, + root, + ); + }} + > --> { + // const myHousehold = this.householdStore.myHousehold.get(); + // if (myHousehold.status !== "completed" || !myHousehold.value) return; + // const orders = this.ordersForHousehold + // .get(myHousehold.value.householdHash) + // .get(); + // if (orders.status !== "completed") return; + // }); + } /** Order */ @@ -294,3 +288,39 @@ export class OrdersStore { }), ); } + +// NOTE: This scheduling logic is too basic to be useful. Do not copy/paste. +// This function would usually live in a library/framework, not application code +let pending = false; + +const w = new Signal.subtle.Watcher(() => { + if (!pending) { + pending = true; + queueMicrotask(() => { + pending = false; + for (const s of w.getPending()) s.get(); + w.watch(); + }); + } +}); + +// TODO: why do we need to use this complicated effect method? +// An effect effect Signal which evaluates to cb, which schedules a read of +// itself on the microtask queue whenever one of its dependencies might change +function effect(cb: any) { + let destructor: any; + const c = new Signal.Computed(() => { + if (typeof destructor === "function") { + destructor(); + } + destructor = cb(); + }); + w.watch(c); + c.get(); + return () => { + if (typeof destructor === "function") { + destructor(); + } + w.unwatch(c); + }; +}