-
Notifications
You must be signed in to change notification settings - Fork 1
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
571 additions
and
432 deletions.
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 |
---|---|---|
|
@@ -22,4 +22,7 @@ logs | |
!.env.example | ||
|
||
# graphql codegen | ||
/queries/codegen.ts | ||
/queries/codegen.ts | ||
|
||
# docker db volumes | ||
.db-data |
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 @@ | ||
<script setup lang="ts"> | ||
import {useCom1} from '~/use/use-com1' | ||
const props = defineProps({}) | ||
const emit = defineEmits([]) | ||
const com1 = useCom1() | ||
onMounted(() => { | ||
com1.bar = 'bar!' | ||
}) | ||
onUnmounted(() => { | ||
com1.bar = '' | ||
}) | ||
</script> |
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 @@ | ||
<script setup lang="ts"> | ||
import {useCom1} from '~/use/use-com1' | ||
const props = defineProps({}) | ||
const emit = defineEmits([]) | ||
const com1 = useCom1() | ||
onMounted(() => { | ||
com1.foo = 'foo!' | ||
}) | ||
onUnmounted(() => { | ||
com1.foo = '' | ||
}) | ||
</script> |
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
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,12 @@ | ||
version: "3" | ||
services: | ||
db: | ||
image: postgres:latest | ||
container_name: postgres | ||
ports: | ||
- "5432:5432" | ||
environment: | ||
POSTGRES_USER: "user" | ||
POSTGRES_PASSWORD: "pa22w0rd" | ||
volumes: | ||
- ./.db_data/:/var/lib/postgresql/data |
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
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,43 @@ | ||
<template> | ||
<div> | ||
com1 | ||
{{ foo }} | ||
{{ bar }} | ||
----- | ||
<foo v-if="showFoo" /> | ||
<bar v-if="showBar" /> | ||
<button @click="onToggleFoo">toggle foo</button> | ||
<button @click="onToggleBar">toggle bar</button> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import {ref} from 'vue' | ||
import {provideCom1} from '~/use/use-com1' | ||
import Bar from '~/components/Bar.vue' | ||
import Foo from '~/components/Foo.vue' | ||
const props = defineProps({}) | ||
const emit = defineEmits([]) | ||
const showFoo = ref(false) | ||
const showBar = ref(false) | ||
const com1 = provideCom1() | ||
const foo = computed(() => { | ||
return com1.foo | ||
}) | ||
const bar = computed(() => { | ||
return com1.bar | ||
}) | ||
const onToggleFoo = () => { | ||
showFoo.value = !showFoo.value | ||
} | ||
const onToggleBar = () => { | ||
showBar.value = !showBar.value | ||
} | ||
</script> |
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
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,27 @@ | ||
import {inject, InjectionKey, provide, reactive, ref} from 'vue' | ||
import {ReactiveOptions} from '@byte-abc/use' | ||
|
||
export interface Com1Context { | ||
bar: string | undefined | ||
foo: string | undefined | ||
} | ||
|
||
export const COM1_CONTEXT_KEY: InjectionKey<ReactiveOptions<Com1Context>> = Symbol('com1') | ||
|
||
export const createCom1 = (): ReactiveOptions<Com1Context> => { | ||
return { | ||
bar: ref<string | undefined>(), | ||
foo: ref<string | undefined>(), | ||
} | ||
} | ||
export const useCom1 = () => { | ||
return reactive(inject(COM1_CONTEXT_KEY) ?? createCom1()) | ||
} | ||
|
||
export const provideCom1 = () => { | ||
const context = createCom1() | ||
|
||
provide(COM1_CONTEXT_KEY, context) | ||
|
||
return reactive(context) | ||
} |
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
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 @@ | ||
export * from './assign-ref' | ||
export * from './is-to-ref' | ||
export * from './is-writable-ref' | ||
export * from './resolve-ref' | ||
export * from './types' |
This file was deleted.
Oops, something went wrong.
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,37 @@ | ||
import {ReactiveOptions} from '../ref' | ||
import {reactive, ref, watch} from 'vue' | ||
import {flushPromises} from '@vue/test-utils' | ||
|
||
describe('reactive options', () => { | ||
it('should be reactive options', async () => { | ||
interface UseReactiveOptionsOptions { | ||
foo?: string | ||
} | ||
|
||
const watchCallback = jest.fn() | ||
|
||
const useReactiveOptions = (options: ReactiveOptions<UseReactiveOptionsOptions>) => { | ||
const optionsObjectRef = reactive(options) | ||
|
||
watch( | ||
() => optionsObjectRef.foo, | ||
(foo) => { | ||
watchCallback(foo) | ||
}, | ||
{immediate: true}, | ||
) | ||
} | ||
|
||
const foo = ref('foo') | ||
|
||
useReactiveOptions({foo}) | ||
|
||
expect(watchCallback).toHaveBeenCalledWith('foo') | ||
|
||
foo.value = 'bar' | ||
|
||
await flushPromises() | ||
|
||
expect(watchCallback).toHaveBeenCalledWith('bar') | ||
}) | ||
}) |
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,6 @@ | ||
import {ComponentPublicInstance, VNodeChild} from 'vue' | ||
|
||
export type Children = VNodeChild | ||
|
||
export type MaybeElement = ComponentPublicInstance | HTMLElement | null | undefined | ||
export type MaybeElementOrWindow = ComponentPublicInstance | HTMLElement | null | undefined | Window |
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 @@ | ||
/// <reference types="vite/client" /> |
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 @@ | ||
export * from './component' | ||
export * from './props' | ||
export * from './ref' |
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 @@ | ||
import {AllowedComponentProps, Component, VNodeProps} from 'vue' | ||
|
||
// using outside this package | ||
// noinspection JSUnusedGlobalSymbols | ||
export type ExtractComponentProps<C extends Component> = C extends new (...args: any) => any | ||
? Omit<InstanceType<C>['$props'], keyof VNodeProps | keyof AllowedComponentProps> | ||
: never | ||
|
||
export type Data = Record<string, unknown> | ||
|
||
// noinspection JSUnusedGlobalSymbols | ||
export type FastPropObjectOptions<P = Data> = { | ||
[K in keyof P]: null | ||
} |
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,27 @@ | ||
import {ComputedRef, Ref, ToRef, WatchSource, WritableComputedRef} from 'vue' | ||
|
||
/** | ||
* 함수를 제외한 값들은 Ref 입니다 custom hook 만들때 리턴값으로 사용하면 좋습니다 | ||
*/ | ||
export type ToRefsValueOnly<T = any> = { | ||
[K in keyof T]: T[K] extends (...args: any) => any ? T[K] : ToRef<T[K]> | ||
} | ||
|
||
/** | ||
* 모든 종류의 Ref 입니다 또는 일반 변수 입니다 | ||
*/ | ||
export type MaybeRef<T> = Ref<T> | ComputedRef<T> | T | WritableComputedRef<T> | ||
|
||
/** | ||
* 쓰기가능한 Ref 타입 입니다 | ||
*/ | ||
export type WritableRef<T> = WritableComputedRef<T> | Ref<T> | ||
|
||
/** | ||
* 여러 WatchSource | ||
*/ | ||
export type MultiWatchSources = (WatchSource<unknown> | object)[] | ||
|
||
export type ReactiveOptions<T> = { | ||
[K in keyof T]: MaybeRef<T[K]> | ||
} |
Oops, something went wrong.