Created
September 25, 2014 15:53
-
-
Save jmdobry/3a99d898aeb33aeaab28 to your computer and use it in GitHub Desktop.
Creating custom adapters for angular-data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('myApp', ['angular-data']).run('DS', 'DSCustomAdapter', function (DS, DSCustomAdapter) { | |
// register the adapter with the data store | |
DS.adapters.DSCustomAdapter = DSCustomAdapter; | |
// set your custom adapter as the default | |
DS.defaults.defaultAdapter = 'DSCustomAdapter'; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('myApp').provider('DSCustomAdapter', function () { | |
'use strict'; | |
var defaults = this.defaults = { | |
queryTransform: function (resourceName, params) { | |
return params; | |
} | |
}; | |
// inject whatever you need here | |
this.$get = ['$q', function ($q) { | |
return { | |
defaults: defaults, | |
// implement each function that will be used | |
find: function (resourceConfig, id, options) { | |
// "resourceConfig" will be the return value of DS.defineResource(...) | |
var deferred = $q.deferred(); | |
// asynchronously retrieve a single item from wherever | |
// then resolve or reject the promise | |
return deferred.promise; | |
}, | |
findAll: function (resourceConfig, params, options) {...}, | |
create: function create(resourceConfig, attrs, options) {...}, | |
update: function (resourceConfig, id, attrs, options) {...}, | |
updateAll: function (resourceConfig, attrs, params, options) {...}, | |
destroy: function (resourceConfig, id, options) {...}, | |
destroyAll: function destroyAll(resourceConfig, params, options) {...} | |
}; | |
}]; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment