-
-
Notifications
You must be signed in to change notification settings - Fork 342
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
Conversation
Can you just use |
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. |
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. |
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 |
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! |
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 |
@DaBs Can you add a test, please? |
@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() |
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.
This can be moved inside the it
function as it's only used there
@DaBs Yes, thank you. |
@@ -25,6 +27,36 @@ describe('VueFire', function () { | |||
}) | |||
}) | |||
|
|||
describe('is callable as Function', function () { |
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.
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 () { |
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.
Do you actually need to have a child component?
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.
It could easily be simplified to simply test the call of the function. I'll change immediately.
@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 😄 |
@DaBs It's ok, I actually feel being pushy 😓 |
@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 |
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 think it makes sense to move this one line below, so if the function is returning nothing we can skip too
@DaBs That's okay 😄 |
@@ -196,8 +196,9 @@ function ensureRefs (vm) { | |||
} | |||
|
|||
var init = function () { | |||
if (!this.$options.firebase) return |
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 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
What is status on this PR? 😄 |
@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? |
@posva Ah, damn, that reoccured. Will do ASAP. |
@posva This should do it 😄 |
@DaBs Thank you very much! I'm merging this and adding some minor changes to the test! |
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.