Skip to content

Commit fbd27f2

Browse files
committed
refactor: global options names
1 parent 186ce40 commit fbd27f2

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-29
lines changed

src/database/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Ref, ref, getCurrentScope, onScopeDispose } from 'vue-demi'
22
import type { DatabaseReference, Query } from 'firebase/database'
33
import { OperationsType, walkSet, _RefWithState } from '../shared'
44
import { rtdbUnbinds } from './optionsApi'
5-
import { bindAsArray, bindAsObject, RTDBOptions } from './subscribe'
5+
import { bindAsArray, bindAsObject, _DatabaseRefOptions } from './subscribe'
66

77
export { databasePlugin } from './optionsApi'
88

@@ -14,7 +14,7 @@ const ops: OperationsType = {
1414
remove: (array, index) => array.splice(index, 1),
1515
}
1616

17-
export interface _UseDatabaseRefOptions extends RTDBOptions {
17+
export interface _UseDatabaseRefOptions extends _DatabaseRefOptions {
1818
target?: Ref<unknown>
1919
}
2020

@@ -89,7 +89,7 @@ export function _useDatabaseRef(
8989
export function internalUnbind(
9090
key: string,
9191
unbinds: Record<string, UnbindType> | undefined,
92-
reset?: RTDBOptions['reset']
92+
reset?: _DatabaseRefOptions['reset']
9393
) {
9494
if (unbinds && unbinds[key]) {
9595
unbinds[key](reset)
@@ -108,7 +108,7 @@ export function internalUnbind(
108108
*/
109109
export function useList<T = unknown>(
110110
reference: DatabaseReference | Query,
111-
options?: RTDBOptions
111+
options?: _DatabaseRefOptions
112112
): _RefDatabase<T[]> {
113113
const unbinds = {}
114114
const data = ref<T[]>([]) as Ref<T[]>
@@ -120,7 +120,7 @@ export function useList<T = unknown>(
120120

121121
export function useObject<T = unknown>(
122122
reference: DatabaseReference,
123-
options?: RTDBOptions
123+
options?: _DatabaseRefOptions
124124
): _RefDatabase<T | undefined> {
125125
const data = ref<T>() as Ref<T | undefined>
126126
return _useDatabaseRef(reference, {
@@ -129,7 +129,7 @@ export function useObject<T = unknown>(
129129
}) as _RefDatabase<T | undefined>
130130
}
131131

132-
export const unbind = (target: Ref, reset?: RTDBOptions['reset']) =>
132+
export const unbind = (target: Ref, reset?: _DatabaseRefOptions['reset']) =>
133133
internalUnbind('', rtdbUnbinds.get(target), reset)
134134

135135
export interface _RefDatabase<T> extends _RefWithState<T, Error> {}

src/database/optionsApi.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
bindAsArray,
77
bindAsObject,
88
rtdbOptions,
9-
RTDBOptions,
9+
_DatabaseRefOptions,
1010
} from './subscribe'
1111

1212
/**
@@ -24,9 +24,9 @@ function getRef(refOrQuery: DatabaseReference | Query): DatabaseReference {
2424
export interface DatabasePluginOptions {
2525
bindName?: string
2626
unbindName?: string
27-
serialize?: RTDBOptions['serialize']
28-
reset?: RTDBOptions['reset']
29-
wait?: RTDBOptions['wait']
27+
serialize?: _DatabaseRefOptions['serialize']
28+
reset?: _DatabaseRefOptions['reset']
29+
wait?: _DatabaseRefOptions['wait']
3030
}
3131

3232
const databasePluginDefaults: Readonly<Required<DatabasePluginOptions>> = {
@@ -49,13 +49,13 @@ declare module '@vue/runtime-core' {
4949
$rtdbBind(
5050
name: string,
5151
reference: DatabaseReference | Query,
52-
options?: RTDBOptions
52+
options?: _DatabaseRefOptions
5353
): Promise<DataSnapshot>
5454

5555
/**
5656
* Unbinds a bound reference
5757
*/
58-
$rtdbUnbind: (name: string, reset?: RTDBOptions['reset']) => void
58+
$rtdbUnbind: (name: string, reset?: _DatabaseRefOptions['reset']) => void
5959

6060
/**
6161
* Bound database references
@@ -112,7 +112,7 @@ export function databasePlugin(
112112

113113
GlobalTarget[unbindName] = function rtdbUnbind(
114114
key: string,
115-
reset?: RTDBOptions['reset']
115+
reset?: _DatabaseRefOptions['reset']
116116
) {
117117
internalUnbind(key, rtdbUnbinds.get(this), reset)
118118
delete this.$firebaseRefs[key]
@@ -123,7 +123,7 @@ export function databasePlugin(
123123
this: ComponentPublicInstance,
124124
key: string,
125125
source: DatabaseReference | Query,
126-
userOptions?: RTDBOptions
126+
userOptions?: _DatabaseRefOptions
127127
) {
128128
const options = Object.assign({}, globalOptions, userOptions)
129129
const target = toRef(this.$data as any, key)

src/database/subscribe.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
2-
createRecordFromRTDBSnapshot,
2+
createRecordFromDatabaseSnapshot,
33
indexForKey,
4-
RTDBSerializer,
4+
DatabaseSnapshotSerializer,
55
} from './utils'
66
import { OperationsType, ResetOption } from '../shared'
77
import { ref, Ref, unref } from 'vue-demi'
@@ -16,23 +16,23 @@ import {
1616
} from 'firebase/database'
1717

1818
// TODO: rename to match where it's used
19-
export interface RTDBOptions {
19+
export interface _DatabaseRefOptions {
2020
reset?: ResetOption
21-
serialize?: RTDBSerializer
21+
serialize?: DatabaseSnapshotSerializer
2222
wait?: boolean
2323

2424
initialValue?: unknown
2525
}
2626

27-
export interface _GlobalRTDBOptions extends RTDBOptions {
27+
export interface _GlobalDatabaseRefOptions extends _DatabaseRefOptions {
2828
reset: ResetOption
29-
serialize: RTDBSerializer
29+
serialize: DatabaseSnapshotSerializer
3030
wait: boolean
3131
}
3232

33-
const DEFAULT_OPTIONS: _GlobalRTDBOptions = {
33+
const DEFAULT_OPTIONS: _GlobalDatabaseRefOptions = {
3434
reset: true,
35-
serialize: createRecordFromRTDBSnapshot,
35+
serialize: createRecordFromDatabaseSnapshot,
3636
wait: false,
3737
}
3838

@@ -53,14 +53,14 @@ interface BindAsObjectParameter extends CommonBindOptionsParameter {
5353
}
5454

5555
/**
56-
* Binds a RTDB reference as an object
56+
* Binds a Firebase Database reference as an object
5757
* @param param0
5858
* @param options
59-
* @returns a function to be called to stop listeninng for changes
59+
* @returns a function to be called to stop listening for changes
6060
*/
6161
export function bindAsObject(
6262
{ target, document, resolve, reject, ops }: BindAsObjectParameter,
63-
extraOptions: RTDBOptions = DEFAULT_OPTIONS
63+
extraOptions: _DatabaseRefOptions = DEFAULT_OPTIONS
6464
) {
6565
const key = 'value'
6666
const options = Object.assign({}, DEFAULT_OPTIONS, extraOptions)
@@ -102,7 +102,7 @@ interface BindAsArrayParameter extends CommonBindOptionsParameter {
102102
*/
103103
export function bindAsArray(
104104
{ target, collection, resolve, reject, ops }: BindAsArrayParameter,
105-
extraOptions: RTDBOptions = DEFAULT_OPTIONS
105+
extraOptions: _DatabaseRefOptions = DEFAULT_OPTIONS
106106
) {
107107
const options = Object.assign({}, DEFAULT_OPTIONS, extraOptions)
108108
const key = 'value'

src/database/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import type { DataSnapshot } from 'firebase/database'
22
import { isObject } from '../shared'
33

44
/**
5-
* Convert firebase RTDB snapshot into a bindable data record.
5+
* Convert firebase Database snapshot into a bindable data record.
66
*
77
* @param snapshot
88
* @return
99
*/
10-
export function createRecordFromRTDBSnapshot(snapshot: DataSnapshot): any {
10+
export function createRecordFromDatabaseSnapshot(snapshot: DataSnapshot): any {
1111
const value = snapshot.val()
1212
const res = isObject(value)
1313
? value
@@ -23,7 +23,7 @@ export function createRecordFromRTDBSnapshot(snapshot: DataSnapshot): any {
2323
return res
2424
}
2525

26-
export type RTDBSerializer = typeof createRecordFromRTDBSnapshot
26+
export type DatabaseSnapshotSerializer = typeof createRecordFromDatabaseSnapshot
2727

2828
/**
2929
* Find the index for an object with given key.

0 commit comments

Comments
 (0)