Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ interface ReactiveReplicant<T> {
loadDefault: () => void
}

export function useReplicant<T>(name: string, namespace: string | undefined, opts: NodeCG.Replicant.Options<T> = {}) {
return useReplicantRaw(name, namespace, opts).reactiveReplicant
type ReplicantOptions<T> = Parameters<typeof nodecg.Replicant<T>>[1];

export function useReplicant<T>(name: string, namespace: string | undefined, opts: ReplicantOptions<T> = {}) {
return useReplicantRaw<T>(name, namespace, opts).reactiveReplicant
}

function useReplicantRaw<T>(name: string, namespace: string | NodeCG.Replicant.Options<T> | undefined, opts: NodeCG.Replicant.Options<T> | undefined) {
function useReplicantRaw<T>(name: string, namespace: string | ReplicantOptions<T> | undefined, opts: ReplicantOptions<T> | undefined) {
if (isRef(name)) {
console.warn(`Tried to create a StaticReplicant using a reactive name (${name.value})`)
throw Error(`Tried to create a StaticReplicant using a reactive name (${name.value})`)
Expand Down Expand Up @@ -84,7 +86,7 @@ function useReplicantRaw<T>(name: string, namespace: string | NodeCG.Replicant.O
}
}

export function useDynamicReplicant<T>(name: Ref<string>, namespace: string, opts: NodeCG.Replicant.Options<T> | undefined) {
export function useDynamicReplicant<T>(name: Ref<string>, namespace: string, opts: ReplicantOptions<T> | undefined) {
if (!isRef(name)) {
console.warn(`Tried to create a DynamicReplicant using a static name (${name})`)
throw Error(`Tried to create a DynamicReplicant using a static name (${name})`)
Expand Down Expand Up @@ -113,10 +115,10 @@ export function useDynamicReplicant<T>(name: Ref<string>, namespace: string, opt


export function useAssetReplicant(name: string, namespace: string) {
const rep = nodecg.Replicant<NodeCG.AssetFile[]>(`assets:${name}`, namespace)
const newVal: Ref<NodeCG.AssetFile[]> = ref([])
const rep = nodecg.Replicant<NodeCG.default.AssetFile[]>(`assets:${name}`, namespace)
const newVal: Ref<NodeCG.default.AssetFile[]> = ref([])

rep.on('change', (newRepVal: NodeCG.AssetFile[] | null | undefined) => {
rep.on('change', (newRepVal: NodeCG.default.AssetFile[] | null | undefined) => {
newVal.value = clone(newRepVal ?? [])
})

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nodecg-vue-composable",
"version": "1.2.1",
"version": "1.2.2",
"description": "A set of Vue composables for interacting more predictably with NodeCG replicants.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -28,7 +28,7 @@
}
},
"devDependencies": {
"@nodecg/types": "^2.1.12",
"@nodecg/types": "^2.5.3",
"typescript": "^4.9.4",
"vue": "^3.3.8"
}
Expand Down
Loading