1
+ /**
2
+ * @author Jason Dobry <[email protected] >
3
+ * @file angular-data.js
4
+ * @version 0.5.0 - Homepage <http://jmdobry.github.io/angular-data/>
5
+ * @copyright (c) 2014 Jason Dobry <https://github.com/jmdobry/angular-data>
6
+ * @license MIT <https://github.com/jmdobry/angular-data/blob/master/LICENSE>
7
+ *
8
+ * @overview Data store for Angular.js.
9
+ */
1
10
require = ( function e ( t , n , r ) { function s ( o , u ) { if ( ! n [ o ] ) { if ( ! t [ o ] ) { var a = typeof require == "function" && require ; if ( ! u && a ) return a ( o , ! 0 ) ; if ( i ) return i ( o , ! 0 ) ; throw new Error ( "Cannot find module '" + o + "'" ) } var f = n [ o ] = { exports :{ } } ; t [ o ] [ 0 ] . call ( f . exports , function ( e ) { var n = t [ o ] [ 1 ] [ e ] ; return s ( n ?n :e ) } , f , f . exports , e , t , n , r ) } return n [ o ] . exports } var i = typeof require == "function" && require ; for ( var o = 0 ; o < r . length ; o ++ ) s ( r [ o ] ) ; return s } ) ( { 1 :[ function ( require , module , exports ) {
2
11
var indexOf = require ( './indexOf' ) ;
3
12
@@ -1953,7 +1962,6 @@ module.exports = destroy;
1953
1962
var utils = require ( 'utils' ) ,
1954
1963
errors = require ( 'errors' ) ,
1955
1964
services = require ( 'services' ) ,
1956
- GET = require ( '../../http' ) . GET ,
1957
1965
errorPrefix = 'DS.find(resourceName, id[, options]): ' ;
1958
1966
1959
1967
/**
@@ -2023,7 +2031,7 @@ function find(resourceName, id, options) {
2023
2031
2024
2032
if ( ! ( id in resource . completedQueries ) ) {
2025
2033
if ( ! ( id in resource . pendingQueries ) ) {
2026
- promise = resource . pendingQueries [ id ] = GET ( utils . makePath ( resource . baseUrl , resource . endpoint , id ) , null )
2034
+ promise = resource . pendingQueries [ id ] = _this . GET ( utils . makePath ( resource . baseUrl , resource . endpoint , id ) , null )
2027
2035
. then ( function ( data ) {
2028
2036
// Query is no longer pending
2029
2037
delete resource . pendingQueries [ id ] ;
@@ -2046,11 +2054,10 @@ function find(resourceName, id, options) {
2046
2054
2047
2055
module . exports = find ;
2048
2056
2049
- } , { "../../http" : 34 , " errors" :"hIh4e1" , "services" :"cX8q+p" , "utils" :"uE/lJt" } ] , 30 :[ function ( require , module , exports ) {
2057
+ } , { "errors" :"hIh4e1" , "services" :"cX8q+p" , "utils" :"uE/lJt" } ] , 30 :[ function ( require , module , exports ) {
2050
2058
var utils = require ( 'utils' ) ,
2051
2059
errors = require ( 'errors' ) ,
2052
2060
services = require ( 'services' ) ,
2053
- GET = require ( '../../http' ) . GET ,
2054
2061
errorPrefix = 'DS.findAll(resourceName, params[, options]): ' ;
2055
2062
2056
2063
function processResults ( data , resourceName , queryHash ) {
@@ -2068,7 +2075,7 @@ function processResults(data, resourceName, queryHash) {
2068
2075
}
2069
2076
2070
2077
// Update the data store's index for this resource
2071
- resource . index = utils . toLookup ( resource . collection , resource . idAttribute || services . config . idAttribute || 'id' ) ;
2078
+ resource . index = utils . toLookup ( resource . collection , resource . idAttribute ) ;
2072
2079
2073
2080
// Update modified timestamp of collection
2074
2081
resource . collectionModified = utils . updateTimestamp ( resource . collectionModified ) ;
@@ -2090,7 +2097,7 @@ function _findAll(resourceName, params, options) {
2090
2097
if ( ! ( queryHash in resource . pendingQueries ) ) {
2091
2098
2092
2099
// This particular query has never even been made
2093
- resource . pendingQueries [ queryHash ] = GET ( utils . makePath ( resource . baseUrl , resource . endpoint ) , { params : params } )
2100
+ resource . pendingQueries [ queryHash ] = _this . GET ( utils . makePath ( resource . baseUrl , resource . endpoint ) , { params : params } )
2094
2101
. then ( function ( data ) {
2095
2102
try {
2096
2103
return processResults . apply ( _this , [ data , resourceName , queryHash ] ) ;
@@ -2202,7 +2209,7 @@ function findAll(resourceName, params, options) {
2202
2209
2203
2210
module . exports = findAll ;
2204
2211
2205
- } , { "../../http" : 34 , " errors" :"hIh4e1" , "services" :"cX8q+p" , "utils" :"uE/lJt" } ] , 31 :[ function ( require , module , exports ) {
2212
+ } , { "errors" :"hIh4e1" , "services" :"cX8q+p" , "utils" :"uE/lJt" } ] , 31 :[ function ( require , module , exports ) {
2206
2213
module . exports = {
2207
2214
/**
2208
2215
* @doc method
@@ -2269,8 +2276,7 @@ module.exports = {
2269
2276
var utils = require ( 'utils' ) ,
2270
2277
errors = require ( 'errors' ) ,
2271
2278
services = require ( 'services' ) ,
2272
- PUT = require ( '../../http' ) . PUT ,
2273
- errorPrefix = 'DS.refresh(resourceName, id): ' ;
2279
+ errorPrefix = 'DS.refresh(resourceName, id[, options]): ' ;
2274
2280
2275
2281
/**
2276
2282
* @doc method
@@ -2329,21 +2335,23 @@ function refresh(resourceName, id, options) {
2329
2335
if ( ! services . store [ resourceName ] ) {
2330
2336
throw new errors . RuntimeError ( errorPrefix + resourceName + ' is not a registered resource!' ) ;
2331
2337
} else if ( ! utils . isString ( id ) && ! utils . isNumber ( id ) ) {
2332
- throw new errors . IllegalArgumentError ( 'DS.refresh(resourceName, id): id: Must be a string or a number!', { id : { actual : typeof id , expected : 'string|number' } } ) ;
2338
+ throw new errors . IllegalArgumentError ( errorPrefix + ' id: Must be a string or a number!', { id : { actual : typeof id , expected : 'string|number' } } ) ;
2333
2339
} else if ( ! utils . isObject ( options ) ) {
2334
2340
throw new errors . IllegalArgumentError ( errorPrefix + 'options: Must be an object!' , { options : { actual : typeof options , expected : 'object' } } ) ;
2335
- }
2336
-
2337
- if ( id in services . store [ resourceName ] . index ) {
2338
- return this . find ( resourceName , id , true ) ;
2339
2341
} else {
2340
- return false ;
2342
+ options . bypassCache = true ;
2343
+
2344
+ if ( id in services . store [ resourceName ] . index ) {
2345
+ return this . find ( resourceName , id , options ) ;
2346
+ } else {
2347
+ return false ;
2348
+ }
2341
2349
}
2342
2350
}
2343
2351
2344
2352
module . exports = refresh ;
2345
2353
2346
- } , { "../../http" : 34 , " errors" :"hIh4e1" , "services" :"cX8q+p" , "utils" :"uE/lJt" } ] , 33 :[ function ( require , module , exports ) {
2354
+ } , { "errors" :"hIh4e1" , "services" :"cX8q+p" , "utils" :"uE/lJt" } ] , 33 :[ function ( require , module , exports ) {
2347
2355
var utils = require ( 'utils' ) ,
2348
2356
errors = require ( 'errors' ) ,
2349
2357
services = require ( 'services' ) ,
@@ -2995,9 +3003,9 @@ Resource.prototype = services.config;
2995
3003
* idAttribute: '_id',
2996
3004
* endpoint: '/documents
2997
3005
* baseUrl: 'http://myapp.com/api',
2998
- * validate : function (attrs, options , cb) {
3006
+ * beforeDestroy : function (resourceName attrs , cb) {
2999
3007
* console.log('looks good to me');
3000
- * cb(null);
3008
+ * cb(null, attrs );
3001
3009
* }
3002
3010
* });
3003
3011
* ```
@@ -3926,7 +3934,9 @@ function previous(resourceName, id) {
3926
3934
3927
3935
module . exports = previous ;
3928
3936
3929
- } , { "errors" :"hIh4e1" , "services" :"cX8q+p" , "utils" :"uE/lJt" } ] , "hIh4e1" :[ function ( require , module , exports ) {
3937
+ } , { "errors" :"hIh4e1" , "services" :"cX8q+p" , "utils" :"uE/lJt" } ] , "errors" :[ function ( require , module , exports ) {
3938
+ module . exports = require ( 'hIh4e1' ) ;
3939
+ } , { } ] , "hIh4e1" :[ function ( require , module , exports ) {
3930
3940
/**
3931
3941
* @doc function
3932
3942
* @id errors.types:UnhandledError
@@ -4138,8 +4148,6 @@ module.exports = {
4138
4148
RuntimeError : RuntimeError
4139
4149
} ;
4140
4150
4141
- } , { } ] , "errors" :[ function ( require , module , exports ) {
4142
- module . exports = require ( 'hIh4e1' ) ;
4143
4151
} , { } ] , 52 :[ function ( require , module , exports ) {
4144
4152
( function ( window , angular , undefined ) {
4145
4153
'use strict' ;
@@ -4296,4 +4304,4 @@ module.exports = {
4296
4304
4297
4305
} , { "mout/array/contains" :1 , "mout/array/filter" :2 , "mout/array/slice" :5 , "mout/array/sort" :6 , "mout/array/toLookup" :7 , "mout/lang/isEmpty" :12 , "mout/object/deepMixIn" :19 , "mout/object/forOwn" :21 , "mout/string/makePath" :23 , "mout/string/upperCase" :24 } ] , "utils" :[ function ( require , module , exports ) {
4298
4306
module . exports = require ( 'uE/lJt' ) ;
4299
- } , { } ] } , { } , [ 52 ] )
4307
+ } , { } ] } , { } , [ 52 ] )
0 commit comments