Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Cannot call method 'save' of undefined #76

Closed
mikermcneil opened this issue Dec 18, 2013 · 6 comments
Closed

Cannot call method 'save' of undefined #76

mikermcneil opened this issue Dec 18, 2013 · 6 comments

Comments

@mikermcneil
Copy link

Anyone else seen this? Here's how to reproduce (everything else is working great):

// I have a collection instance in the variable `theseThings`
// with a url hooked up (http://localhost:1337/things)
// The front-end is an HTML page served from a file URL, and the local server has CORS enabled, so everything works great.


// Get a few things from server..
theseThings.fetch();


//
// Kill server
//

// Now add a new thing
theseThings.add({});


//
// Start server again
//

// Now try to syncDirtyAndDestroyed()
theseThings.syncDirtyAndDestroyed();
Result:
theseThings.syncDirtyAndDestroyed();
TypeError: Cannot call method 'save' of undefined

Thanks!

Versions
  • Backbone.dualStorage version 1.1.0 (from bower)
  • Backbone 1.1.0 (from bower)
  • Underscore 1.5.2 (from bower)
  • jQuery 2.0.3 (from bower)
@nilbus
Copy link
Owner

nilbus commented Dec 20, 2013

You're not alone.

There can be a timing issue when calling syncDirtyAndDestroyed too quickly in succession, before the first call completes or fails.

I committed cd17ff2 to master as a workaround, which should address your problem. This change is not yet released with a version number.

@mikermcneil
Copy link
Author

@nilbus awesome, thank you!

@nilbus
Copy link
Owner

nilbus commented Dec 20, 2013

FYI, #35 is the issue open to address this.

@mikermcneil
Copy link
Author

@nilbus re: your comment here:

Have Backbone.dualStorage manage detecting the online/offline state, sync retries, etc. This would resolve #4 and #35, and allow for the deprecation of syncDirtyAndDestroyed.

Do you know off-hand if anyone is working on this "presence" feature? It's solveable with socket.io currently, but only if you're running Sails or another socket.io-compatible server, and there really ought to be a backend-agnostic solution.

We're working on a project where dualStorage covers two tricky use cases perfectly (queueing operations and intermediate caching from localstorage for fetches). Whether we need to adapt an existing solution to work w/ dualStorage or roll something, we're happy to jump in and help.

Thanks!

PS. A consideration- probably makes sense to break that part off into a separate module IMO, since there are at least a couple of other key use cases for it that I've come across ("isOnline status" for collaboration/social features and "time-on-site" user engagement measurements)

@mikermcneil
Copy link
Author

@nilbus re: #35 thanks, sorry to recreate the issue! I only tried searching the error message , which never seems to work :\

@nilbus
Copy link
Owner

nilbus commented Dec 20, 2013

On Fri, Dec 20, 2013 at 12:44 AM, Mike McNeil [email protected]:

@nilbus https://github.com/nilbus re: your comment herehttps://github.com//issues/65#issuecomment-28489104:

Have Backbone.dualStorage manage detecting the online/offline state, sync
retries, etc. This would resolve #4https://github.com/nilbus/Backbone.dualStorage/issues/4and
#35 #35, and allow
for the deprecation of syncDirtyAndDestroyed.

Do you know off-hand if anyone is working on this "presence" feature? It's
solveable with socket.io currently, but only if you're running Sails or
another socket.io-compatible server, and there really ought to be a
backend-agnostic solution.

No one is working on it now, as far as I know.

PS. A consideration- probably makes sense to break that part off into a
separate module IMO, since there are at least a couple of other key use
cases for it that I've come across ("isOnline status" for
collaboration/social feature and, "time-on-site" measurement of user
engagement)

Agreed. That makes sense to live as its own thing, which dualStorage could
have as a possibly optional runtime dependency.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants