-
-
Notifications
You must be signed in to change notification settings - Fork 344
Added custom createSnapshot support #291
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
Closed
Closed
Changes from 13 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
7b5d852
Since the issue pointed already has a merged PR and typescript was up…
trickstival cfe843c
passing options to createSnapshot and added custom createSnapshot sup…
trickstival 693bf30
added tests for custom createSnapshot
trickstival 4af4d93
Fixed test to return data
trickstival 7d6accc
Added createSnapshot docs
trickstival 24ebfe7
Using defineProperties instead of spread in docs to avoid unnecessary…
trickstival 35d2f1d
more info in docs
trickstival cafc175
Added vue-test-utils to avoid global Vues properties conflict
trickstival 38d20e0
removed vue test utils in favor of Vue.extend
trickstival 731b22d
no need to pass object with options
trickstival da3ade6
Added empty line between tests
trickstival cde8da3
Added createSnapshot types
trickstival cc00b06
No need for comma
trickstival 936c7ad
refactor(core): rename createSnapshot to serialize
posva 67f9cf8
feat(core): allow serialize function for RTDB
posva 0375464
chore: format
posva 5a0e23f
feat(vuefire): add serialize option globally and locally ($bind)
posva ac36b90
types(vuefire): fix typing for new option serialize
posva dae5e13
Merge branch 'master' into issue-240
posva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,10 +1,45 @@ | ||
import { firestorePlugin } from '../src' | ||
import { Vue } from '@posva/vuefire-test-helpers' | ||
import { db, delay, Vue } from '@posva/vuefire-test-helpers' | ||
|
||
const createLocalVue = () => { | ||
const newVue = Vue.extend() | ||
newVue.config = Vue.config | ||
return newVue | ||
} | ||
|
||
describe('Firestore: plugin options', () => { | ||
it('allows customizing $rtdbBind', () => { | ||
Vue.use(firestorePlugin, { bindName: '$myBind', unbindName: '$myUnbind' }) | ||
expect(typeof Vue.prototype.$myBind).toBe('function') | ||
expect(typeof Vue.prototype.$myUnbind).toBe('function') | ||
const LocalVue = createLocalVue() | ||
LocalVue.use(firestorePlugin, { bindName: '$myBind', unbindName: '$myUnbind' }) | ||
expect(typeof LocalVue.prototype.$myBind).toBe('function') | ||
expect(typeof LocalVue.prototype.$myUnbind).toBe('function') | ||
}) | ||
|
||
it('allows global use of a custom createSnapshot function', async () => { | ||
trickstival marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const LocalVue = createLocalVue() | ||
const pluginOptions = { | ||
createSnapshot: jest.fn((documentSnapshot) => { | ||
return { | ||
customId: documentSnapshot.id, | ||
globalIsBar: documentSnapshot.data().foo === 'bar', | ||
stuff: documentSnapshot.data() | ||
} | ||
}) | ||
} | ||
LocalVue.use(firestorePlugin, pluginOptions) | ||
|
||
const items = db.collection() | ||
const item = items.doc() | ||
const itemMock = { foo: 'bar' } | ||
await item.set(itemMock) | ||
|
||
const vm = new LocalVue({ | ||
data: () => ({ items: [] }), | ||
firestore: { items } | ||
}) | ||
await delay(5) | ||
expect(pluginOptions.createSnapshot).toHaveBeenCalledTimes(1) | ||
expect(Array.isArray(vm.items)).toBe(true) | ||
expect(vm.items[0]).toEqual({ customId: '0', globalIsBar: true, stuff: itemMock }) | ||
}) | ||
}) |
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about the naming because a snapshot has a particular meaning in Firestore, so let's try to find other alternatives. Maybe
serializeSnapshot
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe something with
populate
would be nice, since it's gonna get the firestore data and populate the vm.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed this message, sorry :(
I think we should emphasize on the fact that it transforms the data coming from Firebase before we set it on the instance, that's why I think the verb should be related to that with something like serialize or serializer