Skip to content

Commit

Permalink
add vue package
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed Jan 14, 2024
1 parent 856f945 commit 8c17e08
Show file tree
Hide file tree
Showing 19 changed files with 425 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/twelve-tools-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect-rx/rx-vue": minor
---

add vue package
13 changes: 13 additions & 0 deletions packages/rx-vue/.gitignore
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
2 changes: 2 additions & 0 deletions packages/rx-vue/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.js
*.ts
21 changes: 21 additions & 0 deletions packages/rx-vue/LICENSE
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.
3 changes: 3 additions & 0 deletions packages/rx-vue/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
WIP.

Docs: https://effect-ts.github.io/rx
24 changes: 24 additions & 0 deletions packages/rx-vue/docgen.json
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/*"]
}
}
}
36 changes: 36 additions & 0 deletions packages/rx-vue/package.json
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:^"
}
}
113 changes: 113 additions & 0 deletions packages/rx-vue/src/index.ts
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>>
}
5 changes: 5 additions & 0 deletions packages/rx-vue/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { describe, test } from "vitest"

describe("rx-vue", () => {
test("", () => {})
})
10 changes: 10 additions & 0 deletions packages/rx-vue/tsconfig.build.json
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" }]
}
16 changes: 16 additions & 0 deletions packages/rx-vue/tsconfig.examples.json
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
}
}
14 changes: 14 additions & 0 deletions packages/rx-vue/tsconfig.json
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"
}
]
}
10 changes: 10 additions & 0 deletions packages/rx-vue/tsconfig.src.json
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" }]
}
16 changes: 16 additions & 0 deletions packages/rx-vue/tsconfig.test.json
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
}
}
16 changes: 16 additions & 0 deletions packages/rx-vue/vitest.config.ts
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")
}
}
})
Loading

0 comments on commit 8c17e08

Please sign in to comment.