@@ -97,7 +97,6 @@ helper.DataLayerHelper = function(dataLayer, opt_listener, opt_listenToPast) {
97
97
*/
98
98
this . unprocessed_ = [ ] ;
99
99
100
- var that = this ;
101
100
/**
102
101
* The interface to the internal dataLayer model that is exposed to custom
103
102
* methods. Custom methods will the executed with this interface as the value
@@ -106,21 +105,37 @@ helper.DataLayerHelper = function(dataLayer, opt_listener, opt_listenToPast) {
106
105
* @type {!Object }
107
106
* @private
108
107
*/
109
- this . abstractModelInterface_ = {
110
- 'set' : function ( key , value ) {
111
- helper . merge_ ( helper . expandKeyValue_ ( key , value ) , that . model_ ) ;
112
- } ,
113
- 'get' : function ( key ) {
114
- return that . get ( key ) ;
115
- }
108
+ this . abstractModelInterface_ = { } ;
109
+
110
+ /**
111
+ * Helper function that will build the abstract model interface using the
112
+ * supplied dataLayerHelper.
113
+ *
114
+ * @param {DataLayerHelper } dataLayerHelper The helper class to construct the
115
+ * abstract model interface for.
116
+ * @private
117
+ */
118
+ this . buildAbstractModelInterface_ = function ( dataLayerHelper ) {
119
+ dataLayerHelper . abstractModelInterface_ = {
120
+ 'set' : function ( key , value ) {
121
+ helper . merge_ ( helper . expandKeyValue_ ( key , value ) ,
122
+ dataLayerHelper . model_ ) ;
123
+ } ,
124
+ 'get' : function ( key ) {
125
+ return dataLayerHelper . get ( key ) ;
126
+ }
127
+ } ;
116
128
} ;
117
129
130
+ // Create the abstract interface used in Custom Methods.
131
+ this . buildAbstractModelInterface_ ( this ) ;
118
132
119
133
// Process the existing/past states.
120
134
this . processStates_ ( dataLayer , ! opt_listenToPast ) ;
121
135
122
136
// Add listener for future state changes.
123
137
var oldPush = dataLayer . push ;
138
+ var that = this ;
124
139
dataLayer . push = function ( ) {
125
140
var states = [ ] . slice . call ( arguments , 0 ) ;
126
141
var result = oldPush . apply ( dataLayer , states ) ;
@@ -196,7 +211,7 @@ helper.DataLayerHelper.prototype.processStates_ =
196
211
update . call ( this . abstractModelInterface_ ) ;
197
212
} catch ( e ) {
198
213
// Catch any exceptions to we don't drop subsequent updates.
199
- // TODO(arnau) : Add some sort of logging when this happens.
214
+ // TODO: Add some sort of logging when this happens.
200
215
}
201
216
} else if ( plain . isPlainObject ( update ) ) {
202
217
for ( var key in update ) {
@@ -238,7 +253,7 @@ helper.processCommand_ = function(command, model) {
238
253
target [ method ] . apply ( target , args ) ;
239
254
} catch ( e ) {
240
255
// Catch any exception so we don't drop subsequent updates.
241
- // TODO(Alex Nau) : Add some sort of logging here when this happens.
256
+ // TODO: Add some sort of logging here when this happens.
242
257
}
243
258
} ;
244
259
0 commit comments