-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
425 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@effect-rx/rx-vue": minor | ||
--- | ||
|
||
add vue package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
coverage/ | ||
*.tsbuildinfo | ||
node_modules/ | ||
.ultra.cache.json | ||
.DS_Store | ||
tmp/ | ||
build/ | ||
dist/ | ||
.direnv/ | ||
|
||
# files | ||
/src/tsconfig.json | ||
/dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.js | ||
*.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023-present The Contributors | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
WIP. | ||
|
||
Docs: https://effect-ts.github.io/rx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"exclude": ["src/internal/**/*.ts"], | ||
"theme": "mikearnaldi/just-the-docs", | ||
"parseCompilerOptions": { | ||
"noEmit": true, | ||
"strict": true, | ||
"target": "es2015", | ||
"lib": ["es2015"], | ||
"paths": { | ||
"@effect-rx/rx": ["./src/index.ts"], | ||
"@effect-rx/rx/*": ["./src/*"] | ||
} | ||
}, | ||
"examplesCompilerOptions": { | ||
"noEmit": true, | ||
"strict": true, | ||
"target": "es2015", | ||
"lib": ["es2015"], | ||
"paths": { | ||
"@effect-rx/rx": ["./src/index.ts"], | ||
"@effect-rx/rx/*": ["./src/*"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"name": "@effect-rx/rx-vue", | ||
"version": "0.0.0", | ||
"description": "Reactive toolkit for Effect", | ||
"type": "module", | ||
"publishConfig": { | ||
"access": "public", | ||
"directory": "dist" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/effect-ts/rx.git" | ||
}, | ||
"homepage": "https://github.com/effect-ts/rx", | ||
"scripts": { | ||
"build": "pnpm build-esm && pnpm build-cjs && pnpm build-annotate && build-utils pack-v2", | ||
"build-esm": "tsc -b tsconfig.build.json", | ||
"build-cjs": "babel build/esm --plugins @babel/transform-export-namespace-from --plugins @babel/transform-modules-commonjs --out-dir build/cjs --source-maps", | ||
"build-annotate": "babel build --plugins annotate-pure-calls --out-dir build --source-maps" | ||
}, | ||
"keywords": [], | ||
"author": "Effect contributors", | ||
"license": "MIT", | ||
"sideEffects": false, | ||
"devDependencies": { | ||
"effect": "^2.0.2", | ||
"vue": "^3.4.13" | ||
}, | ||
"peerDependencies": { | ||
"effect": "^2.0.0", | ||
"vue": "^3.4" | ||
}, | ||
"dependencies": { | ||
"@effect-rx/rx": "workspace:^" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
import * as Registry from "@effect-rx/rx/Registry" | ||
import type * as Rx from "@effect-rx/rx/Rx" | ||
import type * as RxRef from "@effect-rx/rx/RxRef" | ||
import { globalValue } from "effect/GlobalValue" | ||
import type { InjectionKey, Ref } from "vue" | ||
import { getCurrentScope, inject, onScopeDispose, ref } from "vue" | ||
|
||
/** | ||
* @since 1.0.0 | ||
* @category modules | ||
*/ | ||
export * as Registry from "@effect-rx/rx/Registry" | ||
/** | ||
* @since 1.0.0 | ||
* @category modules | ||
*/ | ||
export * as Result from "@effect-rx/rx/Result" | ||
/** | ||
* @since 1.0.0 | ||
* @category modules | ||
*/ | ||
export * as Rx from "@effect-rx/rx/Rx" | ||
/** | ||
* @since 1.0.0 | ||
* @category modules | ||
*/ | ||
export * as RxRef from "@effect-rx/rx/RxRef" | ||
|
||
/** | ||
* @since 1.0.0 | ||
* @category registry | ||
*/ | ||
export const registryKey = Registry.TypeId as InjectionKey<Registry.Registry> | ||
|
||
/** | ||
* @since 1.0.0 | ||
* @category registry | ||
*/ | ||
export const defaultRegistry: Registry.Registry = globalValue( | ||
"@effect-rx/rx-vue/defaultRegistry", | ||
() => Registry.make() | ||
) | ||
|
||
/** | ||
* @since 1.0.0 | ||
* @category registry | ||
*/ | ||
export const injectRegistry = (): Registry.Registry => { | ||
return inject(registryKey) ?? defaultRegistry | ||
} | ||
|
||
/** | ||
* @since 1.0.0 | ||
* @category composables | ||
*/ | ||
export const useRx = <R, W>(rx: Rx.Writable<R, W>): readonly [Readonly<Ref<R>>, (_: W) => void] => { | ||
const registry = injectRegistry() | ||
const value = ref<R>(registry.get(rx)) | ||
const cancel = registry.subscribe(rx, (nextValue) => { | ||
value.value = nextValue as any | ||
}) | ||
if (getCurrentScope()) { | ||
onScopeDispose(cancel) | ||
} | ||
return [value as Readonly<Ref<R>>, (_) => registry.set(rx, _)] | ||
} | ||
|
||
/** | ||
* @since 1.0.0 | ||
* @category composables | ||
*/ | ||
export const useRxValue = <A>(rx: Rx.Rx<A>): Readonly<Ref<A>> => { | ||
const registry = injectRegistry() | ||
const value = ref<A>(registry.get(rx)) | ||
const cancel = registry.subscribe(rx, (nextValue) => { | ||
value.value = nextValue as any | ||
}) | ||
if (getCurrentScope()) { | ||
onScopeDispose(cancel) | ||
} | ||
return value as Readonly<Ref<A>> | ||
} | ||
|
||
/** | ||
* @since 1.0.0 | ||
* @category composables | ||
*/ | ||
export const useRxSet = <R, W>(rx: Rx.Writable<R, W>): (_: W) => void => { | ||
const registry = injectRegistry() | ||
const cancel = registry.mount(rx) | ||
if (getCurrentScope()) { | ||
onScopeDispose(cancel) | ||
} | ||
return (_) => registry.set(rx, _) | ||
} | ||
|
||
/** | ||
* @since 1.0.0 | ||
* @category composables | ||
*/ | ||
export const useRxRef = <A>(rxRef: RxRef.ReadonlyRef<A>): Readonly<Ref<A>> => { | ||
const value = ref<A>(rxRef.value) | ||
const cancel = rxRef.subscribe((nextValue) => { | ||
value.value = nextValue as any | ||
}) | ||
if (getCurrentScope()) { | ||
onScopeDispose(cancel) | ||
} | ||
return value as Readonly<Ref<A>> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { describe, test } from "vitest" | ||
|
||
describe("rx-vue", () => { | ||
test("", () => {}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "./tsconfig.src.json", | ||
"compilerOptions": { | ||
"tsBuildInfoFile": ".tsbuildinfo/build.tsbuildinfo", | ||
"outDir": "build/esm", | ||
"declarationDir": "build/dts", | ||
"stripInternal": true | ||
}, | ||
"references": [{ "path": "../rx" }] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"include": [ | ||
"examples" | ||
], | ||
"references": [ | ||
{ | ||
"path": "tsconfig.build.json" | ||
} | ||
], | ||
"compilerOptions": { | ||
"tsBuildInfoFile": ".tsbuildinfo/examples.tsbuildinfo", | ||
"rootDir": "examples", | ||
"noEmit": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"references": [ | ||
{ | ||
"path": "tsconfig.src.json" | ||
}, | ||
{ | ||
"path": "tsconfig.test.json" | ||
}, | ||
{ | ||
"path": "tsconfig.examples.json" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"include": ["src"], | ||
"compilerOptions": { | ||
"tsBuildInfoFile": ".tsbuildinfo/src.tsbuildinfo", | ||
"rootDir": "src", | ||
"outDir": "build/src" | ||
}, | ||
"references": [{ "path": "../rx" }] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"include": [ | ||
"test", | ||
], | ||
"references": [ | ||
{ | ||
"path": "tsconfig.src.json" | ||
}, | ||
], | ||
"compilerOptions": { | ||
"tsBuildInfoFile": ".tsbuildinfo/test.tsbuildinfo", | ||
"rootDir": "test", | ||
"noEmit": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as path from "path" | ||
import { defineConfig } from "vitest/config" | ||
|
||
export default defineConfig({ | ||
test: { | ||
include: ["./test/**/*.test.ts"] | ||
}, | ||
resolve: { | ||
alias: { | ||
"@effect-rx/rx/test": path.join(__dirname, "../rx/test"), | ||
"@effect-rx/rx": path.join(__dirname, "../rx/src"), | ||
"@effect-rx/rx-vue/test": path.join(__dirname, "test"), | ||
"@effect-rx/rx-vue": path.join(__dirname, "src") | ||
} | ||
} | ||
}) |
Oops, something went wrong.