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

Enabled firebase to be called as function, thus enabling patterns where Firebase ref's are stored in root component #25

Merged
merged 13 commits into from
Sep 9, 2016

Conversation

DaBs
Copy link

@DaBs DaBs commented Aug 10, 2016

This pull request will enable using the firebase option in the same way as the data option, by calling it as a function and returning an object. This allows for coding patterns where you originally define the Firebase references as data in the root component, but want to use the later on in child components, e.g.

export default {
    ...,
    firebase() {
        return {
            someArray: this.$root.database.ref('someArray')
        }
    },
    ...
}

@jwngr
Copy link

jwngr commented Aug 10, 2016

Can you just use firebase.database.ref('someArray') instead this.$root.database.ref('someArray')? That should make it so that you don't need to have a function here and it's even fewer characters.

@DaBs
Copy link
Author

DaBs commented Aug 10, 2016

Hm, sure, albeit this means you have to (with ES6 modules atleast) import the firebase module everywhere you want to use it, which is then a lot more characters than the above mentioned (if that's what we're measuring). Furthermore, I don't understand why this would not be intended behaviour, seeing as some other VueJS options. like data, is capable of being defined this way, and that the VueFire basicly mirrors the data options to a degree.

@jwngr
Copy link

jwngr commented Aug 10, 2016

The fewer characters was a bit tongue-in-cheek. I'll leave it to Evan to comment on whether or not this makes sense from a Vue perspective. From a Firebase perspective though, I think it would be a bit redundant.

@DaBs
Copy link
Author

DaBs commented Aug 10, 2016

Heh, well aware, I was just throwing it right back at you in the same manner. 😛 No offence taken. And I realise that this is sort of opposite of the idea behind how Firebase wants to both store its own state and references, but attempting to utilize this in a VueJS component context, it made little sense why it wouldn't behave like the data() { ... } option, as it to some degree replaces that in a VueJS + Firebase app.

@jwngr
Copy link

jwngr commented Aug 10, 2016

Haha makes sense 😄 I am not familiar enough with VueJS to say whether or not this is a good idea. It certainly seems like it takes very little code to support and I guess I don't see a reason not to include it, but I'll leave that to Evan to decide.

Thanks for the contribution by the way! I'm always happy to see the community getting involved!

@DaBs
Copy link
Author

DaBs commented Aug 10, 2016

No problem, I'm just happy that two of my favourite stack choices right now have a well-functioning module and I'll gladly contribute to ensure that it continues to be well-functioning 😄 Now we just wait for Evan

@posva
Copy link
Member

posva commented Aug 11, 2016

@DaBs Can you add a test, please?
Also, I think you can remove the compiled version. That seems to be done in a separate commit

@DaBs
Copy link
Author

DaBs commented Aug 11, 2016

@posva I'm not sure if this covers what you wanted from a test case, but it tests the basic functionality of whether or not you can use the firebase option as a function. And the compiled version seems to get created as a build artifact when you run the tests?


beforeEach(function (done) {
firebaseRef = firebaseApp.database().ref()
firebaseDb = firebaseApp.database()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be moved inside the it function as it's only used there

@posva
Copy link
Member

posva commented Aug 11, 2016

@DaBs Yes, thank you.
About the compiled version, you'll have to rebase and remove the modification in the build. You have to commit everything but the dist files.

@@ -25,6 +27,36 @@ describe('VueFire', function () {
})
})

describe('is callable as Function', function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The title is missing something about option, which is what you're actually changing. I'd name it something like support Function options

components: {
'child-component': Vue.extend({
name: 'ChildComponent',
firebase: function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you actually need to have a child component?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could easily be simplified to simply test the call of the function. I'll change immediately.

@DaBs
Copy link
Author

DaBs commented Aug 15, 2016

@posva Does the test satisfy the standard? I'm sorry it took so long to get a proper test, but writing unit tests in chai is relatively new for me 😄

@posva
Copy link
Member

posva commented Aug 15, 2016

@DaBs It's ok, I actually feel being pushy 😓
The unit test is much better that way. It'd be perfect if you can use a spy and check it gets called only once after the $mount
I'd also remove the regex on the throw. If it throws anything it can be considered as a failure

@DaBs
Copy link
Author

DaBs commented Aug 23, 2016

@posva Sorry for the delay, I was busy most of the week. The latest commit should have added both a spy and removed the regex 😄

@@ -198,6 +198,7 @@ function ensureRefs (vm) {
var init = function () {
var bindings = this.$options.firebase
if (!bindings) return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to move this one line below, so if the function is returning nothing we can skip too

@posva
Copy link
Member

posva commented Aug 23, 2016

@DaBs That's okay 😄

@@ -196,8 +196,9 @@ function ensureRefs (vm) {
}

var init = function () {
if (!this.$options.firebase) return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't clear about this, sorry. I was thinking about this:

var bindings = this.$options.firebase
if (typeof bindings === 'function') bindings = bindings.call(this)
if (!bindings) return

@DaBs
Copy link
Author

DaBs commented Aug 30, 2016

What is status on this PR? 😄

@posva
Copy link
Member

posva commented Aug 30, 2016

@DaBs Sorry for not giving you any updates! Can you remove the modifications on the dist folder, so we only keep the src and test modifications?

@DaBs
Copy link
Author

DaBs commented Aug 30, 2016

@posva Ah, damn, that reoccured. Will do ASAP.

@DaBs
Copy link
Author

DaBs commented Aug 31, 2016

@posva This should do it 😄

@posva
Copy link
Member

posva commented Sep 9, 2016

@DaBs Thank you very much! I'm merging this and adding some minor changes to the test!

@posva posva merged commit 195ea7d into vuejs:master Sep 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants