Code Monkey home page Code Monkey logo

js-model's People

Contributors

benpickles avatar cnandreu avatar ismasan avatar jlsync avatar olivernn avatar olly avatar pablobm avatar wildfalcon avatar

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

js-model's Issues

Runtime VERSION constant

...would be useful. In the case of embedding widgets in other sites where this library could potentially be loaded already it would be nice if version could be detected. It's a good practice for potentially common libraries. In jQuery and Underscore there's also a noConflict() method, but knowing the version would at least make it possible to detect if versions match. Usually VERSION constant within the namespace is a practice: Model.VERSION. What u say? :)

Roadmap?

model_class_methods.js was heavily updated and removed the all method along with many others in b09e2df. It looks like now we are to rely on a functional programming method for interacting with objects of the collection. Is that the case and can you give any details about what this move is all about?

model with REST persistence, when calling model.save(), no params are being passed

Hi,

I'm getting a weird issue with doing model.save() on a model which has restful persistence. When I call model.save(), it is not passing any params to the restful persistence path at all.

I've checked that attributes are set for the model, as well as the path passed to the Model.REST argument, they are both fine. Project.load() works fine in getting the collection of objects. I double-checked that there was nothing wrong with the json API being access by js-model by testing a POST request with RestClient in Ruby, and that worked fine. I'm at a loss; the problem seems to lie with js-model passing params when doing a post request.

This is on version 0.9.3 (minified) with jQuery 1.4.4 (minified).

I have a private repo where this is occurring. Let me know if you want access to it for debugging.

Regards,

Persistence freezing

If I use this.persistence(Model.localStorage); the Chrome freezes to the pint I have to restart it.

Any toughts?

Cross-domain support (JSON/P)

After some rumbling I got js-model to work with cross-domain scripting - which is vey much a requirement for most web apps today. Not complete, but here's how the AJAX call should look like:

return jQuery.ajax({
        type: method,
        url: url + '.json',
        dataType: "jsonp",
        jsonpCallback: 'JSONP',
        data: data,
        dataFilter: function(data, type) {
          return /\S/.test(data) ? data : null;
        },
        success: function(data) {
          self.xhrComplete({status: 200, responseText: data}, 'success', model, callback)
        },
        error: function(xhr, textStatus) {
          console.error(xhr)
        }
      });

As you can see I'm trying to fake a XHR-object here because XHR is not really used for JSONP-requests under the hood (using script tags hack), and "complete" callback don't appears to be triggered by jQuery for JSONP-requests. I'm hardcoding 200 status here which is a bit ugly I guess, but as I understand it JSONP-requests work a status code is not available - just error/success.

So personally I need this hack for my own and I bet plenty of js-model users will end up needing it as well. Is it of interest?

localStorage

Hello,

I'm having some problem at destroying models (called Lines). After calling the destroy method and refreshing the page, the load() method will still bring those same models to the list again:

  • list models by attribute
  • delete each model instance
  • refresh the page
  • Line.load()
  • Line.all() returns the same models that should have been destroyed

Both Chrome and Firefox have the same behavior. Am I missing something about the API?

Thank you!

nested structures possible?

Hi Ben,

thank your for the plugin!
Do you have a recommendation concerning nested models with arrays?
It seems, that
var post = new Post({ foo: ["bar","baz"] })
works well until I save it via REST - rails moans about the array instead of a hash.
Is it a bad idea overall, or do you think it would be possible to tweak rails' params-parsing or write an other persistence strategy?

-- Frank

validations are broken

Using jquery 1.3.1 when running the validation example in the read me post.valid() returns false when all the validations are met. Is there a requirement for jquery 1.4+?

Use $ instead of jQuery

If you use $ instead of jQuery in model_rest you can use other libraries than jQuery such as tire.js and zepto.js.

another possibility is to have an adapter incase those libraries are missing a feature it needs.

Bower Support

You should consider putting this library on Bower.

I install Sammy.js from Bower and it looks like there is a lot of talk online about using these two libraries together. It would be great if they were installable the same way.

"change" event is not triggered on attr(key, "val")

By example:

project.bind("change", function() { ... });

project.attr({ name: "Hello" });  /* triggers 'change' */
project.attr("name", "Hello");  /* doesn't trigger 'change' */

It seems like this is by design. Can I ask what's the rationale behind that?

Next version?

When will you release the next version?
Any future plans?

I really like the idea behind js-model and I would like to use it in my next project, but I can't use it if there is no further developement.

Especially I need to do some updates offline in localStorage and sync them with a REST api as soon as reconnected to the internet.

Model.save() and REST persistence

Hi Ben,

Thanks for sharing js-model, it's very nice to work with.

I am facing an issue however that might look simular to this one: #16, though I am not completely sure.

When I update the attributes of an existing model and call save afterward a put request is sent to the server. All is well but it seems like the request is not properly encoded. When I open up my Chrome developer tools and take a closer look in the headers section of the network tab, I can see that the data is sent as "request payload" rather than the expected "form data". Also this post (http://stackoverflow.com/questions/10494574/what-is-the-difference-between-form-data-and-request-payload) pushed me somewhat in the right direction, although I could not find the exact solution.

Regards,

Maarten

POST - REST persistence

var Project = new Model('project', function(){ this.persistence(Model.REST, "api/projects"); });
var project = new Project({name:"testing12345"});
project.save();

It will send data like this : {project: {name: "testing12345"} }
yet my backend expect just attributes {name:"testing12345"} . Can this be configured in js-model, or do I have to change my API ?

thx

Date Serialisation

I was playing with js-model over the weekend and dates in models don't work as I expected they would. Objects with properties set as dates get serialised to strings and the when the object is parsed from localstorage it returns a string.

I had a quick look into the problem and it seems like a custom replacer callback for the JSON.parse and JSON.stringify is needed to fix this.

unsafe multithread access to Model.collection

If you have a large collection of Projects and run something like,
Project.each(function(){ Project.remove(this)});
you'll find that
Project.count()
is not zero. I'm guessing there is concurrent activity between the index location and then splicing in Model.remove.

Maybe the collection could be made an object keyed on id: or some other primary key attribute to fix this problem.

Associations?

Any plans for rudimentary associations between models? How are you doing this now?

Destroy problem when used with Rails

Hi Ben,

Just noticed a problem when using with Rails.

Rails destroy actions return an empty string by default meaning the 'ajaxError' event gets triggered. This may well happen with updates too but I've not tested.

I'm not sure of the best way round this as there is already a ticket for Rails which they're not going to fix: https://rails.lighthouseapp.com/projects/8994/tickets/5199-respond_with-returns-on-put-and-delete-verb

What are your thoughts on this?

Cheers,

Jamie

on/off for bind/unbind

Hi,

This is very minor. But, I was wondering if you have considered using on/off for bind/unbind following the preferred convention in jQuery or some other libs.

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.