Skip to content

Commit

Permalink
update effect
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed Nov 30, 2023
1 parent a293d38 commit f3d415a
Show file tree
Hide file tree
Showing 7 changed files with 936 additions and 667 deletions.
6 changes: 6 additions & 0 deletions .changeset/odd-plants-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@effect-rx/rx-react": minor
"@effect-rx/rx": minor
---

update effect
22 changes: 8 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,22 @@
},
"devDependencies": {
"@babel/cli": "^7.23.4",
"@babel/core": "^7.23.3",
"@babel/core": "^7.23.5",
"@babel/plugin-transform-export-namespace-from": "^7.23.4",
"@babel/plugin-transform-modules-commonjs": "^7.23.3",
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.2",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.1",
"@effect/build-utils": "^0.5.0",
"@effect/docgen": "^0.3.5",
"@effect/docgen": "^0.3.6",
"@effect/eslint-plugin": "^0.1.2",
"@effect/language-service": "^0.0.21",
"@typescript-eslint/eslint-plugin": "^6.12.0",
"@typescript-eslint/parser": "^6.12.0",
"@typescript-eslint/eslint-plugin": "^6.13.1",
"@typescript-eslint/parser": "^6.13.1",
"@vitest/coverage-v8": "^0.34.6",
"@vitest/web-worker": "^0.34.6",
"babel-plugin-annotate-pure-calls": "^0.4.0",
"eslint": "^8.54.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-codegen": "^0.18.1",
"eslint-plugin-codegen": "^0.21.0",
"eslint-plugin-deprecation": "^2.0.0",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-simple-import-sort": "^10.0.0",
Expand All @@ -44,13 +43,8 @@
"glob": "^10.3.10",
"madge": "^6.1.0",
"prettier": "^3.1.0",
"tsx": "^4.1.4",
"tsx": "^4.6.1",
"typescript": "^5.3.2",
"vitest": "^0.34.6"
},
"pnpm": {
"patchedDependencies": {
"@changesets/[email protected]": "patches/@[email protected]"
}
}
}
6 changes: 3 additions & 3 deletions packages/rx-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
"license": "MIT",
"sideEffects": false,
"devDependencies": {
"@types/react": "^18.2.37",
"effect": "2.0.0-next.56",
"@types/react": "^18.2.39",
"effect": "2.0.0-next.57",
"react": "^18.2.0"
},
"peerDependencies": {
"effect": "2.0.0-next.56",
"effect": "2.0.0-next.57",
"react": "^18"
},
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/rx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
"license": "MIT",
"sideEffects": false,
"devDependencies": {
"effect": "2.0.0-next.56"
"effect": "2.0.0-next.57"
},
"peerDependencies": {
"effect": "2.0.0-next.56"
"effect": "2.0.0-next.57"
}
}
66 changes: 32 additions & 34 deletions packages/rx/src/Rx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ const RxProto = {
}
},
toString() {
return Inspectable.toString(this)
// TODO: remove any when fix lands
return (Inspectable as any).format(this)
},
[Inspectable.NodeInspectSymbol](this: Rx<any>) {
return this.toJSON()
Expand All @@ -234,19 +235,19 @@ const RxProto = {
if (runtimeResult._tag !== "Success") {
return Result.replacePrevious(runtimeResult, previous)
}
return read(runtimeResult.value)(get)
return read(get, runtimeResult.value)
})
},

fn(this: RxRuntime<any, any>, arg: any, options?: { readonly initialValue?: unknown }) {
const [makeRead, write] = makeResultFn(arg, options)
const [read, write] = makeResultFn(arg, options)
return writable((get) => {
const previous = get.self<Result.Result<any, any>>()
const runtimeResult = get(this)
if (runtimeResult._tag !== "Success") {
return Result.replacePrevious(runtimeResult, previous)
}
return makeRead(runtimeResult.value)(get)
return read(get, runtimeResult.value)
}, write)
},

Expand Down Expand Up @@ -344,7 +345,7 @@ export const make: {
<A>(create: Rx.Read<A>): Rx<A>
<A>(initialValue: A): Writable<A, A>
} = (arg: any, options?: { readonly initialValue?: unknown }) => {
const readOrRx = makeRead(arg, options)()
const readOrRx = makeRead(arg, options)
if (TypeId in readOrRx) {
return readOrRx as any
}
Expand All @@ -358,24 +359,24 @@ export const make: {
const makeRead: {
<E, A>(effect: Effect.Effect<Scope.Scope, E, A>, options?: {
readonly initialValue?: A
}): (runtime?: Runtime.Runtime<any>) => Rx.Read<Result.Result<E, A>>
}): (get: Context, runtime?: Runtime.Runtime<any>) => Result.Result<E, A>
<E, A>(create: Rx.Read<Effect.Effect<Scope.Scope, E, A>>, options?: {
readonly initialValue?: A
}): (runtime?: Runtime.Runtime<any>) => Rx.Read<Result.Result<E, A>>
}): (get: Context, runtime?: Runtime.Runtime<any>) => Result.Result<E, A>
<E, A>(stream: Stream.Stream<never, E, A>, options?: {
readonly initialValue?: A
}): (runtime?: Runtime.Runtime<any>) => Rx.Read<Result.Result<E, A>>
}): (get: Context, runtime?: Runtime.Runtime<any>) => Result.Result<E, A>
<E, A>(create: Rx.Read<Stream.Stream<never, E, A>>, options?: {
readonly initialValue?: A
}): (runtime?: Runtime.Runtime<any>) => Rx.Read<Result.Result<E, A>>
}): (get: Context, runtime?: Runtime.Runtime<any>) => Result.Result<E, A>
<E, A>(
layer: Layer.Layer<never, E, A>
): (runtime?: Runtime.Runtime<any>) => Rx.Read<Result.Result<E, Runtime.Runtime<any>>>
): (get: Context, runtime?: Runtime.Runtime<any>) => Result.Result<E, Runtime.Runtime<any>>
<E, A>(
create: Rx.Read<Layer.Layer<never, E, A>>
): (runtime?: Runtime.Runtime<any>) => Rx.Read<Result.Result<E, Runtime.Runtime<any>>>
<A>(create: Rx.Read<A>): (runtime?: Runtime.Runtime<any>) => Rx.Read<A>
<A>(initialValue: A): (runtime?: Runtime.Runtime<any>) => Writable<A, A>
): (get: Context, runtime?: Runtime.Runtime<any>) => Result.Result<E, Runtime.Runtime<any>>
<A>(create: Rx.Read<A>): (get: Context, runtime?: Runtime.Runtime<any>) => A
<A>(initialValue: A): Writable<A, A>
} = <E, A>(
arg:
| Effect.Effect<Scope.Scope, E, A>
Expand All @@ -387,11 +388,10 @@ const makeRead: {
| Rx.Read<A>
| A,
options?: { readonly initialValue?: unknown }
) =>
(providedRuntime?: Runtime.Runtime<any>) => {
) => {
if (typeof arg === "function") {
const create = arg as Rx.Read<any>
return function(get: Context) {
return function(get: Context, providedRuntime?: Runtime.Runtime<any>) {
const value = create(get)
if (typeof value === "object" && value !== null) {
if (Effect.EffectTypeId in value) {
Expand All @@ -406,15 +406,15 @@ const makeRead: {
}
} else if (typeof arg === "object" && arg !== null) {
if (Effect.EffectTypeId in arg) {
return function(get: Context) {
return function(get: Context, providedRuntime?: Runtime.Runtime<any>) {
return effect(get, arg, options, providedRuntime)
}
} else if (Stream.StreamTypeId in arg) {
return function(get: Context) {
return function(get: Context, providedRuntime?: Runtime.Runtime<any>) {
return stream(get, arg, options, providedRuntime)
}
} else if (Layer.LayerTypeId in arg) {
return function(get: Context) {
return function(get: Context, providedRuntime?: Runtime.Runtime<any>) {
return runtime(get, arg, providedRuntime)
}
}
Expand Down Expand Up @@ -639,8 +639,8 @@ export const fn: {
} = <Arg, E, A>(f: Rx.ReadFn<Arg, Stream.Stream<never, E, A> | Effect.Effect<Scope.Scope, E, A>>, options?: {
readonly initialValue?: A
}): RxResultFn<E | NoSuchElementException, A, Arg> => {
const [makeRead, write] = makeResultFn(f, options)
return writable(makeRead(), write)
const [read, write] = makeResultFn(f, options)
return writable(read, write)
}

function makeResultFn<Arg, E, A>(
Expand All @@ -652,23 +652,21 @@ function makeResultFn<Arg, E, A>(
? Result.success<E, A>(options.initialValue)
: Result.initial<E, A>()

function makeRead(runtime?: Runtime.Runtime<never>): Rx.Read<Result.Result<E | NoSuchElementException, A>> {
return function(get) {
const [counter, arg] = get(argRx)
if (counter === 0) {
return initialValue
}
const value = f(arg, get)
if (Effect.EffectTypeId in value) {
return makeEffect(get, value, initialValue, runtime)
}
return makeStream(get, value, initialValue, runtime)
function read(get: Context, runtime?: Runtime.Runtime<never>): Result.Result<E | NoSuchElementException, A> {
const [counter, arg] = get(argRx)
if (counter === 0) {
return initialValue
}
const value = f(arg, get)
if (Effect.EffectTypeId in value) {
return makeEffect(get, value, initialValue, runtime)
}
return makeStream(get, value, initialValue, runtime)
}
function write(ctx: WriteContext<Result.Result<E | NoSuchElementException, A>>, arg: Arg) {
ctx.set(argRx, [ctx.get(argRx)[0] + 1, arg])
}
return [makeRead, write] as const
return [read, write] as const
}

/**
Expand All @@ -691,7 +689,7 @@ export const pull = <E, A>(create: Rx.Read<Stream.Stream<never, E, A>> | Stream.
const pullRx = readable(
makeRead(function(get) {
return makeStreamPullEffect(get, create, options)
})()
})
)
return makeStreamPull(pullRx, options)
}
Expand Down
67 changes: 0 additions & 67 deletions patches/@[email protected]

This file was deleted.

Loading

0 comments on commit f3d415a

Please sign in to comment.