Backbone.js binding (BackFire) model destroy function not working - firebase

I get the following error when i try to call destroy function to my Backbone Model:
Uncaught TypeError: Cannot call method 'apply' of undefined backbone-firebase.js:126
Backbone.Firebase.sync backbone-firebase.js:126
Backbone.sync backbone-firebase.js:154
h.extend.sync backbone-min.js:1
h.extend.destroy backbone-min.js:1
Backbone.View.extend.remove sample.html:79
p.event.dispatch jquery.min.js:2
g.handle.h
Code: http://dl.dropboxusercontent.com/u/14749491/sample.html

Since you're using the "implicit" sync method, don't use destroy to remove the model, use the remove method on the collection instead.
If you'd like to use destroy, I recommend using the "explicit" sync method,,using Backbone.Collection.extend with a firebase property. More information on these two methods here: https://github.com/firebase/backfire

I don't know anything about BackFire. But it appears to be a conflict between FireBase and BackBone-FireBase. Since the code you are loading from the FireBase cdn is minified method names (like delete in this case) have been changed. Try using the unminified version of FireBase and see if it works correctly.

Related

Problem when retrieving uploaded file with Firebase Storage using Redux Saga

I'm using redux saga with firebase in an app. When I need to use the firebase storage and I need to get the download URL of a file I just upload:
this doesn't work
yield call (uploadTask.snapshot.ref.getDownloadURL);
but this work
yield call (() => uploadTask.snapshot.ref.getDownloadURL());
can anyone help me understand why the first option isn't working? I didn't understand the difference between these approaches :)
The difference between those is what value this has once getDownloadURL is running. The first version will have this equal to the window object (in non-strict mode) or undefined (in strict mode), while the latter will have this equal to uploadTask.snapshot.ref.
The call effect does have a couple of overloads which let you specify this. You can see them listed here, but one example is to pass in an array as the first argument, as in:
yield call([uploadTask.snapshot.ref, uploadTask.snapshot.ref.getDownloadURL])

What the proper way to avoid console warning, when meteor collection is not ready

Every time I refresh the page I receive the following console warning for every single helper that is returning something to template from collection. I know the reason is because the subscription is not ready yet, but what is the solution?
Exception in template helper: TypeError: Cannot read property 'x' of undefined.
I'm already using if(collection.find({}) !== undefined) , but this makes my codes so messy, there must be a way to fix this issue. then I tried guards and still not 100% solved.
In addition to Brendan's answer, using Blaze you can check if the subscriptions for the template is ready using
this.subscriptionsReady()
Which checks all the subscriptions scoped to the template with
this.subscribe()
in your onCreated or onRendered blocks
Meteor.subscribe returns a handle with a reactive method called .ready(). You can use that in your helper to only return the mongo cursor once it's ready.
Edit: docs

Meteor.autorun vs Tracker.autorun?

What is the difference between Meteor.autorun and Tracker.autorun?
are they just aliases?
is one deprecated?
is there any instance where one is preferable to the other?
I'm well aware of the difference in using this.autorun in template lifecycle callbacks, but have seen these two used interchangeably and just want to be sure I haven't missed a trick.
Well, it can easily be found out with the identity operator.
This will be false because it is not the same function:
(function() {} === function() {})
Let's try with the two autorun :
(Meteor.autorun === Tracker.autorun)
This returns true. So yes it's only a pure alias.
However, only Tracker.autorun is documented. I suspect some kind of old API left for compatibility...
Let's check some Meteor code on GitHub!
File : deprecated.js
Meteor.autorun = Tracker.autorun;
This is in deprecated.js, it says some things about //Deprecated functions and some backward compatibility with Meteor 0.5.4. It seems pretty clear which one you should use.
You can find some other old timers in there, such as Deps...
Try to run Meteor.autorun(); in the console, it throws the following error Uncaught Error: Tracker.autorun requires a function argument like you were trying to run Tracker.autorun();

firebase ios gooffline remove observers

Simple question:
Will all obersvers automatically removed when I use goOffline (disconnect to firebase) ?
If not, is there another way to do it, because removeAllOberserves doesn't seem to work or must I keep an array of single handles?
UPDATE
I answer myself.
removeAllOberserves works well, if you call it with the reference you used to set the observer!
Example:
Firebase *userThreadRef;
userThreadRef = [userRef appendPathComponent: ThreadsPath];
[userThreadRef observeEventType: FEventTypeChildAdded withBlock: ^(FDataSnapshot *snapshot) {
...
}];
....
[userThreadRef removeAllObservers];
Do not use a new reference like this:
Firebase *newUserThreadRef = [userRef appendPathComponent: ThreadsPath];
[newUserThreadRef removeAllObservers];
Will all observers automatically removed when I use goOffline (disconnect to firebase) ?
No. Calling goOffline() will not automatically remove observers/listeners.
is there another way to do it, because removeAllOberserves doesn't seem to work or must I keep an array of single handles?
It's hard to say without seeing your code, but likely your expectations are just wrong.
You'll need to call removeAllObservers() on each reference. The All in the method name is for the fact that it removes the observers for all event types, not for all references.

Can I return an async value (a Promise) from a Meteor helper?

A Promise is an object type which serves as a placeholder for a future result,
such as the body of an HTTP request, or the return value of a Meteor method call.
Basically any function that forces you to pass a callback to recieve its
return value (instead of just returning it) is said to be an async function,
and the value it gives back can be represented by a Promise.
The issue in Meteor is that helper methods are only intended to work with
synchronous values - such as the text in a web page, or the contents of a
Minimongo collection. When you return a Promise from one, the helper
shows [object Promise] instead of the resolved value
does not update when the promise resolves
Some attempts at solving this exist: simple:reactive-method
and arsnebula:reactive-promise, but they require you to change your helpers to a certain style, or only work with Meteor.call instead of just simply allowing a generic promise to be returned.
Is there something existing I've overlooked, or is there a solution in the works? I've been experimenting with this for some time, and may work on something myself if there's not an official answer.
Even with respect to other libraries out there, I think the answer for now is to go with the package deanius:promise (disclaimer: I authored it, with input from the authors of some other packages).
It does what the question asks, and adds some nice touches like controllable error and loading messages.

Resources