Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for this referencing inside firebase funcs #407

Closed
wants to merge 1 commit into from
Closed
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
13 changes: 11 additions & 2 deletions packages/vuefire/src/firestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '@posva/vuefire-core'
import { firestore } from 'firebase'
import Vue, { PluginFunction } from 'vue'
import { CombinedVueInstance } from 'vue/types/vue'

const ops: OperationsType = {
set: (target, key, value) => walkSet(target, key, value),
Expand Down Expand Up @@ -96,8 +97,15 @@ type VueFirestoreObject = Record<
type FirestoreOption<V> = VueFirestoreObject | ((this: V) => VueFirestoreObject)

declare module 'vue/types/options' {
interface ComponentOptions<V extends Vue> {
firestore?: FirestoreOption<V>
interface ComponentOptions<
V extends Vue,
Data = DefaultData<V>,
Methods = DefaultMethods<V>,
Computed = DefaultComputed,
PropsDef = PropsDefinition<DefaultProps>,
Props = DefaultProps
> {
firestore?: FirestoreOption<CombinedVueInstance<V, Data, Methods, Computed, Props>>
}
}

Expand Down Expand Up @@ -142,6 +150,7 @@ export const firestorePlugin: PluginFunction<PluginOptions> = function firestore
},
created(this: Vue) {
const { firestore } = this.$options
// @ts-ignore
const refs = typeof firestore === 'function' ? firestore.call(this) : firestore
if (!refs) return
for (const key in refs) {
Expand Down
30 changes: 30 additions & 0 deletions packages/vuefire/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,32 @@
import {
DefaultData,
DefaultMethods,
DefaultComputed,
ThisTypedComponentOptionsWithArrayProps,
DefaultProps,
ThisTypedComponentOptionsWithRecordProps,
} from 'vue/types/options'

export * from './rtdb'
export * from './firestore'

declare module 'vue/types/vue' {
interface VueConstructor<V extends Vue> {
extend<
Data = DefaultData<V>,
Methods = DefaultMethods<V>,
Computed = DefaultComputed,
PropNames extends string = never
>(
options?: ThisTypedComponentOptionsWithArrayProps<V, Data, Methods, Computed, PropNames>
): ExtendedVue<V, Data, Methods, Computed, Record<PropNames, any>>
extend<
Data = DefaultData<V>,
Methods = DefaultMethods<V>,
Computed = DefaultComputed,
Props = DefaultProps
>(
options?: ThisTypedComponentOptionsWithRecordProps<V, Data, Methods, Computed, Props>
): ExtendedVue<V, Data, Methods, Computed, Props>
}
}
12 changes: 10 additions & 2 deletions packages/vuefire/src/rtdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '@posva/vuefire-core'
import { database } from 'firebase'
import Vue, { PluginFunction } from 'vue'
import { CombinedVueInstance } from 'vue/types/vue'

/**
* Returns the original reference of a Firebase reference or query across SDK versions.
Expand Down Expand Up @@ -99,8 +100,15 @@ type VueFirebaseObject = Record<string, database.Query | database.Reference>
type FirebaseOption<V> = VueFirebaseObject | ((this: V) => VueFirebaseObject)

declare module 'vue/types/options' {
interface ComponentOptions<V extends Vue> {
firebase?: FirebaseOption<V>
interface ComponentOptions<
V extends Vue,
Data = DefaultData<V>,
Methods = DefaultMethods<V>,
Computed = DefaultComputed,
PropsDef = PropsDefinition<DefaultProps>,
Props = DefaultProps
> {
firebase?: FirebaseOption<CombinedVueInstance<V, Data, Methods, Computed, Props>>
}
}

Expand Down