goodeggs / angular-cached-resource

An AngularJS module to interact with RESTful resources, even when browser is offline
MIT License
216 stars 29 forks source link

Lowercase actions method are not taken into account. #26

Closed nimaen closed 10 years ago

nimaen commented 10 years ago

Hi,

I have just seen something wrong, at my first start with the project. I just replaced the $resource object by the $cachedResource and it went wrong... Just because I had some custom actions methods in lowercase.

I'm not arguing on which one is the best or correct form, but you might want to ensure the compatibility ;)

hazeledmands commented 10 years ago

Hi @Nimaen,

Is there any chance you could post an example of how you are using $cachedResource? I'm happy to help you figure out what's going wrong. We definitely do support lowercase actions :)

Best, Max

nimaen commented 10 years ago

Hey @demands, my bad, did not provide enough information ;) Let's say I create a UserResource object with a custom method getAll, I would do as follow :

angular.module("example.resources", ["ngCachedResource"])
    .factory("UserResource", ["$cachedResource", function($cachedResource) {
        return $cachedResource("someUserKey", "http://dummy.com/users", {}, {
            // Custom methods here
            getAll : {method: "get"}
        });
    }]);

Here, the problem is the post method. When injecting UserResource, I entend to do :

UserResource.getAll();

The fact is that getAlll is undefined under UserResource, BUT, is defined under UserResource.$resource.getAll().

That's my point here :) If I put now POST under the method attribute, it works as espected. Any ideas ? Am I clear enough ? :)

hazeledmands commented 10 years ago

Oh! Totally. Thanks for the bug report :) Working on a fix now.

hazeledmands commented 10 years ago

Sweet, you should be able to use actions with methods in whatever case you want, as of version 0.7.1. It'll even support getAll: { method: 'GeT' } if you want!

nimaen commented 10 years ago

No problem :) Thanks.

I was also wondering, it might be off topic, but why don't you store requests' responses on localStorage too ? If i'm not wrong, you're only storing requests and saves, not requests' responses.

hazeledmands commented 10 years ago

why don't you store requests' responses on localStorage too ? If i'm not wrong, you're only storing requests and saves, not requests' responses.

Not sure I understand your question. $cachedResource should store responses to all requests in the browser's cache (unless you've explicitly turned that off with the cache: false option on an action). If you're seeing anything different, then you might have found another bug. What's the behavior exactly?

Thanks, Max

nimaen commented 10 years ago

Seems like I was out of myself... I've just written a simple example and it works as expected. I might have wondered because of a write flag in local storage, something like that. My bad :/

hazeledmands commented 10 years ago

Np, thanks for double checking!