From c7612e2ded6a1f62e1637bb62e41047b52d6949e Mon Sep 17 00:00:00 2001 From: Tim Date: Fri, 26 Jan 2024 09:46:34 +1300 Subject: [PATCH] don't treat Option and Either as effects --- .changeset/witty-mangos-shake.md | 5 ++ package.json | 4 +- packages/rx-react/package.json | 2 +- packages/rx-vue/package.json | 2 +- packages/rx/package.json | 2 +- packages/rx/src/Rx.ts | 15 +++- packages/rx/test/Rx.test.ts | 14 ++- pnpm-lock.yaml | 146 ++++++++++++++++++++----------- 8 files changed, 130 insertions(+), 60 deletions(-) create mode 100644 .changeset/witty-mangos-shake.md diff --git a/.changeset/witty-mangos-shake.md b/.changeset/witty-mangos-shake.md new file mode 100644 index 0000000..f09f60f --- /dev/null +++ b/.changeset/witty-mangos-shake.md @@ -0,0 +1,5 @@ +--- +"@effect-rx/rx": patch +--- + +don't treat Option and Either as effects diff --git a/package.json b/package.json index c07c1b2..16ff4ce 100644 --- a/package.json +++ b/package.json @@ -18,8 +18,8 @@ "lint-fix": "pnpm lint --fix" }, "devDependencies": { - "@babel/cli": "^7.23.4", - "@babel/core": "^7.23.7", + "@babel/cli": "^7.23.9", + "@babel/core": "^7.23.9", "@babel/plugin-transform-export-namespace-from": "^7.23.4", "@babel/plugin-transform-modules-commonjs": "^7.23.3", "@changesets/changelog-github": "^0.5.0", diff --git a/packages/rx-react/package.json b/packages/rx-react/package.json index 65ae8c9..df75aa8 100644 --- a/packages/rx-react/package.json +++ b/packages/rx-react/package.json @@ -24,7 +24,7 @@ "sideEffects": false, "devDependencies": { "@types/react": "^18.2.48", - "effect": "^2.2.0", + "effect": "^2.2.2", "react": "^18.2.0" }, "peerDependencies": { diff --git a/packages/rx-vue/package.json b/packages/rx-vue/package.json index 50b677f..1aae0eb 100644 --- a/packages/rx-vue/package.json +++ b/packages/rx-vue/package.json @@ -23,7 +23,7 @@ "license": "MIT", "sideEffects": false, "devDependencies": { - "effect": "^2.2.0", + "effect": "^2.2.2", "vue": "^3.4.15" }, "peerDependencies": { diff --git a/packages/rx/package.json b/packages/rx/package.json index 551c8d0..78270aa 100644 --- a/packages/rx/package.json +++ b/packages/rx/package.json @@ -24,7 +24,7 @@ "license": "MIT", "sideEffects": false, "devDependencies": { - "effect": "^2.2.0" + "effect": "^2.2.2" }, "peerDependencies": { "effect": "^2.2.0" diff --git a/packages/rx/src/Rx.ts b/packages/rx/src/Rx.ts index 9bdc2cf..4dca653 100644 --- a/packages/rx/src/Rx.ts +++ b/packages/rx/src/Rx.ts @@ -5,6 +5,7 @@ import { NoSuchElementException } from "effect/Cause" import * as Chunk from "effect/Chunk" import * as Duration from "effect/Duration" import * as Effect from "effect/Effect" +import * as Either from "effect/Either" import * as Exit from "effect/Exit" import { dual, pipe } from "effect/Function" import { globalValue } from "effect/GlobalValue" @@ -365,6 +366,10 @@ export const make: { // constructors - effect // ----------------------------------------------------------------------------- +const isDataType = (u: object): u is Option.Option | Either.Either => + Option.TypeId in u || + Either.TypeId in u + const makeRead: { (effect: Effect.Effect, options?: { readonly initialValue?: A @@ -401,8 +406,10 @@ const makeRead: { return function(get: Context, providedRuntime?: Runtime.Runtime) { const value = create(get) if (typeof value === "object" && value !== null) { - if (Effect.EffectTypeId in value) { - return effect(get, value, options, providedRuntime) + if (isDataType(value)) { + return value + } else if (Effect.EffectTypeId in value) { + return effect(get, value as any, options, providedRuntime) } else if (Stream.StreamTypeId in value) { return stream(get, value, options, providedRuntime) } else if (Layer.LayerTypeId in value) { @@ -412,7 +419,9 @@ const makeRead: { return value } } else if (typeof arg === "object" && arg !== null) { - if (Effect.EffectTypeId in arg) { + if (isDataType(arg)) { + return state(arg) + } else if (Effect.EffectTypeId in arg) { return function(get: Context, providedRuntime?: Runtime.Runtime) { return effect(get, arg, options, providedRuntime) } diff --git a/packages/rx/test/Rx.test.ts b/packages/rx/test/Rx.test.ts index f754506..5fe6887 100644 --- a/packages/rx/test/Rx.test.ts +++ b/packages/rx/test/Rx.test.ts @@ -1,7 +1,7 @@ import * as Registry from "@effect-rx/rx/Registry" import * as Result from "@effect-rx/rx/Result" import * as Rx from "@effect-rx/rx/Rx" -import { Cause, FiberRef } from "effect" +import { Cause, Either, FiberRef } from "effect" import * as Context from "effect/Context" import * as Effect from "effect/Effect" import * as Hash from "effect/Hash" @@ -752,6 +752,18 @@ describe("Rx", () => { cancel() }) + + it("Option is not an Effect", async () => { + const rx = Rx.make(Option.none()) + const r = Registry.make() + assert.deepStrictEqual(r.get(rx), Option.none()) + }) + + it("Either is not an Effect", async () => { + const rx = Rx.make(Either.right(123)) + const r = Registry.make() + assert.deepStrictEqual(r.get(rx), Either.right(123)) + }) }) interface BuildCounter { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5c59469..856e683 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,17 +9,17 @@ importers: .: devDependencies: '@babel/cli': - specifier: ^7.23.4 - version: 7.23.4(@babel/core@7.23.7) + specifier: ^7.23.9 + version: 7.23.9(@babel/core@7.23.9) '@babel/core': - specifier: ^7.23.7 - version: 7.23.7 + specifier: ^7.23.9 + version: 7.23.9 '@babel/plugin-transform-export-namespace-from': specifier: ^7.23.4 - version: 7.23.4(@babel/core@7.23.7) + version: 7.23.4(@babel/core@7.23.9) '@babel/plugin-transform-modules-commonjs': specifier: ^7.23.3 - version: 7.23.3(@babel/core@7.23.7) + version: 7.23.3(@babel/core@7.23.9) '@changesets/changelog-github': specifier: ^0.5.0 version: 0.5.0 @@ -49,7 +49,7 @@ importers: version: 1.2.1(vitest@1.2.1) babel-plugin-annotate-pure-calls: specifier: ^0.4.0 - version: 0.4.0(@babel/core@7.23.7) + version: 0.4.0(@babel/core@7.23.9) eslint: specifier: ^8.56.0 version: 8.56.0 @@ -96,8 +96,8 @@ importers: packages/rx: devDependencies: effect: - specifier: ^2.2.0 - version: 2.2.0 + specifier: ^2.2.2 + version: 2.2.2 publishDirectory: dist packages/rx-react: @@ -110,8 +110,8 @@ importers: specifier: ^18.2.48 version: 18.2.48 effect: - specifier: ^2.2.0 - version: 2.2.0 + specifier: ^2.2.2 + version: 2.2.2 react: specifier: ^18.2.0 version: 18.2.0 @@ -124,8 +124,8 @@ importers: version: link:../rx/dist devDependencies: effect: - specifier: ^2.2.0 - version: 2.2.0 + specifier: ^2.2.2 + version: 2.2.2 vue: specifier: ^3.4.15 version: 3.4.15(typescript@5.3.3) @@ -146,15 +146,15 @@ packages: '@jridgewell/trace-mapping': 0.3.20 dev: true - /@babel/cli@7.23.4(@babel/core@7.23.7): - resolution: {integrity: sha512-j3luA9xGKCXVyCa5R7lJvOMM+Kc2JEnAEIgz2ggtjQ/j5YUVgfsg/WsG95bbsgq7YLHuiCOzMnoSasuY16qiCw==} + /@babel/cli@7.23.9(@babel/core@7.23.9): + resolution: {integrity: sha512-vB1UXmGDNEhcf1jNAHKT9IlYk1R+hehVTLFlCLHBi8gfuHQGP6uRjgXVYU0EVlI/qwAWpstqkBdf2aez3/z/5Q==} engines: {node: '>=6.9.0'} hasBin: true peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/core': 7.23.7 - '@jridgewell/trace-mapping': 0.3.20 + '@babel/core': 7.23.9 + '@jridgewell/trace-mapping': 0.3.22 commander: 4.1.1 convert-source-map: 2.0.0 fs-readdir-recursive: 1.1.0 @@ -179,20 +179,20 @@ packages: engines: {node: '>=6.9.0'} dev: true - /@babel/core@7.23.7: - resolution: {integrity: sha512-+UpDgowcmqe36d4NwqvKsyPMlOLNGMsfMmQ5WGCu+siCe3t3dfe9njrzGfdN4qq+bcNUt0+Vw6haRxBOycs4dw==} + /@babel/core@7.23.9: + resolution: {integrity: sha512-5q0175NOjddqpvvzU+kDiSOAk4PfdO6FvwCWoQ6RO7rTzEe8vlo+4HVfcnAREhD4npMs0e9uZypjTwzZPCf/cw==} engines: {node: '>=6.9.0'} dependencies: '@ampproject/remapping': 2.2.1 '@babel/code-frame': 7.23.5 '@babel/generator': 7.23.6 '@babel/helper-compilation-targets': 7.23.6 - '@babel/helper-module-transforms': 7.23.3(@babel/core@7.23.7) - '@babel/helpers': 7.23.8 - '@babel/parser': 7.23.6 - '@babel/template': 7.22.15 - '@babel/traverse': 7.23.7 - '@babel/types': 7.23.6 + '@babel/helper-module-transforms': 7.23.3(@babel/core@7.23.9) + '@babel/helpers': 7.23.9 + '@babel/parser': 7.23.9 + '@babel/template': 7.23.9 + '@babel/traverse': 7.23.9 + '@babel/types': 7.23.9 convert-source-map: 2.0.0 debug: 4.3.4 gensync: 1.0.0-beta.2 @@ -258,13 +258,13 @@ packages: '@babel/types': 7.23.6 dev: true - /@babel/helper-module-transforms@7.23.3(@babel/core@7.23.7): + /@babel/helper-module-transforms@7.23.3(@babel/core@7.23.9): resolution: {integrity: sha512-7bBs4ED9OmswdfDzpz4MpWgSrV7FXlc3zIagvLFjS5H+Mk7Snr21vQ6QwrsoCGMfNC4e4LQPdoULEt4ykz0SRQ==} engines: {node: '>=6.9.0'} peerDependencies: '@babel/core': ^7.0.0 dependencies: - '@babel/core': 7.23.7 + '@babel/core': 7.23.9 '@babel/helper-environment-visitor': 7.22.20 '@babel/helper-module-imports': 7.22.15 '@babel/helper-simple-access': 7.22.5 @@ -306,13 +306,13 @@ packages: engines: {node: '>=6.9.0'} dev: true - /@babel/helpers@7.23.8: - resolution: {integrity: sha512-KDqYz4PiOWvDFrdHLPhKtCThtIcKVy6avWD2oG4GEvyQ+XDZwHD4YQd+H2vNMnq2rkdxsDkU82T+Vk8U/WXHRQ==} + /@babel/helpers@7.23.9: + resolution: {integrity: sha512-87ICKgU5t5SzOT7sBMfCOZQ2rHjRU+Pcb9BoILMYz600W6DkVRLFBPwQ18gwUVvggqXivaUakpnxWQGbpywbBQ==} engines: {node: '>=6.9.0'} dependencies: - '@babel/template': 7.22.15 - '@babel/traverse': 7.23.7 - '@babel/types': 7.23.6 + '@babel/template': 7.23.9 + '@babel/traverse': 7.23.9 + '@babel/types': 7.23.9 transitivePeerDependencies: - supports-color dev: true @@ -334,34 +334,42 @@ packages: '@babel/types': 7.23.6 dev: true - /@babel/plugin-syntax-export-namespace-from@7.8.3(@babel/core@7.23.7): + /@babel/parser@7.23.9: + resolution: {integrity: sha512-9tcKgqKbs3xGJ+NtKF2ndOBBLVwPjl1SHxPQkd36r3Dlirw3xWUeGaTbqr7uGZcTaxkVNwc+03SVP7aCdWrTlA==} + engines: {node: '>=6.0.0'} + hasBin: true + dependencies: + '@babel/types': 7.23.9 + dev: true + + /@babel/plugin-syntax-export-namespace-from@7.8.3(@babel/core@7.23.9): resolution: {integrity: sha512-MXf5laXo6c1IbEbegDmzGPwGNTsHZmEy6QGznu5Sh2UCWvueywb2ee+CCE4zQiZstxU9BMoQO9i6zUFSY0Kj0Q==} peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/core': 7.23.7 + '@babel/core': 7.23.9 '@babel/helper-plugin-utils': 7.22.5 dev: true - /@babel/plugin-transform-export-namespace-from@7.23.4(@babel/core@7.23.7): + /@babel/plugin-transform-export-namespace-from@7.23.4(@babel/core@7.23.9): resolution: {integrity: sha512-GzuSBcKkx62dGzZI1WVgTWvkkz84FZO5TC5T8dl/Tht/rAla6Dg/Mz9Yhypg+ezVACf/rgDuQt3kbWEv7LdUDQ==} engines: {node: '>=6.9.0'} peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/core': 7.23.7 + '@babel/core': 7.23.9 '@babel/helper-plugin-utils': 7.22.5 - '@babel/plugin-syntax-export-namespace-from': 7.8.3(@babel/core@7.23.7) + '@babel/plugin-syntax-export-namespace-from': 7.8.3(@babel/core@7.23.9) dev: true - /@babel/plugin-transform-modules-commonjs@7.23.3(@babel/core@7.23.7): + /@babel/plugin-transform-modules-commonjs@7.23.3(@babel/core@7.23.9): resolution: {integrity: sha512-aVS0F65LKsdNOtcz6FRCpE4OgsP2OFnW46qNxNIX9h3wuzaNcSQsJysuMwqSibC98HPrf2vCgtxKNwS0DAlgcA==} engines: {node: '>=6.9.0'} peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/core': 7.23.7 - '@babel/helper-module-transforms': 7.23.3(@babel/core@7.23.7) + '@babel/core': 7.23.9 + '@babel/helper-module-transforms': 7.23.3(@babel/core@7.23.9) '@babel/helper-plugin-utils': 7.22.5 '@babel/helper-simple-access': 7.22.5 dev: true @@ -382,6 +390,15 @@ packages: '@babel/types': 7.23.6 dev: true + /@babel/template@7.23.9: + resolution: {integrity: sha512-+xrD2BWLpvHKNmX2QbpdpsBaWnRxahMwJjO+KZk2JOElj5nSmKezyS1B4u+QbHMTX69t4ukm6hh9lsYQ7GHCKA==} + engines: {node: '>=6.9.0'} + dependencies: + '@babel/code-frame': 7.23.5 + '@babel/parser': 7.23.9 + '@babel/types': 7.23.9 + dev: true + /@babel/traverse@7.23.7: resolution: {integrity: sha512-tY3mM8rH9jM0YHFGyfC0/xf+SB5eKUu7HPj7/k3fpi9dAlsMc5YbQvDi0Sh2QTPXqMhyaAtzAr807TIyfQrmyg==} engines: {node: '>=6.9.0'} @@ -400,6 +417,24 @@ packages: - supports-color dev: true + /@babel/traverse@7.23.9: + resolution: {integrity: sha512-I/4UJ9vs90OkBtY6iiiTORVMyIhJ4kAVmsKo9KFc8UOxMeUfi2hvtIBsET5u9GizXE6/GFSuKCTNfgCswuEjRg==} + engines: {node: '>=6.9.0'} + dependencies: + '@babel/code-frame': 7.23.5 + '@babel/generator': 7.23.6 + '@babel/helper-environment-visitor': 7.22.20 + '@babel/helper-function-name': 7.23.0 + '@babel/helper-hoist-variables': 7.22.5 + '@babel/helper-split-export-declaration': 7.22.6 + '@babel/parser': 7.23.9 + '@babel/types': 7.23.9 + debug: 4.3.4 + globals: 11.12.0 + transitivePeerDependencies: + - supports-color + dev: true + /@babel/types@7.23.5: resolution: {integrity: sha512-ON5kSOJwVO6xXVRTvOI0eOnWe7VdUcIpsovGo9U/Br4Ie4UVFQTboO2cYnDhAGU6Fp+UxSiT+pMft0SMHfuq6w==} engines: {node: '>=6.9.0'} @@ -418,6 +453,15 @@ packages: to-fast-properties: 2.0.0 dev: true + /@babel/types@7.23.9: + resolution: {integrity: sha512-dQjSq/7HaSjRM43FFGnv5keM2HsxpmyV1PfaSVm0nzzjwwTmjOe6J4bC8e3+pTEIgHaHj+1ZlLThRJ2auc/w1Q==} + engines: {node: '>=6.9.0'} + dependencies: + '@babel/helper-string-parser': 7.23.4 + '@babel/helper-validator-identifier': 7.22.20 + to-fast-properties: 2.0.0 + dev: true + /@bcoe/v8-coverage@0.2.3: resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==} dev: true @@ -2117,12 +2161,12 @@ packages: engines: {node: '>= 0.4'} dev: true - /babel-plugin-annotate-pure-calls@0.4.0(@babel/core@7.23.7): + /babel-plugin-annotate-pure-calls@0.4.0(@babel/core@7.23.9): resolution: {integrity: sha512-oi4M/PWUJOU9ZyRGoPTfPMqdyMp06jbJAomd3RcyYuzUtBOddv98BqLm96Lucpi2QFoQHkdGQt0ACvw7VzVEQA==} peerDependencies: '@babel/core': ^6.0.0-0 || 7.x dependencies: - '@babel/core': 7.23.7 + '@babel/core': 7.23.9 dev: true /balanced-match@1.0.2: @@ -2186,8 +2230,8 @@ packages: engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7} hasBin: true dependencies: - caniuse-lite: 1.0.30001576 - electron-to-chromium: 1.4.624 + caniuse-lite: 1.0.30001580 + electron-to-chromium: 1.4.646 node-releases: 2.0.14 update-browserslist-db: 1.0.13(browserslist@4.22.2) dev: true @@ -2235,8 +2279,8 @@ packages: engines: {node: '>=6'} dev: true - /caniuse-lite@1.0.30001576: - resolution: {integrity: sha512-ff5BdakGe2P3SQsMsiqmt1Lc8221NR1VzHj5jXN5vBny9A6fpze94HiVV/n7XRosOlsShJcvMv5mdnpjOGCEgg==} + /caniuse-lite@1.0.30001580: + resolution: {integrity: sha512-mtj5ur2FFPZcCEpXFy8ADXbDACuNFXg6mxVDqp7tqooX6l3zwm+d8EPoeOSIFRDvHs8qu7/SLFOGniULkcH2iA==} dev: true /chai@4.4.1: @@ -2769,12 +2813,12 @@ packages: resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==} dev: true - /effect@2.2.0: - resolution: {integrity: sha512-ymp4cEa231FtoVDA+FZM6BR6acEXwWTz43jO1qbOspZPK170l4DfYwPCNI9FZm8tRSQgmqVp5Z+ACQUUnTlsjw==} + /effect@2.2.2: + resolution: {integrity: sha512-hY/37Ssd2Zfn0r09vDe9tSYPVS5HZBbmW4DMBO7OIIvRADgp5cnWfLhY6pVy+Bm5DXV9luFycjDcB1731WGyTA==} dev: true - /electron-to-chromium@1.4.624: - resolution: {integrity: sha512-w9niWuheXjz23vezH3w90n9KKcHe0UkhTfJ+rXJkuGGogHyQbQ7KS1x0a8ER4LbI3ljFS/gqxKh1TidNXDMHOg==} + /electron-to-chromium@1.4.646: + resolution: {integrity: sha512-vThkQ0JuF45qT/20KbRgM56lV7IuGt7SjhawQ719PDHzhP84KAO1WJoaxgCoAffKHK47FmVKP1Fqizx7CwK1SA==} dev: true /emoji-regex@8.0.0: @@ -3042,7 +3086,7 @@ packages: resolution: {integrity: sha512-p8Nj3Mo4I2jsfCnaPkaR9Rh6eP9pT87xQiFz5TOymsco7unAysR4ZYWh8fuFV5oTdL6Y1C2oAVZdID2olhfHBg==} engines: {node: '>=12.0.0'} dependencies: - '@babel/core': 7.23.7 + '@babel/core': 7.23.9 '@babel/generator': 7.12.17 '@babel/parser': 7.23.6 '@babel/traverse': 7.23.7