Git Product home page Git Product logo

backbone.iobind's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

backbone.iobind's Issues

handle iosync error

Hey
I hope i am not bugging you too much with my posts !
When you call Backbone.sync io, "emit" substitute the usual ajax call.

when server is not responding ajax sync call the error function with the http error. Could we handle this kind of error in backbone.io too ?

I am pretty new to Socket io so I don't know what are the best practices to deal with this errors, the simplest handler could look like that maybe

    //...
    var io = model.socket || window.socket || Backbone.socket;

    if (io.socket.connected === false) {
      options.error(new Error("socket is not connected"));
    } else {
      // ...
    }

Uncaught Error: Module name "jquery" has not been loaded yet for context: _. Use require([])

Hi.

I'm using grunt to build my project.
When I concat all requirejs files (all libraries and classes) using requirejs optimizer (r.js) I get error:
Module name "jquery" has not been loaded yet for context: _. Use require([])

According to http://requirejs.org/docs/errors.html#notloaded
error is caused by backbone.iobind and backbone.iosync Common JS require because there is is a require('name') call, but the 'name' module has not been loaded yet:

  // Common JS // require JS
  var _, $, Backbone, exports;
  if (typeof window === 'undefined' || typeof require === 'function') {
    $ = require('jquery');
    _ = require('underscore');
    Backbone = require('backbone');
    exports = Backbone;
    if (typeof module !== 'undefined') module.exports = exports;
  } else {
    $ = this.$;
    _ = this._;
    Backbone = this.Backbone;
    exports = this;
  }

I also declared dependencies in requirejs config to make backbone.iobind dependend on jquery, underscore and backbone, what in theory should solve loading problems, but it didn't.

But when I remove block completely, it works both in nonconcated project and also builded project.

So my quesion is can it be just removed also in git hub repos?

Version of libraries I'm using:

"requirejs": "~2.1.4",
"jquery": "~1.9.0",
"jquery-mobile": "1.3.1",
"underscore": "~1.4.3",
"backbone": "~1.0.0",
"backbone.iobind": "*"

Update your associated website with API docs

The website referenced in Github for API docs has very old versions of Backbone and Socket.io as dependencies (compared to the package.json).

Nothing super important, but I can't change that and I couldn't find a place to contact you outside of Github...so here it is.

:)

Can't get it to work with _id

Hi.

I can't get iosync/iobind to play nicely with MongoDB powered backends. I have set the idAttribute: '_id' on the collection and gave it an URL and did a .fetch().

app.vios.collection.models[0].get('_id')
// => 12345
app.vios.collection.get(app.vios.collection.models[0].get('_id'))
// => undefined

This works fine if I change all _id's to id's on my server side, but that's not a change I am dieing to make since I'm using _id across all of my services.

gr,

Tom

Improved amd/requirejs support

What I ultimately want to get to is like this example from backbone.modelbinding.

if (typeof define === 'function' && define.amd) {
    // AMD support
    define([
      'backbone',    // use Backbone 0.5.3-optamd3 branch (https://github.com/jrburke/backbone/tree/optamd3)
      'underscore',  // AMD supported
      'jquery'       // AMD supported
      ], function (Backbone, _, jQuery) {
        return modelbinding(Backbone, _, jQuery);
      });
} else {
    // No AMD, use Backbone namespace
    root.Backbone = Backbone || {};
    root.Backbone.ModelBinding = modelbinding(Backbone, _, jQuery);
}

sync options

iobind.sync does use options.url

what do you think about adding this piece of code taken from Backbone.Sync to enable this feature

    var getUrl = function (object) {

      if (options && options.url) {
        return _.isFunction(options.url) ? options.url() : options.url;
      }

      // ...
    };


// this way to trigger specialUrl:read, we can write 
collection.fetch(url: 'specialUrl') 

cannot install dependencies of the sample app via npm install

npm ERR! error installing [email protected] Error: No compatible version found: oath@'>=0.0.0- <0.1.0-'
npm ERR! error installing [email protected] Valid install targets:
npm ERR! error installing [email protected] ["0.1.0"]
npm ERR! error installing [email protected]     at installTargetsError (/usr/local/lib/node_modules/npm/lib/cache.js:424:10)
npm ERR! error installing [email protected]     at /usr/local/lib/node_modules/npm/lib/cache.js:406:17
npm ERR! error installing [email protected]     at saved (/usr/local/lib/node_modules/npm/lib/utils/npm-registry-client/get.js:136:7)
npm ERR! error installing [email protected]     at Object.cb [as oncomplete] (/usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:36:9)
npm ERR! Error: No compatible version found: oath@'>=0.0.0- <0.1.0-'
npm ERR! Valid install targets:
npm ERR! ["0.1.0"]
npm ERR!     at installTargetsError (/usr/local/lib/node_modules/npm/lib/cache.js:424:10)
npm ERR!     at /usr/local/lib/node_modules/npm/lib/cache.js:406:17
npm ERR!     at saved (/usr/local/lib/node_modules/npm/lib/utils/npm-registry-client/get.js:136:7)
npm ERR!     at Object.cb [as oncomplete] (/usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:36:9)
npm ERR! Report this *entire* log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <[email protected]>
npm ERR! 
npm ERR! System Darwin 11.2.0
npm ERR! command "node" "/usr/local/bin/npm" "install"
npm ERR! cwd /Users/moellenbeck/Dropbox/_dev/nodejs/backbone.iobind
npm ERR! node -v v0.6.5
npm ERR! npm -v 1.0.106
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     ./npm-debug.log
npm not ok

´´´

Seeking new project maintainer...

I am seeking a new maintainer for this project. I no longer have the time or resources to commit to it and it's current users deserve someone who does.

Here are my criteria:

  • You must be an active open-source contributor with a github profile. I would prefer transferring to a github organization but highly active individuals can also apply.
  • You should be using this project in production (or private beta), and I should be able to examine your usage of it.
  • You must agree to keep the MIT license.

Please contact me via my github profile @logicalparadox if you are interested.

Thank you,
Jake

Only the first part of URL is used for the namespace

In my case (and I it's very common when you have complex model) the url looks like this: /users/profiles/categories/{cat_id}

But Backbone.iosync only uses the first part as a namespace:

if (params.url) {
    params.url = _.result(params, 'url');
  } else {
    params.url = _.result(model, 'url') || urlError();
  }

  var cmd = params.url.split('/')
    , namespace = (cmd[0] !== '') ? cmd[0] : cmd[1]; // if leading slash, ignore

Which means all models which have a URL that starts with /users/... loose the rest of the URL.

Backbone 1.0 and iosync compatibility

Hey,
 
Now in backbone 1.0, "options.success" is a function with a single parameter "resp"

options.success = function (resp) {
...
}

I've had problems using bb1.0 version and "success object" when I did "fetch" in collections.

backbone.iosync.js

I changed (line 78) and it seems that "iosync" still works perfectly for me.

var success = options.success;
   options.success = function (resp) {
     if (success) success (resp); / / line 78
     model.trigger ('sync', model, resp, options);
   };

require js wrapper

Hello
great work first for this really nice plugin
I tried to drop in the code as is in my amd/require-js app and got an error on
exports = module.exports = ... as module is not defined
do we really need the "module.exports" ? It works fine once I removed it

Sending custom data with fetch() method

I was trying to do something like:

Tasks.fetch({data: {project: id}});

in order to fetch all tasks associated with given project, following what the Backbone documentation recommends. I noticed that the project id wasn't making it to node, however, when using iosync. I did a little digging and found this on line 56 of the iosync code:

params.data = model.toJSON() || {};

This replaces any data passed as an option of the fetch method with the model data. I modified this to read

if( !params.data ) {
  params.data = model.toJSON() || {};
}

Which sends custom data if it exists, or just the model data if it doesn't.

Is this the correct way to achieve this?

same host only?

Does this work only when the client and server is on the same host? I have an express server running on a remote machine, and my backbone app is on my local machine. And I just cant get this working. Any suggestions?

Handle both normal Backbone.sync and socket.io sync

I only have part of my api that is using socket.io. The other part is a pure reset AJAX model. How can I support a normal Backbone fetch but also utilize backbone.iobind for socket.io calls. Since backbone.iobind is overwriting Backbone.sync, it looks to be not possible. Any suggestions?

"Streaming" or partial collections

I like this library, But I'm missing feature I call partial processing (or streaming collections)

The main benefit of websockets is that server could send collection data that spans into multiple responses. It allows partial processing.

Wouldn't it be nice if this library supports collections streaming (or partial collections)?
So server can send chunks of data (flagged with partial: true) so client knows, that more data is comming, but also can process (render) partial results.

Currently this is not possible on client (backbone) side.

ioBind can't be used before the model has an id.

Obviously, the server can't trigger events on objects without an id, but it should be possible to ioBind an object before the id is set, and have it re-bind the socket.io event.

This issue also affects any other situation where the model id changes, such as a call to clear.

Namespace problem with parsing

I have a user object with /user url and no collections. IO.sync does not set the namespace right as cmd[0] is empty and cmd[1 ] is equal to "user". I switched to do namespace = cmd[1 ] for now but expect problems in the future.

require js wrapper

Hello
great work first for this really nice plugin
I tried to drop in the code as is in my amd/require-js app and got an error on
exports = module.exports = ... as module is not defined
do we really need the "module.exports" ? It works fine once I removed it

Only get create event, should be updating

Hey,

This isn't so much a bug (I assume), as a problem I am having with implementation. Basically every time I call save on a backbone model, it sends an event create out of the iosync/iobind each time. I know the first .save is suppose to create, but afterward it should do an update instead. Anyone else ever have this problem?

Tiny code implmentation below....which is a part of the item's view.

    update: function(e) {
        var text = $(e.target).html();
        this.model.save({
            title: text
        });
    }

Any suggestions would be appreciated! Thanks for making this!

Exceeding number of args passed in success()

In line 77 of backbone.iosync.js, 'if (success) success(model, resp, options);' passes three arguments to the success(), this will cause the local model instances fail to update themselves.

If you look at backbone.js, line 430, 'options.success = function(resp) {' only takes one argument, that is the response object from server.

I ran into a situation that lead me to this problem after one of our developer introduced a different version of backbone.iobind.

iosync does not allow to pass options via Collection.fetch()

In Backbone you can pass options to the server via the fetch method.

This could contain relevant information like what models to fetch.

Right now, the current sync() method implementation overwrites this data with the JSON representation of a given model.
This should be refactored, so that the model data is passed along with the given fetch options.

This is how we implemented it in a quick hack:

params.data = params.data || {};
params.data.model = model.toJSON() || {};

.fetch() on model is broken.

When fetching a single model, the slash and id in the URL are stripped off, and the request is sent to the collection instead, so all models in the collection are added as properties on the model being "fetched".

A simple workaround is to never fetch a model, but the entire collection instead.

What about the history?

With backbone.iobind its not neccessarry to use a approuter, isnt it?
i get incomming items directly via this.ioBind.
So, how to use the pushstate?
Thx!

Backbone.ioBind example: update, delete event at server

I'm backbone beginner. I think using socket.io instead of REST is wonderful. I try this backbone.iobind example in github. When i ran this project, i found that i can't remove todo item. Open project and open this TodoListItem view, i toggled some break point, TodoListItem view fired up completed and delete event. Run it step by step when it pass over

this.model.save({ completed: !!!status });

and observe this console log at server, socket at server doesn't got any update event???

Thanks for any help!!!

support for require.js 2.x

Hello,

I'm trying to use backbone.iobind with require.js
I have the following error message

Uncaught ReferenceError: module is not defined at backbone.iosync.js:8
Uncaught ReferenceError: module is not defined at backbone.iosync.js:8

my shim config is set as follow

shim: {
    backbone: {
        deps: ["jquery", "underscore"],
        exports: "Backbone"
    },
    underscore: {
        exports: '_'
    },        
    iosync: {
      deps: ["jquery", "underscore"],
      exports: "iosync"
    },
    iobind: {
      deps: ["jquery", "underscore", "iosync"],
      exports: "iobind"
    }
}

Could you please tell me if i have something wrong and if not when you are planning to support requirejs 2x ?

many thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.