mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-23 05:25:47 +00:00
make xhr just a method
This commit is contained in:
parent
2df072e3f8
commit
c9aba8b442
5 changed files with 12 additions and 7 deletions
|
|
@ -7,7 +7,7 @@ $(document).ready(function(){
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var resourceFactory = new ResourceFactory({method: xhr});
|
var resourceFactory = new ResourceFactory(xhr);
|
||||||
|
|
||||||
var Tweeter = resourceFactory.route("http://twitter.com/statuses/:service:username.json", {}, {
|
var Tweeter = resourceFactory.route("http://twitter.com/statuses/:service:username.json", {}, {
|
||||||
home: {method:'GET', params: {service:'home_timeline'}, isArray:true },
|
home: {method:'GET', params: {service:'home_timeline'}, isArray:true },
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,10 @@ load:
|
||||||
- lib/underscore/underscore.js
|
- lib/underscore/underscore.js
|
||||||
- src/Angular.js
|
- src/Angular.js
|
||||||
- src/*.js
|
- src/*.js
|
||||||
- src/test/_namespace.js
|
- src/scenario/_namespace.js
|
||||||
- src/test/*.js
|
- src/scenario/*.js
|
||||||
- test/testabilityPatch.js
|
- test/testabilityPatch.js
|
||||||
- test/test/*.js
|
- test/scenario/*.js
|
||||||
- test/*.js
|
- test/*.js
|
||||||
|
|
||||||
exclude:
|
exclude:
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ ResourceFactory.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
var value = action.isArray ? [] : new Resource(data);
|
var value = action.isArray ? [] : new Resource(data);
|
||||||
self.xhr.method(action.method, route.url($.extend({}, action.params || {}, extractParams(data), params)), data, function(response) {
|
self.xhr(action.method, route.url($.extend({}, action.params || {}, extractParams(data), params)), data, function(response) {
|
||||||
if (action.isArray) {
|
if (action.isArray) {
|
||||||
foreach(response, function(item){
|
foreach(response, function(item){
|
||||||
value.push(new Resource(item));
|
value.push(new Resource(item));
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ describe("resource", function() {
|
||||||
|
|
||||||
beforeEach(function(){
|
beforeEach(function(){
|
||||||
xhr = new MockXHR();
|
xhr = new MockXHR();
|
||||||
resource = new ResourceFactory(xhr);
|
resource = new ResourceFactory(_(xhr.method).bind(xhr));
|
||||||
CreditCard = resource.route('/CreditCard/:id:verb', {id:'@id.key'}, {
|
CreditCard = resource.route('/CreditCard/:id:verb', {id:'@id.key'}, {
|
||||||
charge:{
|
charge:{
|
||||||
method:'POST',
|
method:'POST',
|
||||||
|
|
@ -80,6 +80,11 @@ describe("resource", function() {
|
||||||
expect(typeof CreditCard.query).toBe('function');
|
expect(typeof CreditCard.query).toBe('function');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should default to empty parameters', function(){
|
||||||
|
xhr.expectGET('URL').respond({});
|
||||||
|
resource.route('URL').query();
|
||||||
|
});
|
||||||
|
|
||||||
it("should build resource with default param", function(){
|
it("should build resource with default param", function(){
|
||||||
xhr.expectGET('/Order/123/Line/456.visa?minimum=0.05').respond({id:'abc'});
|
xhr.expectGET('/Order/123/Line/456.visa?minimum=0.05').respond({id:'abc'});
|
||||||
var LineItem = resource.route('/Order/:orderId/Line/:id:verb', {orderId: '123', id: '@id.key', verb:'.visa', minimum:0.05});
|
var LineItem = resource.route('/Order/:orderId/Line/:id:verb', {orderId: '123', id: '@id.key', verb:'.visa', minimum:0.05});
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,6 @@ StepsTest = TestCase("StepsTest");
|
||||||
|
|
||||||
StepsTest.prototype.testGivenDataset=function(){
|
StepsTest.prototype.testGivenDataset=function(){
|
||||||
var self = {frame:{}, dataset:[]};
|
var self = {frame:{}, dataset:[]};
|
||||||
angular.test.GIVEN.dataset.call(self);
|
angular.scenario.GIVEN.dataset.call(self);
|
||||||
assertEquals('$DATASET:{"dataset":[]}', self.frame.name);
|
assertEquals('$DATASET:{"dataset":[]}', self.frame.name);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue