@@ -103,20 +103,34 @@ return /******/ (function(modules) { // webpackBootstrap
103
103
104
104
var _modelScope2 = _interopRequireDefault ( _modelScope ) ;
105
105
106
- exports [ 'default' ] = function ( baseUrl , httpBackend ) {
106
+ var instances = [ ] ;
107
+
108
+ function restful ( baseUrl , httpBackend ) {
107
109
var rootScope = ( 0 , _modelScope2 [ 'default' ] ) ( ) ;
108
110
rootScope . assign ( 'config' , 'entityIdentifier' , 'id' ) ;
109
- if ( ! baseUrl && typeof window !== undefined && window . location ) {
111
+ if ( ! baseUrl && typeof window !== ' undefined' && window . location ) {
110
112
rootScope . set ( 'url' , window . location . protocol + '//' + window . location . host ) ;
111
113
} else {
112
114
rootScope . set ( 'url' , baseUrl ) ;
113
115
}
114
116
115
- return ( 0 , _modelDecorator . member ) ( ( 0 , _modelEndpoint2 [ 'default' ] ) ( ( 0 , _serviceHttp2 [ 'default' ] ) ( httpBackend ) ) ( rootScope ) ) ;
117
+ var rootEndpoint = ( 0 , _modelDecorator . member ) ( ( 0 , _modelEndpoint2 [ 'default' ] ) ( ( 0 , _serviceHttp2 [ 'default' ] ) ( httpBackend ) ) ( rootScope ) ) ;
118
+
119
+ instances . push ( rootEndpoint ) ;
120
+
121
+ return rootEndpoint ;
122
+ }
123
+
124
+ restful . _instances = function ( ) {
125
+ return instances ;
126
+ } ;
127
+ restful . _flush = function ( ) {
128
+ return instances . length = 0 ;
116
129
} ;
117
130
118
131
exports . fetchBackend = _httpFetch2 [ 'default' ] ;
119
132
exports . requestBackend = _httpRequest2 [ 'default' ] ;
133
+ exports [ 'default' ] = restful ;
120
134
121
135
/***/ } ,
122
136
/* 2 */
@@ -275,8 +289,6 @@ return /******/ (function(modules) { // webpackBootstrap
275
289
config = config . set ( 'data' , ( 0 , _immutable . fromJS ) ( data ) ) ;
276
290
}
277
291
278
- scope . emit ( 'request' , ( 0 , _utilSerialize2 [ 'default' ] ) ( config ) ) ;
279
-
280
292
return config ;
281
293
}
282
294
@@ -294,13 +306,17 @@ return /******/ (function(modules) { // webpackBootstrap
294
306
function _httpMethodFactory ( method ) {
295
307
var expectData = arguments . length <= 1 || arguments [ 1 ] === undefined ? true : arguments [ 1 ] ;
296
308
309
+ var emitter = function emitter ( ) {
310
+ scope . emit . apply ( scope , arguments ) ;
311
+ } ;
312
+
297
313
if ( expectData ) {
298
314
return function ( data ) {
299
315
var params = arguments . length <= 1 || arguments [ 1 ] === undefined ? null : arguments [ 1 ] ;
300
316
var headers = arguments . length <= 2 || arguments [ 2 ] === undefined ? null : arguments [ 2 ] ;
301
317
302
318
var config = _generateRequestConfig ( method , data , params , headers ) ;
303
- return request ( config ) . then ( function ( rawResponse ) {
319
+ return request ( config , emitter ) . then ( function ( rawResponse ) {
304
320
return _onResponse ( config , rawResponse ) ;
305
321
} , function ( rawResponse ) {
306
322
return _onError ( config , rawResponse ) ;
@@ -313,7 +329,7 @@ return /******/ (function(modules) { // webpackBootstrap
313
329
var headers = arguments . length <= 1 || arguments [ 1 ] === undefined ? null : arguments [ 1 ] ;
314
330
315
331
var config = _generateRequestConfig ( method , null , params , headers ) ;
316
- return request ( config ) . then ( function ( rawResponse ) {
332
+ return request ( config , emitter ) . then ( function ( rawResponse ) {
317
333
return _onResponse ( config , rawResponse ) ;
318
334
} , function ( error ) {
319
335
return _onError ( config , error ) ;
@@ -6112,35 +6128,51 @@ return /******/ (function(modules) { // webpackBootstrap
6112
6128
var _utilSerialize2 = _interopRequireDefault ( _utilSerialize ) ;
6113
6129
6114
6130
/* eslint-disable new-cap */
6115
- function reducePromiseList ( list , initialValue ) {
6116
- var params = arguments . length <= 2 || arguments [ 2 ] === undefined ? [ ] : arguments [ 2 ] ;
6131
+ function reducePromiseList ( emitter , list , initialValue ) {
6132
+ var params = arguments . length <= 3 || arguments [ 3 ] === undefined ? [ ] : arguments [ 3 ] ;
6117
6133
6118
6134
return list . reduce ( function ( promise , nextItem ) {
6119
6135
return promise . then ( function ( currentValue ) {
6136
+ emitter . apply ( undefined , [ 'pre' , ( 0 , _utilSerialize2 [ 'default' ] ) ( currentValue ) ] . concat ( _toConsumableArray ( params ) , [ nextItem . name ] ) ) ;
6120
6137
return Promise . resolve ( nextItem . apply ( undefined , [ ( 0 , _utilSerialize2 [ 'default' ] ) ( currentValue ) ] . concat ( _toConsumableArray ( params ) ) ) ) . then ( function ( nextValue ) {
6121
6138
if ( ! _immutable . Iterable . isIterable ( currentValue ) ) {
6122
6139
return ( 0 , _objectAssign2 [ 'default' ] ) ( { } , currentValue , nextValue ) ;
6123
6140
}
6124
6141
6125
6142
return currentValue . mergeDeep ( nextValue ) ;
6143
+ } ) . then ( function ( nextValue ) {
6144
+ emitter . apply ( undefined , [ 'post' , ( 0 , _utilSerialize2 [ 'default' ] ) ( nextValue ) ] . concat ( _toConsumableArray ( params ) , [ nextItem . name ] ) ) ;
6145
+
6146
+ return nextValue ;
6126
6147
} ) ;
6127
6148
} ) ;
6128
6149
} , Promise . resolve ( initialValue ) ) ;
6129
6150
}
6130
6151
6131
6152
exports [ 'default' ] = function ( httpBackend ) {
6132
- return function ( config ) {
6153
+ return function ( config , emitter ) {
6133
6154
var errorInterceptors = ( 0 , _immutable . List ) ( config . get ( 'errorInterceptors' ) ) ;
6134
6155
var requestInterceptors = ( 0 , _immutable . List ) ( config . get ( 'requestInterceptors' ) ) ;
6135
6156
var responseInterceptors = ( 0 , _immutable . List ) ( config . get ( 'responseInterceptors' ) ) ;
6136
6157
var currentConfig = config [ 'delete' ] ( 'errorInterceptors' ) [ 'delete' ] ( 'requestInterceptors' ) [ 'delete' ] ( 'responseInterceptors' ) ;
6137
6158
6138
- return reducePromiseList ( requestInterceptors , currentConfig ) . then ( function ( transformedConfig ) {
6159
+ function emitterFactory ( type ) {
6160
+ return function ( event ) {
6161
+ for ( var _len = arguments . length , args = Array ( _len > 1 ? _len - 1 : 0 ) , _key = 1 ; _key < _len ; _key ++ ) {
6162
+ args [ _key - 1 ] = arguments [ _key ] ;
6163
+ }
6164
+
6165
+ emitter . apply ( undefined , [ type + ':' + event ] . concat ( args ) ) ;
6166
+ } ;
6167
+ }
6168
+
6169
+ return reducePromiseList ( emitterFactory ( 'request:interceptor' ) , requestInterceptors , currentConfig ) . then ( function ( transformedConfig ) {
6170
+ emitter ( 'request' , ( 0 , _utilSerialize2 [ 'default' ] ) ( transformedConfig ) ) ;
6139
6171
return httpBackend ( ( 0 , _utilSerialize2 [ 'default' ] ) ( transformedConfig ) ) . then ( function ( response ) {
6140
- return reducePromiseList ( responseInterceptors , ( 0 , _immutable . fromJS ) ( response ) , [ ( 0 , _utilSerialize2 [ 'default' ] ) ( transformedConfig ) ] ) ;
6172
+ return reducePromiseList ( emitterFactory ( 'response:interceptor' ) , responseInterceptors , ( 0 , _immutable . fromJS ) ( response ) , [ ( 0 , _utilSerialize2 [ 'default' ] ) ( transformedConfig ) ] ) ;
6141
6173
} ) ;
6142
6174
} ) . then ( null , function ( error ) {
6143
- return reducePromiseList ( errorInterceptors , error , [ ( 0 , _utilSerialize2 [ 'default' ] ) ( currentConfig ) ] ) . then ( function ( transformedError ) {
6175
+ return reducePromiseList ( emitterFactory ( 'error:interceptor' ) , errorInterceptors , error , [ ( 0 , _utilSerialize2 [ 'default' ] ) ( currentConfig ) ] ) . then ( function ( transformedError ) {
6144
6176
return Promise . reject ( transformedError ) ;
6145
6177
} ) ;
6146
6178
} ) ;
0 commit comments