@@ -14,8 +14,6 @@ var Identify = require('segmentio-facade').Identify;
1414var SourceMiddlewareChain = require ( './middleware' ) . SourceMiddlewareChain ;
1515var IntegrationMiddlewareChain = require ( './middleware' )
1616 . IntegrationMiddlewareChain ;
17- var DestinationMiddlewareChain = require ( './middleware' )
18- . DestinationMiddlewareChain ;
1917var Page = require ( 'segmentio-facade' ) . Page ;
2018var Track = require ( 'segmentio-facade' ) . Track ;
2119var bindAll = require ( 'bind-all' ) ;
@@ -52,7 +50,6 @@ function Analytics() {
5250 this . Integrations = { } ;
5351 this . _sourceMiddlewares = new SourceMiddlewareChain ( ) ;
5452 this . _integrationMiddlewares = new IntegrationMiddlewareChain ( ) ;
55- this . _destinationMiddlewares = { } ;
5653 this . _integrations = { } ;
5754 this . _readied = false ;
5855 this . _timeout = 300 ;
@@ -114,7 +111,6 @@ Analytics.prototype.addSourceMiddleware = function(middleware) {
114111
115112/**
116113 * Define a new `IntegrationMiddleware`
117- * DEPRECATED
118114 *
119115 * @param {Function } Middleware
120116 * @return {Analytics }
@@ -125,32 +121,6 @@ Analytics.prototype.addIntegrationMiddleware = function(middleware) {
125121 return this ;
126122} ;
127123
128- /**
129- * Define a new `DestinationMiddleware`
130- * Destination Middleware is chained after integration middleware
131- *
132- * @param {String } integrationName
133- * @param {Array } Middlewares
134- * @return {Analytics }
135- */
136-
137- Analytics . prototype . addDestinationMiddleware = function (
138- integrationName ,
139- middlewares
140- ) {
141- var self = this ;
142- middlewares . forEach ( function ( middleware ) {
143- if ( ! self . _destinationMiddlewares [ integrationName ] ) {
144- self . _destinationMiddlewares [
145- integrationName
146- ] = new DestinationMiddlewareChain ( ) ;
147- }
148-
149- self . _destinationMiddlewares [ integrationName ] . add ( middleware ) ;
150- } ) ;
151- return self ;
152- } ;
153-
154124/**
155125 * Initialize with the given integration `settings` and `options`.
156126 *
@@ -764,6 +734,11 @@ Analytics.prototype._invoke = function(method, facade) {
764734 result = new Facade ( result ) ;
765735 }
766736
737+ self . emit ( 'invoke' , result ) ;
738+ metrics . increment ( 'analytics_js.invoke' , {
739+ method : method
740+ } ) ;
741+
767742 applyIntegrationMiddlewares ( result ) ;
768743 }
769744 ) ;
@@ -816,53 +791,12 @@ Analytics.prototype._invoke = function(method, facade) {
816791 result = new Facade ( result ) ;
817792 }
818793
819- // apply destination middlewares
820- // Apply any integration middlewares that exist, then invoke the integration with the result.
821- if ( self . _destinationMiddlewares [ integration . name ] ) {
822- self . _destinationMiddlewares [ integration . name ] . applyMiddlewares (
823- facadeCopy ,
824- integration . name ,
825- function ( result ) {
826- // A nullified payload should not be sent to an integration.
827- if ( result === null ) {
828- self . log (
829- 'Payload to destination "%s" was null and dropped by a middleware.' ,
830- name
831- ) ;
832- return ;
833- }
834-
835- // Check if the payload is still a Facade. If not, convert it to one.
836- if ( ! ( result instanceof Facade ) ) {
837- result = new Facade ( result ) ;
838- }
839-
840- self . emit ( 'invoke' , result ) ;
841- metrics . increment ( 'analytics_js.invoke' , {
842- method : method
843- } ) ;
844-
845- metrics . increment ( 'analytics_js.integration.invoke' , {
846- method : method ,
847- integration_name : integration . name
848- } ) ;
849-
850- integration . invoke . call ( integration , method , result ) ;
851- }
852- ) ;
853- } else {
854- self . emit ( 'invoke' , result ) ;
855- metrics . increment ( 'analytics_js.invoke' , {
856- method : method
857- } ) ;
858-
859- metrics . increment ( 'analytics_js.integration.invoke' , {
860- method : method ,
861- integration_name : integration . name
862- } ) ;
863-
864- integration . invoke . call ( integration , method , result ) ;
865- }
794+ metrics . increment ( 'analytics_js.integration.invoke' , {
795+ method : method ,
796+ integration_name : integration . name
797+ } ) ;
798+
799+ integration . invoke . call ( integration , method , result ) ;
866800 }
867801 ) ;
868802 } catch ( e ) {
0 commit comments